newton.utils.SimRendererOpenGL#

class newton.utils.SimRendererOpenGL(model, path, scaling=1.0, fps=60, up_axis=None, show_rigid_contact_points=False, contact_points_radius=1e-3, show_joints=False, show_particles=True, **render_kwargs)#

Bases: SimRenderer

Real-time OpenGL renderer for Newton Physics simulations.

This renderer provides real-time visualization of physics simulations using OpenGL, with interactive camera controls and various rendering options.

Parameters:
  • model (newton.Model) – The Newton physics model to render.

  • path (str) – Window title for the OpenGL window.

  • scaling (float, optional) – Scaling factor for the rendered objects. Defaults to 1.0.

  • fps (int, optional) – Target frames per second. Defaults to 60.

  • up_axis (newton.AxisType, optional) – Up axis for the scene. If None, uses model’s up axis.

  • show_rigid_contact_points (bool, optional) – Whether to show contact points. Defaults to False.

  • contact_points_radius (float, optional) – Radius of contact point spheres. Defaults to 1e-3.

  • show_joints (bool, optional) – Whether to show joint visualizations. Defaults to False.

  • **render_kwargs – Additional arguments passed to the underlying OpenGLRenderer.

Example

import newton

model = newton.Model()  # your model setup
renderer = newton.utils.SimRendererOpenGL(model, "Newton Simulator")
# In your simulation loop:
renderer.begin_frame(time)
renderer.render(state)
renderer.end_frame()

Note

Keyboard shortcuts available during rendering:

  • W, A, S, D (or arrow keys) + mouse: FPS-style camera movement

  • X: Toggle wireframe rendering

  • B: Toggle backface culling

  • C: Toggle coordinate system axes

  • G: Toggle ground grid

  • T: Toggle depth rendering

  • I: Toggle info text

  • SPACE: Pause/continue simulation

  • TAB: Skip rendering (background simulation)

Methods

__init__(model, path[, scaling, fps, ...])

compute_projection_matrix(fov, aspect_ratio, ...)

Compute a projection matrix given the field of view, aspect ratio, near plane, and far plane.

get_pixels(target_image[, split_up_tiles, ...])

Read the pixels from the frame buffer (RGB or depth are supported) into the given array.

render(state)

Updates the renderer with the given simulation state.

render_arrow(name, pos, rot, base_radius, ...)

Add a arrow for visualization

render_box(name, pos, rot, extents[, ...])

Add a box for visualization

render_capsule(name, pos, rot, radius, ...)

Add a capsule for visualization

render_cone(name, pos, rot, radius, half_height)

Add a cone for visualization

render_cylinder(name, pos, rot, radius, ...)

Add a cylinder for visualization

render_ground([size, plane])

Add a ground plane for visualization

render_line_list(name, vertices, indices[, ...])

Add a line list as a set of capsules

render_line_strip(name, vertices[, color, ...])

Add a line strip as a set of capsules

render_mesh(name, points, indices[, colors, ...])

Add a mesh for visualization

render_plane(name, pos, rot, width, length)

Add a plane for visualization

render_points(name, points, radius[, ...])

Add a set of points

render_ref(name, path, pos, rot, scale[, color])

Create a reference (instance) with the given name to the given path.

render_sphere(name, pos, rot, radius[, ...])

Add a sphere for visualization

setup_tiled_rendering(instances[, ...])

Set up tiled rendering where the render buffer is split into multiple tiles that can visualize different shape instances of the scene with different view and projection matrices.

update_shape_instance(name[, pos, rot, ...])

Update the instance properties of the shape

update_tile(tile_id[, instances, ...])

Update the shape instances, projection matrix, view matrix, tile size, or tile position for a given tile given its index.

Attributes

