Simplify MuJoCo Studio viewer selection and unify model flags.
This change removes the ViewerMode enum and instead infers whether to launch the Web Viewer or Native Viewer based on the graphics mode (gfx) setting. Specifically, setting gfx to "web" or "webgl" will now launch the Web Viewer (in future "webgpu" would also launch the Web Viewer). Additionally, this unifies command-line flags across studio scripts and samples by replacing the --mjcf flag with --model (with positional argument fallback) and standardizing absl flags usage. --model is a better name since formats like .mjz and .mjb are also supported by this argument. PiperOrigin-RevId: 959058940 Change-Id: If4e0ace664ddc6e45cb681d168679148e8c4901d
This commit is contained in:
committed by
Copybara-Service
parent
0a10860257
commit
b3ef7a8c2f
@@ -86,26 +86,21 @@ def run_viewer_target(
|
||||
"""Creates the appropriate viewer and runs the viewer loop.
|
||||
|
||||
Args:
|
||||
config: Configuration specifying the viewer mode and window settings.
|
||||
config: Configuration specifying the viewer window settings.
|
||||
viewer_endpoint: Endpoint for communicating with the simulation side.
|
||||
handlers: Optional list of viewer-side handler instances, which are classes
|
||||
with methods decorated with ``@handler``.
|
||||
|
||||
Raises:
|
||||
ValueError: If the viewer mode requested in config is unknown.
|
||||
"""
|
||||
if config.viewer_mode == viewer_protocol.ViewerMode.NATIVE:
|
||||
if config.gfx in ('web', 'webgl'): # In future we may add 'webgpu' here too.
|
||||
from mujoco.experimental.studio import web_viewer # pylint: disable=g-import-not-at-top
|
||||
|
||||
viewer = web_viewer.WebViewer(config, viewer_endpoint, handlers=handlers)
|
||||
else:
|
||||
from mujoco.experimental.studio import native_viewer # pylint: disable=g-import-not-at-top
|
||||
|
||||
viewer = native_viewer.NativeViewer(
|
||||
config, viewer_endpoint, handlers=handlers
|
||||
)
|
||||
elif config.viewer_mode == viewer_protocol.ViewerMode.WEB:
|
||||
from mujoco.experimental.studio import web_viewer # pylint: disable=g-import-not-at-top
|
||||
|
||||
viewer = web_viewer.WebViewer(config, viewer_endpoint, handlers=handlers)
|
||||
else:
|
||||
raise ValueError(f'Unknown viewer mode: {config.viewer_mode!r}')
|
||||
|
||||
viewer_protocol.run_viewer_loop(viewer)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user