Class MujocoRenderer
- Namespace
- Gym.Environments.Envs.MuJoCo
- Assembly
- Gym.Environments.dll
Draws a MuJoCo env's frames (MujocoRenderer): the camera resolved as Gymnasium resolves it (a named camera,
an id, or the free camera with the env's default configuration), and the render modes rgb_array,
depth_array, rgbd_tuple and human. Gym.NET draws the scene itself (DR-62); its frames are
compared with Gymnasium's and the differences measured, not required equal (DR-67).
[PyName("MujocoRenderer")]
public sealed class MujocoRenderer
- Inheritance
-
MujocoRenderer
- Inherited Members
- Extension Methods
Remarks
Reference: gymnasium/envs/mujoco/mujoco_rendering.py.
Constructors
MujocoRenderer(MjModel, MjData, IReadOnlyDictionary<string, object?>?, int?, int?, int, int?, string?, IReadOnlyDictionary<int, bool>?, EnvViewerFactory?)
Resolves the camera and keeps the settings (Gymnasium's MujocoRenderer.init); nothing is drawn until
Render(string?).
public MujocoRenderer(MjModel model, MjData data, IReadOnlyDictionary<string, object?>? defaultCamConfig = null, int? width = null, int? height = null, int maxGeom = 1000, int? cameraId = null, string? cameraName = null, IReadOnlyDictionary<int, bool>? visualOptions = null, EnvViewerFactory? viewerFactory = null)
Parameters
modelMjModelThe model to draw.
dataMjDataThe simulation to draw.
defaultCamConfigIReadOnlyDictionary<string, object>The free camera's settings (
default_cam_config), or null.widthint?The frame's width, or null (only
humanmode allows it).heightint?The frame's height, or null.
maxGeomintThe most geoms a frame draws (
max_geom).cameraIdint?The camera id (
camera_id), or null.cameraNamestringThe camera name (
camera_name), or null.visualOptionsIReadOnlyDictionary<int, bool>MuJoCo visual flags to switch (
visual_options), or null.viewerFactoryEnvViewerFactoryGym.NET's
viewer_factory(DR-20): the windowhumanmode shows frames in, or null forGymnasium.HumanViewerFactory.
Remarks
With neither camera given, Gymnasium looks up a camera named track and then uses the free camera anyway
(id -1), so the env's default camera configuration takes effect; a named or numbered camera is used as given.
Exceptions
- ArgumentNullException
A null model or data.
- ValueError
Both a camera id and a camera name, with Gymnasium's message.
Properties
CameraId
The camera the frames are drawn from (camera_id): -1 for the free camera, else a model camera.
public int CameraId { get; }
Property Value
Data
The simulation drawn (data), the env's: borrowed, never disposed here.
[NDBorrowed]
public MjData Data { get; }
Property Value
DefaultCamConfig
The free camera's settings (default_cam_config), applied when a mode's first frame is drawn.
public IReadOnlyDictionary<string, object?>? DefaultCamConfig { get; }
Property Value
Height
The frame's height in pixels (height).
public int? Height { get; }
Property Value
- int?
MaxGeom
The most geoms a frame draws (max_geom).
public int MaxGeom { get; }
Property Value
Model
The model drawn (model), the env's: borrowed, never disposed here.
[NDBorrowed]
public MjModel Model { get; }
Property Value
Width
The frame's width in pixels (width).
public int? Width { get; }
Property Value
- int?
Methods
Close()
Closes every window and buffer the modes opened (close): the human window shuts (a paused frame loop
cannot be running, since it holds the env's thread); drawing again opens them again.
public void Close()
Render(string?)
Draws one frame in renderMode (render): the scene from the camera (the free camera
with the env's default configuration, or the chosen model camera), drawn by Gym.NET's own rasterizer (DR-62);
in human mode, into the window with Gymnasium's menu and controls (DR-70).
public RenderResult Render(string? renderMode)
Parameters
Returns
- RenderResult
rgb_array: an(height, width, 3)uint8 frame;depth_array: an(height, width)float32 depth (0 at the near plane, 1 at the far one, as MuJoCo reads it back);rgbd_tuple: both;human: None after showing the frame. The caller owns the arrays.
Remarks
Frames are measured against Gymnasium's GPU frames, not required equal (DR-67, DR-71): lighting, textures,
the floor's reflection, shadows and multisampling follow MuJoCo's classic renderer in software, with the
reference GPU's measured rounding, and the rest of the GPU's choices still decide some pixels at edges and on
distant textures (on 2026-11-12, 0.07% of InvertedPendulum-v5's pixels to 16% of Humanoid-v5's, nearly all by
one level; depths bit for bit but for a few ulps). A 480×480 frame costs about 0.05 to 0.5 s of one desktop
core's time spread over all cores, the shadow map (4096² depths per shadow light) a good part of it, so an
rgb_array loop renders far slower than it steps.
human mode opens a viewer from the env's viewer_factory or Gymnasium.HumanViewerFactory
titled mujoco, at the renderer's width and height, and keeps Gymnasium's controls: Space pauses, and
while paused this call returns only when Space or → is released in the window (see the window's controls in
the MuJoCo guide). Its camera starts at MuJoCo's default free camera with the env's
DefaultCamConfig; CameraId is not used, as in Gymnasium.
Exceptions
- AssertionError
A mode other than
humanwithout a width or height, with Gymnasium's message.- AttributeError
An unknown mode, or none, with Gymnasium's message.
- ArgumentOutOfRangeException
The camera id names no model camera; or a human window's width or height is not positive.
- DependencyNotInstalled
humanmode with neither aviewer_factorynorGymnasium.HumanViewerFactory(DR-20).- ValueError
humanmode with a NaN simulation time or timestep, which the menu's step count cannot round.- OverflowError
humanmode with an infinite step count in the menu (Python'sOverflowError).- IOException
The human window's T key could not write its PNG.
- UnauthorizedAccessException
The human window's T key may not write its PNG there.
- InvalidCastException
A camera configuration value of a kind the camera field cannot take.
- IndexError
A visual option whose flag index is not an
mjtVisFlag, with NumPy's message.