[Python Viewer] Allow users to override rendering flags via user_scn.

Fixes #1190

PiperOrigin-RevId: 603672602
Change-Id: I3ff1bb0dca7e913b36f1b241aaea8b8bb95cadff
This commit is contained in:
Saran Tunyasuvunakool
2024-02-02 06:38:28 -08:00
committed by Copybara-Service
parent 92c161a61b
commit 7bb0ce4211
4 changed files with 33 additions and 7 deletions
+11 -5
View File
@@ -124,15 +124,21 @@ attributes:
- ``is_running()``: returns ``True`` if the viewer window is running and ``False`` if it is closed.
This method can be safely called without locking.
- ``user_scn``: an :ref:`mjvScene` object that allows users to add custom visualization geoms to the rendered scene.
This is separate from the ``mjvScene`` that the viewer uses internally to render the final scene, and is entirely
under the user's control. User scripts can call e.g. :ref:`mjv_initGeom` or :ref:`mjv_makeConnector` to add
visualization geoms to ``user_scn``, and upon the next call to ``sync()``, the viewer will incorporate
these geoms to future rendered images. For example:
- ``user_scn``: an :ref:`mjvScene` object that allows users to add change rendering flags and add custom
visualization geoms to the rendered scene. This is separate from the ``mjvScene`` that the viewer uses internally to
render the final scene, and is entirely under the user's control. User scripts can call e.g. :ref:`mjv_initGeom` or
:ref:`mjv_makeConnector` to add visualization geoms to ``user_scn``, and upon the next call to ``sync()``, the viewer
will incorporate these geoms to future rendered images. Similarly, user scripts can make changes to ``user_scn.flags``
which would be picked up at the next call to ``sync()``. The ``sync()`` call also copies changes to rendering flags
made via the GUI back into ``user_scn`` to preserve consistency. For example:
.. code-block:: python
with mujoco.viewer.launch_passive(m, d, key_callback=key_callback) as viewer:
# Enable wireframe rendering of the entire scene.
v.user_scn.flags[mujoco.mjtRndFlag.mjRND_WIREFRAME] = 1
while viewer.is_running():
...
# Step the physics.