newton.viewer.ViewerUSD#
- class newton.viewer.ViewerUSD(output_path, fps=60, up_axis='Z', num_frames=100, scaling=1.0)[source]#
Bases:
ViewerBaseUSD 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) – Frames per second for time sampling. Default is 60.
up_axis (str) – USD up axis, either ‘Y’ or ‘Z’. Default is ‘Z’.
num_frames (int | None) – Maximum number of frames to record. Default is 100. If None, recording is unlimited.
scaling (float) – Uniform scaling applied to the scene root. Default is 1.0.
- Raises:
ImportError – If the usd-core package is not installed.
- apply_forces(state)#
USD backend does not apply interactive forces.
- Parameters:
state (State) – Current simulation state.
- 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:
- 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.
- Parameters:
name (str) – Unique path/name for the array signal.
array (wp.array(dtype=Any) | nparray) – Array data to visualize.
- 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 (wp.array(dtype=wp.transform) | None) – Array of transforms.
scales (wp.array(dtype=wp.vec3) | None) – Array of scales.
colors (wp.array(dtype=wp.vec3) | None) – Array of colors.
materials (wp.array(dtype=wp.vec4) | None) – Array of materials.
hidden (bool) – 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(dtype=wp.transform) | None) – Instance transforms as a warp array of wp.transform.
scales (wp.array(dtype=wp.vec3) | nparray | None) – Instance scales as a warp array of wp.vec3.
colors (wp.array(dtype=wp.vec3) | wp.array(dtype=wp.float32) | tuple[float, float, float] | list[float] | nparray | None) – Instance colors as a warp array of wp.vec3.
materials (wp.array(dtype=wp.vec4) | None) – 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:
name (str) – Unique name for the line batch.
starts (wp.array(dtype=wp.vec3) | None) – The vertices of the lines (wp.array)
ends (wp.array(dtype=wp.vec3) | None) – The vertices of the lines (wp.array)
colors (wp.array(dtype=wp.vec3) | wp.array(dtype=wp.float32) | tuple[float, float, float] | list[float] | None) – The colors of the lines (wp.array)
width (float) – The width of the lines.
hidden (bool) – Whether the lines are hidden.
- log_mesh(name, points, indices, normals=None, uvs=None, texture=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(dtype=wp.vec3)) – Vertex positions as a warp array of wp.vec3.
indices (wp.array(dtype=wp.int32) | wp.array(dtype=wp.uint32)) – Triangle indices as a warp array of wp.uint32.
normals (wp.array(dtype=wp.vec3) | None) – Vertex normals as a warp array of wp.vec3.
uvs (wp.array(dtype=wp.vec2) | None) – UV coordinates as a warp array of wp.vec2.
texture (np.ndarray | str | None) – Optional texture path/URL or image array.
hidden (bool) – If True, mesh will be hidden.
backface_culling (bool) – If True, enable backface culling.
- log_points(name, points, radii=None, colors=None, hidden=False)#
Log points as a USD Points primitive.
- Parameters:
name (str) – Unique name for the point primitive.
points (wp.array(dtype=wp.vec3) | None) – Point positions.
radii (wp.array(dtype=wp.float32) | float | None) – Point radii or a single shared radius.
colors (wp.array(dtype=wp.vec3) | wp.array(dtype=wp.float32) | tuple[float, float, float] | list[float] | None) – Optional per-point colors or a shared RGB triplet.
hidden (bool) – Whether the point primitive is hidden.
- Returns:
Sdf.Path of the created/updated points primitive.