Refactor Viewer to be a base class owning the communication with the simulation, handler registry, core visualization objects and the render function

ViewerApp is simplified, interacting with the endpoint and handlers through the Viewer instance. This change makes it possible to write simulation viewers without using the UI/UX provided by ViewerApp (which should be renamed StudioApp)

PiperOrigin-RevId: 943642660
Change-Id: Id8eb3d4e6a27ceda93833367fec4699fa6bc838e
This commit is contained in:
Matija Kecman
2026-07-06 20:49:58 -07:00
committed by Copybara-Service
parent ae58855c15
commit 8079ab3d4d
9 changed files with 384 additions and 322 deletions
@@ -23,7 +23,6 @@ from typing import Any
from mujoco.experimental.studio import endpoints
from mujoco.experimental.studio import messages
from mujoco.experimental.studio import viewer_app
from mujoco.experimental.studio import viewer_handle
from mujoco.experimental.studio import viewer_protocol
@@ -100,13 +99,15 @@ def run_viewer_target(
if config.viewer_mode == viewer_protocol.ViewerMode.NATIVE:
from mujoco.experimental.studio import native_viewer # pylint: disable=g-import-not-at-top
viewer = native_viewer.NativeViewer(config)
viewer = native_viewer.NativeViewer(
config, viewer_endpoint, handlers=handlers
)
elif config.viewer_mode == viewer_protocol.ViewerMode.WEB:
raise NotImplementedError('Web viewer not implemented yet')
else:
raise ValueError(f'Unknown viewer mode: {config.viewer_mode!r}')
viewer_app.run_viewer(viewer, viewer_endpoint, handlers=handlers)
viewer_protocol.run_viewer_loop(viewer)
def launch_passive(