__init__(model, path, scaling=1.0, fps=60, up_axis=None, show_rigid_contact_points=False, contact_points_radius=1e-3, show_joints=False, show_particles=True, **render_kwargs)#
Parameters:
  • title (str) – The window title.

  • scaling (float) – The scaling factor for the scene.

  • fps (int) – The target frames per second.

  • up_axis (str) – The up axis of the scene. Can be “X”, “Y”, or “Z”.

  • screen_width (int) – The width of the window.

  • screen_height (int) – The height of the window.

  • near_plane (float) – The near clipping plane.

  • far_plane (float) – The far clipping plane.

  • camera_fov (float) – The camera field of view in degrees.

  • camera_pos (tuple) – The initial camera position.

  • camera_front (tuple) – The initial camera front direction.

  • camera_up (tuple) – The initial camera up direction.

  • background_color (tuple) – The background color of the scene.

  • draw_grid (bool) – Whether to draw a grid indicating the ground plane.

  • draw_sky (bool) – Whether to draw a sky sphere.

  • draw_axis (bool) – Whether to draw the coordinate system axes.

  • show_info (bool) – Whether to overlay rendering information.

  • render_wireframe (bool) – Whether to render scene shapes as wireframes.

  • render_depth (bool) – Whether to show the depth buffer instead of the RGB image.

  • axis_scale (float) – The scale of the coordinate system axes being rendered (only if draw_axis is True).

  • vsync (bool) – Whether to enable vertical synchronization.

  • headless (bool) – Whether to run in headless mode (no window is created). If None, the value is determined by the Pyglet configuration defined in pyglet.options["headless"].

  • enable_backface_culling (bool) – Whether to enable backface culling.

  • enable_mouse_interaction (bool) – Whether to enable mouse interaction.

  • enable_keyboard_interaction (bool) – Whether to enable keyboard interaction.

  • device (Devicelike) – Where to store the internal data.

Note

OpenGLRenderer requires Pyglet (version >= 2.0, known to work on 2.0.7) to be installed.

Headless rendering is supported via EGL on UNIX operating systems. To enable headless rendering, set the following pyglet options before importing warp.render:

import pyglet

pyglet.options["headless"] = True

import warp.render

# OpenGLRenderer is instantiated with headless=True by default
renderer = warp.render.OpenGLRenderer()
static compute_projection_matrix(fov, aspect_ratio, near_plane, far_plane)#

Compute a projection matrix given the field of view, aspect ratio, near plane, and far plane.

Parameters:
  • fov (float) – The field of view in degrees.

  • aspect_ratio (float) – The aspect ratio (width / height).

  • near_plane (float) – The near plane.

  • far_plane (float) – The far plane.

Returns:

A projection matrix.

Return type:

List[float] | List[List[float]] | ndarray

default_num_segments = 32#
get_pixels(target_image, split_up_tiles=True, mode='rgb', use_uint8=False)#

Read the pixels from the frame buffer (RGB or depth are supported) into the given array.

If split_up_tiles is False, array must be of shape (screen_height, screen_width, 3) for RGB mode or (screen_height, screen_width, 1) for depth mode. If split_up_tiles is True, the pixels will be split up into tiles (see tile_width and tile_height for dimensions): array must be of shape (num_tiles, tile_height, tile_width, 3) for RGB mode or (num_tiles, tile_height, tile_width, 1) for depth mode.

Parameters:
  • target_image (array) – The array to read the pixels into. Must have float32 as dtype and be on a CUDA device.

  • split_up_tiles (bool) – Whether to split up the viewport into tiles, see setup_tiled_rendering().

  • mode (str) – can be either “rgb” or “depth”

  • use_uint8 (bool) – Whether to use uint8 as dtype in RGB mode for the target_image array and return values in the range [0, 255]. Otherwise, float32 is assumed as dtype with values in the range [0, 1].

Returns:

Whether the pixels were successfully read.

Return type:

bool

populate(model)#
render(state)#

Updates the renderer with the given simulation state.

Parameters:

state (newton.State) – The simulation state to render.

render_arrow(name, pos, rot, base_radius, base_height, cap_radius=None, cap_height=None, parent_body=None, is_template=False, up_axis=1, color=None, visible=True)#

Add a arrow for visualization

