newton.viewer.ViewerUSD#

class newton.viewer.ViewerUSD(output_path, fps=60, up_axis='Z', num_frames=100, scaling=1.0)[source]#

Bases: ViewerBase

USD viewer backend for Newton physics simulations.

This backend creates a USD stage and manages mesh prototypes and instanced rendering using PointInstancers. It supports time-sampled transforms for efficient playback and visualization of simulation data.

__init__(output_path, fps=60, up_axis='Z', num_frames=100, scaling=1.0)#

Initialize the USD viewer backend for Newton physics simulations.

Parameters:
  • output_path (str) – Path to the output USD file.

  • fps (int, optional) – Frames per second for time sampling. Default is 60.

  • up_axis (str, optional) – USD up axis, either ‘Y’ or ‘Z’. Default is ‘Z’.

  • num_frames (int, optional) – Maximum number of frames to record. Default is 100. If None, recording is unlimited.

  • scaling (float, optional) – Uniform scaling applied to the scene root. Default is 1.0.

Raises:

ImportError – If the usd-core package is not installed.

begin_frame(time)#

Begin a new frame at the given simulation time.

Parameters:

time (float) – The simulation time for the new frame.

close()#

Finalize and save the USD stage.

This should be called when all logging is complete to ensure the USD file is written.

end_frame()#

End the current frame.

This method is a placeholder for any end-of-frame logic required by the backend.

is_running()#

Check if the viewer is still running.

Returns:

False if the frame limit is exceeded, True otherwise.

Return type:

bool

log_array(name, array)#

Log array data (not implemented for USD backend).

This method is a placeholder and does not log array data in the USD backend.

log_instances(name, mesh, xforms, scales, colors, materials, hidden=False)#

Log a batch of mesh instances for rendering.

Parameters:
  • name (str) – Unique name for the instancer.

  • mesh (str) – Name of the base mesh.

  • xforms – Array of transforms.

  • scales – Array of scales.

  • colors – Array of colors.

  • materials – Array of materials.

  • hidden – Whether the instances are hidden.

log_instances_point_instancer(name, mesh, xforms, scales, colors, materials)#

Create or update a PointInstancer for mesh instances.

Parameters:
  • name (str) – Instancer name or Sdf.Path string.

  • mesh (str) – Mesh prototype name (must be previously logged).

  • xforms (wp.array) – Instance transforms as a warp array of wp.transform.

  • scales (wp.array) – Instance scales as a warp array of wp.vec3.

  • colors (wp.array) – Instance colors as a warp array of wp.vec3.

  • materials (wp.array) – Instance materials as a warp array of wp.vec4.

Raises:

RuntimeError – If the mesh prototype is not found.

log_lines(name, starts, ends, colors, width=0.01, hidden=False)#

Debug helper to add a line list as a set of capsules

Parameters:
  • starts – The vertices of the lines (wp.array)

  • ends – The vertices of the lines (wp.array)

  • colors – The colors of the lines (wp.array)

  • width (float) – The width of the lines (float)

  • hidden – Whether the lines are hidden (bool)

log_mesh(name, points, indices, normals=None, uvs=None, hidden=False, backface_culling=True)#

Create a USD mesh prototype from vertex and index data.

Parameters:
  • name (str) – Mesh name or Sdf.Path string.

  • points (wp.array) – Vertex positions as a warp array of wp.vec3.

  • indices (wp.array) – Triangle indices as a warp array of wp.uint32.

  • normals (wp.array, optional) – Vertex normals as a warp array of wp.vec3.

  • uvs (wp.array, optional) – UV coordinates as a warp array of wp.vec2.

  • hidden (bool, optional) – If True, mesh will be hidden. Default is False.

  • backface_culling (bool, optional) – If True, enable backface culling. Default is True.

Returns:

The mesh prototype path.

Return type:

str

log_points(name, points, radii, colors, hidden=False)#
log_scalar(name, value)#

Log scalar value (not implemented for USD backend).

This method is a placeholder and does not log scalar values in the USD backend.