rohanpsingh / mujoco-python-viewer

Simple renderer for use with MuJoCo (>=2.1.2) Python Bindings.
BSD 2-Clause "Simplified" License
163 stars 24 forks source link

Full Reload of Sim without closing window? #25

Open rohit-kumar-j opened 1 year ago

rohit-kumar-j commented 1 year ago

This might be a breaking change:

# pass in the xml path to the viewer directly and upon KEY_BACKSPACE, reload the sim
viewer = viewer.MujocoViewer(xml_path="Projects/rjax_python/robots/humanoid/scene.xml")
while True:
        mujoco.mj_step(viewer.model, viewer.data)
        viewer.render()

Each time the model and data have to be accessed, they have to be done via viewer.model and viewer.data. The examples, etc need to change. Would this PR be okay? (Of course, the changes will be reflected in the README and examples)

Need for this/Use case:

No relaunching of the python script for .xml tweaking, no need to use simulate.cc for the same

Implementation Example:

https://user-images.githubusercontent.com/37873142/192229058-3711d7ab-b69c-46c0-b6b3-998364ce704f.mp4

(If the video stops in the middle, kindly scrub manually to the end. The video may be corrupted)

rohanpsingh commented 1 year ago

Thanks for the nice demo @rohit-kumar-j ! Yes, it's quite a big change (and I'm still looking at your other PR, sorry for the delay).

Don't you think it's better to let simulate.cc handle features like this? As far as I know, there are soon going to be python bindings for simulate.cc, which would make this a redundant feature. What do you think?

rohit-kumar-j commented 1 year ago

Yes, simualte.cc's python counterpart might most likely be able better to handle features like reloading simulation. Perhaps this would be only temporary.

I guess I haven't explained my reasoning for #23, especially in the context of the new simulate.cc viewer's implementation in python. I hope I can faithfully do so here:

I don't see this repo a replica of simulate.cc's. I see this as a more easy-to-use and functional viewer as opposed to feature loaded (like simulate). There are a few things that I have noticed when developing/preparing xml files (I guess this is more of a workflow thing than a number of features in thing, Hence all the PRs 😅)

PS: I have not seen the src code/used the python version of the simulate.cc. (perhaps it is this.)