Parameters:
  • pos (tuple) – The position of the arrow

  • base_radius (float) – The radius of the cylindrical base of the arrow

  • base_height (float) – The height of the cylindrical base of the arrow

  • cap_radius (float | None) – The radius of the conical cap of the arrow

  • cap_height (float | None) – The height of the conical cap of the arrow

  • name (str) – A name for the USD prim on the stage

  • up_axis (int) – The axis of the arrow that points up (0: x, 1: y, 2: z)

render_box(name, pos, rot, extents, parent_body=None, is_template=False, color=None, visible=True)#

Add a box for visualization

Parameters:
  • pos (tuple) – The position of the box

  • extents (tuple) – The extents of the box

  • name (str) – A name for the USD prim on the stage

  • color (tuple[float, float, float] | None) – The color of the box

render_capsule(name, pos, rot, radius, half_height, parent_body=None, is_template=False, up_axis=1, color=None, visible=True)#

Add a capsule for visualization

Parameters:
  • pos (tuple) – The position of the capsule

  • radius (float) – The radius of the capsule

  • half_height (float) – The half height of the capsule

  • name (str) – A name for the USD prim on the stage

  • up_axis (int) – The axis of the capsule that points up (0: x, 1: y, 2: z)

  • color (tuple[float, float, float] | None) – The color of the capsule

render_cone(name, pos, rot, radius, half_height, parent_body=None, is_template=False, up_axis=1, color=None, visible=True)#

Add a cone for visualization

Parameters:
  • pos (tuple) – The position of the cone

  • radius (float) – The radius of the cone

  • half_height (float) – The half height of the cone

  • name (str) – A name for the USD prim on the stage

  • up_axis (int) – The axis of the cone that points up (0: x, 1: y, 2: z)

  • color (tuple[float, float, float] | None) – The color of the cone

render_cylinder(name, pos, rot, radius, half_height, parent_body=None, is_template=False, up_axis=1, color=None, visible=True)#

Add a cylinder for visualization

Parameters:
  • pos (tuple) – The position of the cylinder

  • radius (float) – The radius of the cylinder

  • half_height (float) – The half height of the cylinder

  • name (str) – A name for the USD prim on the stage

  • up_axis (int) – The axis of the cylinder that points up (0: x, 1: y, 2: z)

  • color (tuple[float, float, float] | None) – The color of the capsule

render_ground(size=1000.0, plane=None)#

Add a ground plane for visualization

Parameters:

size (float) – The size of the ground plane

render_line_list(name, vertices, indices, color=None, radius=0.01, visible=True)#

Add a line list as a set of capsules

Parameters:
  • vertices – The vertices of the line-list

  • indices – The indices of the line-list

  • color (tuple[float, float, float] | None) – The color of the line

  • radius (float) – The radius of the line

render_line_strip(name, vertices, color=None, radius=0.01, visible=True)#

Add a line strip as a set of capsules

Parameters:
  • vertices – The vertices of the line-strip

  • color (tuple[float, float, float] | None) – The color of the line

  • radius (float) – The radius of the line

render_mesh(name, points, indices, colors=None, pos=(0.0, 0.0, 0.0), rot=(0.0, 0.0, 0.0, 1.0), scale=(1.0, 1.0, 1.0), update_topology=False, parent_body=None, is_template=False, smooth_shading=True, visible=True)#

Add a mesh for visualization

Parameters:
  • points – The points of the mesh

  • indices – The indices of the mesh

  • colors – The colors of the mesh

  • pos – The position of the mesh

  • rot – The rotation of the mesh

  • scale – The scale of the mesh

  • name (str) – A name for the USD prim on the stage

  • smooth_shading (bool) – Whether to average face normals at each vertex or introduce additional vertices for each face

render_plane(name, pos, rot, width, length, color=(1.0, 1.0, 1.0), color2=None, parent_body=None, is_template=False, u_scaling=1.0, v_scaling=1.0, visible=True)#

Add a plane for visualization

Parameters:
  • name (str) – The name of the plane

  • pos (tuple) – The position of the plane

  • rot (tuple) – The rotation of the plane

  • width (float) – The width of the plane

  • length (float) – The length of the plane

  • color (tuple) – The color of the plane

  • texture – The texture of the plane (optional)

