mjlab.viewer#

Viewer module for environment visualization.

Classes

Protocols

ViewerConfig#

class mjlab.viewer.ViewerConfig[source]#
class OriginType[source]#

The frame in which the camera position and target are defined.

AUTO = 1#

Track the first non-fixed body, or fall back to a free camera.

WORLD = 2#

Free camera at the configured lookat point.

ASSET_ROOT = 3#

Track the root body of the asset defined by entity_name.

ASSET_BODY = 4#

Track the body defined by body_name in the asset defined by entity_name.

origin_type: OriginType = 1#
height: int = 240#
width: int = 320#
enable_reflections: bool = True#
enable_shadows: bool = True#
geom_group: tuple[int, int, int, int, int, int] = (1, 1, 1, 0, 0, 0)#

Which geom visualization groups the offscreen renderer draws.

site_group: tuple[int, int, int, int, int, int] = (1, 1, 1, 0, 0, 0)#

Which site visualization groups the offscreen renderer draws.

env_idx: int = 0#

Environment rendered as the primary env and tracked by the camera.

max_extra_envs: int = 2#

Number of neighboring environments to render around env_idx.

reward_bar_max_terms: int = 20#

Maximum number of reward terms shown in the Viser reward bar panel.

Terms beyond this limit are dropped (with a warning). Raise it for environments with many reward terms.

distance: float = 5.0#
elevation: float = -45.0#
azimuth: float = 90.0#
fovy: float | None = None#

Vertical field of view in degrees. None keeps the model default.

lookat: tuple[float, float, float] = (0.0, 0.0, 0.0)#

Look-at target in the world frame. Only used by the AUTO and WORLD free cameras; the ASSET_ROOT and ASSET_BODY tracking cameras ignore it.

entity_name: str | None = None#

Entity tracked by the camera. Auto-detected if the scene has exactly one entity.

body_name: str | None = None#

Body tracked by the camera. Required for ASSET_BODY.

BaseViewer#

class mjlab.viewer.BaseViewer[source]#

Bases: ABC

Abstract base class for environment viewers.

__init__(env: EnvProtocol, policy: PolicyProtocol, frame_rate: float = 30.0, verbosity: int = VerbosityLevel.SILENT)[source]#
tick() → bool[source]#

Advance one tick: drain actions, step physics, maybe render.

Returns True when a render frame was produced, False otherwise.

NativeMujocoViewer#

class mjlab.viewer.NativeMujocoViewer[source]#

Bases: BaseViewer

__init__(env: EnvProtocol, policy: PolicyProtocol, frame_rate: float = 60.0, key_callback: Callable[[int], None] | None = None, plot_cfg: PlotCfg | None = None, enable_perturbations: bool = True, verbosity: VerbosityLevel = VerbosityLevel.SILENT)[source]#
setup() → None[source]#

Setup MuJoCo viewer resources.

sync_env_to_viewer() → None[source]#

Copy env state to viewer; update reward figures; render other envs.

sync_viewer_to_env() → None[source]#

Sync mouse perturbation to sim via qfrc_applied.

Mouse perturbation forces are converted from Cartesian body space (xfrc_applied) to generalized joint space (qfrc_applied) so that they coexist with programmatic forces on xfrc_applied. See the module docstring for details on the channel separation.

close() → None[source]#

Close viewer and cleanup.

reset_environment() → None[source]#

Extend BaseViewer.reset_environment to clear reward histories.

ViserPlayViewer#

class mjlab.viewer.ViserPlayViewer[source]#

Bases: BaseViewer

Interactive Viser-based viewer with playback controls.

__init__(env: EnvProtocol, policy: PolicyProtocol, frame_rate: float = 60.0, verbosity: VerbosityLevel = VerbosityLevel.SILENT, viser_server: viser.ViserServer | None = None, checkpoint_manager: CheckpointManager | None = None) → None[source]#
setup() → None[source]#

Setup the viewer resources.

sync_env_to_viewer() → None[source]#

Synchronize environment state to viewer.

sync_viewer_to_env() → None[source]#

Synchronize viewer state to environment (e.g., perturbations).

reset_environment() → None[source]#

Extend BaseViewer.reset_environment to clear reward and metrics histories.

close() → None[source]#

Close the viewer and cleanup resources.

is_running() → bool[source]#

Check if viewer is running.

OffscreenRenderer#

class mjlab.viewer.OffscreenRenderer[source]#

Bases: object

__init__(model: MjModel, cfg: ViewerConfig, scene: Scene, sim_model: Any | None = None, expanded_fields: set[str] | None = None) → None[source]#
update(data: Any, debug_vis_callback: Callable[[MujocoNativeDebugVisualizer], None] | None = None, camera: str | None = None) → None[source]#

Update renderer with simulation data.

Protocols#

class mjlab.viewer.EnvProtocol[source]#

Interface we expect from RL environments, which can be either vanilla ManagerBasedRlEnv objects or wrapped with VideoRecorder, RslRlVecEnvWrapper, etc.

__init__(*args, **kwargs)#
class mjlab.viewer.PolicyProtocol[source]#
__init__(*args, **kwargs)#
class mjlab.viewer.VerbosityLevel[source]#
__new__(value)#