warp.render#
The warp.render
module provides a set of renderers that can be used for visualizing scenes involving shapes of various types.
Built on top of these stand-alone renderers, the warp.sim.render
module provides renderers that can be used to visualize scenes directly from warp.sim.ModelBuilder
objects and update them from warp.sim.State
objects.
Stand-alone renderers#
The OpenGLRenderer
provides an interactive renderer to play back animations in real time, the UsdRenderer
provides a renderer that exports the scene to a USD file that can be rendered in a renderer of your choice.
- class warp.render.UsdRenderer(stage, up_axis='Y', fps=60, scaling=1.0)#
A USD renderer
Construct a UsdRenderer object
- Parameters:
model – A simulation model
stage (str/Usd.Stage) – A USD stage (either in memory or on disk)
up_axis (str) – The upfacing axis of the stage
fps – The number of frames per second to use in the USD file
scaling – Scaling factor to use for the entities in the scene
- render_plane(name, pos, rot, width, length, color=None, parent_body=None, is_template=False)#
Render a plane with the given dimensions.
- Parameters:
name (str) – Name of the plane
pos (tuple) – Position of the plane
rot (tuple) – Rotation of the plane
width (float) – Width of the plane
length (float) – Length of the plane
color (tuple | None) – Color of the plane
parent_body (str | None) – Name of the parent body
is_template (bool) – Whether the plane is a template
- render_sphere(name, pos, rot, radius, parent_body=None, is_template=False, color=None)#
Debug helper to add a sphere for visualization
- render_capsule(name, pos, rot, radius, half_height, parent_body=None, is_template=False, color=None)#
Debug helper to add a capsule for visualization
- Parameters:
- render_cylinder(name, pos, rot, radius, half_height, parent_body=None, is_template=False, color=None)#
Debug helper to 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
color (tuple | None) – The color of the cylinder
rot (tuple) –
parent_body (str | None) –
is_template (bool) –
- render_cone(name, pos, rot, radius, half_height, parent_body=None, is_template=False, color=None)#
Debug helper to add a cone for visualization
- render_box(name, pos, rot, extents, parent_body=None, is_template=False, color=None)#
Debug helper to add a box for visualization
- render_line_list(name, vertices, indices, color, radius)#
Debug helper to add a line list as a set of capsules
- Parameters:
vertices – The vertices of the line-strip
color – The color of the line
time – The time to update at
- class warp.render.OpenGLRenderer(title='Warp sim', scaling=1.0, fps=60, up_axis='Y', screen_width=1024, screen_height=768, near_plane=1.0, far_plane=100.0, camera_fov=45.0, camera_pos=(0.0, 2.0, 10.0), camera_front=(0.0, 0.0, -1.0), camera_up=(0.0, 1.0, 0.0), background_color=(0.53, 0.8, 0.92), draw_grid=True, draw_sky=True, draw_axis=True, show_info=True, render_wireframe=False, render_depth=False, axis_scale=1.0, vsync=False, headless=False, enable_backface_culling=True, enable_mouse_interaction=True, enable_keyboard_interaction=True)#
OpenGLRenderer is a simple OpenGL renderer for rendering 3D shapes and meshes.
- 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.
- 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.
tile_nrows (int | None) –
- 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).
- 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.
- update_shape_instance(name, pos=None, rot=None, color1=None, color2=None, visible=None)#
Update the instance transform 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
- 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
andtile_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:
- 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)#
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)
parent_body (str | None) –
is_template (bool) –
- render_ground(size=1000.0, plane=None)#
Add a ground plane for visualization
- Parameters:
size (float) – The size of the ground plane
- render_sphere(name, pos, rot, radius, parent_body=None, is_template=False, color=None)#
Add a sphere for visualization
- render_capsule(name, pos, rot, radius, half_height, parent_body=None, is_template=False, up_axis=1, color=None)#
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 | None) – The color of the capsule
rot (tuple) –
parent_body (str | None) –
is_template (bool) –
- render_cylinder(name, pos, rot, radius, half_height, parent_body=None, is_template=False, up_axis=1, color=None)#
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 | None) – The color of the capsule
rot (tuple) –
parent_body (str | None) –
is_template (bool) –
- render_cone(name, pos, rot, radius, half_height, parent_body=None, is_template=False, up_axis=1, color=None)#
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 | None) – The color of the cone
rot (tuple) –
parent_body (str | None) –
is_template (bool) –
- render_box(name, pos, rot, extents, parent_body=None, is_template=False, color=None)#
Add a box for visualization
- 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)#
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
parent_body (str | None) –
is_template (bool) –
- 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)#
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)
rot (tuple) –
parent_body (str | None) –
is_template (bool) –
- render_ref(name, path, pos, rot, scale, color=None)#
Create a reference (instance) with the given name to the given path.
- render_points(name, points, radius, colors=None)#
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_line_list(name, vertices, indices, color=None, radius=0.01)#
Add a line list as a set of capsules
Simulation renderers#
Based on these renderers from warp.render
, the SimRendererUsd
(which equals SimRenderer
) and SimRendererOpenGL
classes from warp.sim.render
are derived to populate the renderers directly from warp.sim.ModelBuilder
scenes and update them from warp.sim.State
objects.
- warp.sim.render.SimRendererUsd#
alias of
SimRenderer
- warp.sim.render.SimRendererOpenGL#
alias of
SimRenderer