render_points(name, points, radius, colors=None, as_spheres=True, visible=True)#

Add a set of points

Parameters:
  • points – The points to render

  • radius – The radius of the points (scalar or list)

  • colors – The colors of the points

  • name (str) – A name for the USD prim on the stage

render_ref(name, path, pos, rot, scale, color=None)#

Create a reference (instance) with the given name to the given path.

render_sphere(name, pos, rot, radius, parent_body=None, is_template=False, color=None, visible=True)#

Add a sphere for visualization

Parameters:
  • pos (tuple) – The position of the sphere

  • radius (float) – The radius of the sphere

  • name (str) – A name for the USD prim on the stage

  • color (tuple[float, float, float] | None) – The color of the sphere

setup_tiled_rendering(instances, rescale_window=False, tile_width=None, tile_height=None, tile_ncols=None, tile_nrows=None, tile_positions=None, tile_sizes=None, projection_matrices=None, view_matrices=None)#

Set up tiled rendering where the render buffer is split into multiple tiles that can visualize different shape instances of the scene with different view and projection matrices. See get_pixels() which allows to retrieve the pixels of for each tile. See update_tile() which allows to update the shape instances, projection matrix, view matrix, tile size, or tile position for a given tile.

Parameters:
  • instances (list[list[int]]) – A list of lists of shape instance ids. Each list of shape instance ids will be rendered into a separate tile.

  • rescale_window (bool) – If True, the window will be resized to fit the tiles.

  • tile_width (int | None) – The width of each tile in pixels (optional).

  • tile_height (int | None) – The height of each tile in pixels (optional).

  • tile_ncols (int | None) – The number of tiles rendered horizontally (optional). Will be considered if tile_width is set to compute the tile positions, unless tile_positions is defined.

  • tile_positions (list[tuple[int]] | None) – A list of (x, y) tuples specifying the position of each tile in pixels. If None, the tiles will be arranged in a square grid, or, if tile_ncols and tile_nrows is set, in a grid with the specified number of columns and rows.

  • tile_sizes (list[tuple[int]] | None) – A list of (width, height) tuples specifying the size of each tile in pixels. If None, the tiles will have the same size as specified by tile_width and tile_height.

  • projection_matrices (list[List[float] | List[List[float]] | ndarray] | None) – A list of projection matrices for each tile (each view matrix is either a flattened 16-dimensional array or a 4x4 matrix). If the entire array is None, or only a view instances, the projection matrices for all, or these instances, respectively, will be derived from the current render settings.

  • view_matrices (list[List[float] | List[List[float]] | ndarray] | None) – A list of view matrices for each tile (each view matrix is either a flattened 16-dimensional array or a 4x4 matrix). If the entire array is None, or only a view instances, the view matrices for all, or these instances, respectively, will be derived from the current camera settings and be updated when the camera is moved.

update_shape_instance(name, pos=None, rot=None, color1=None, color2=None, visible=None)#

Update the instance properties of the shape

Parameters:
  • name – The name of the shape

  • pos – The position of the shape

  • rot – The rotation of the shape

  • color1 – The first color of the checker pattern

  • color2 – The second color of the checker pattern

  • visible – Whether the shape is visible

update_tile(tile_id, instances=None, projection_matrix=None, view_matrix=None, tile_size=None, tile_position=None)#

Update the shape instances, projection matrix, view matrix, tile size, or tile position for a given tile given its index.

Parameters:
  • tile_id – The index of the tile to update.

  • instances (list[int] | None) – A list of shape instance ids (optional).

  • projection_matrix (List[float] | List[List[float]] | ndarray | None) – A projection matrix (optional).

  • view_matrix (List[float] | List[List[float]] | ndarray | None) – A view matrix (optional).

  • tile_size (tuple[int] | None) – A (width, height) tuple specifying the size of the tile in pixels (optional).

  • tile_position (tuple[int] | None) – A (x, y) tuple specifying the position of the tile in pixels (optional).

use_unique_colors = True#