newton.viewer.ViewerViser#
- class newton.viewer.ViewerViser(*, port=8080, label=None, verbose=True, share=False, record_to_viser=None)[source]#
Bases:
ViewerBaseViewerViser provides a backend for visualizing Newton simulations using the viser library.
Viser is a Python library for interactive 3D visualization in the browser. This viewer launches a web server and renders simulation geometry via WebGL. It supports both standalone browser viewing and Jupyter notebook integration.
- Features:
Real-time 3D visualization in any web browser
Jupyter notebook integration with inline display
Static HTML export for sharing visualizations
Interactive camera controls
- __init__(*, port=8080, label=None, verbose=True, share=False, record_to_viser=None)#
Initialize the ViewerViser backend for Newton using the viser visualization library.
This viewer supports both standalone browser viewing and Jupyter notebook environments. It launches a web server that serves an interactive 3D visualization.
- Parameters:
port (int) – Port number for the web server. Defaults to 8080.
label (str | None) – Optional label for the viser server window title.
verbose (bool) – If True, print the server URL when starting. Defaults to True.
share (bool) – If True, create a publicly accessible URL via viser’s share feature.
record_to_viser (str | None) – Path to record the viewer to a
*.viserrecording file (e.g. “my_recording.viser”). If None, the viewer will not record to a file.
- apply_forces(state)#
Viser backend does not apply interactive forces.
- Parameters:
state (State) – Current simulation state.
- close()#
Close the viewer and clean up resources.
- end_frame()#
End the current frame.
If recording is active, inserts a sleep command for playback timing.
- is_running()#
Check if the viewer is still running.
- Returns:
True if the viewer is running, False otherwise.
- Return type:
- log_array(name, array)#
Viser viewer does not visualize generic arrays.
- Parameters:
name (str) – Unique path/name for the array signal.
array (wp.array(dtype=Any) | nparray) – Array data to visualize.
- log_geo(name, geo_type, geo_scale, geo_thickness, geo_is_solid, geo_src=None, hidden=False)#
Log a geometry primitive, with plane expansion for infinite planes.
- Parameters:
name (str) – Unique path/name for the geometry asset.
geo_type (int) – Geometry type value from newton.GeoType.
geo_scale (tuple[float, ...]) – Geometry scale tuple interpreted by geo_type.
geo_thickness (float) – Shell thickness for mesh-like geometry.
geo_is_solid (bool) – Whether mesh geometry is treated as solid.
geo_src (Mesh | Heightfield | None) – Optional source geometry for mesh-backed types.
hidden (bool) – Whether the resulting geometry is hidden.
- log_instances(name, mesh, xforms, scales, colors, materials, hidden=False)#
Log instanced mesh data to viser using efficient batched rendering.
Uses viser’s add_batched_meshes_simple for GPU-accelerated instanced rendering. Supports in-place updates of transforms for real-time animation.
- Parameters:
name (str) – Entity path for the instances.
mesh (str) – Name of the mesh asset to instance.
xforms (wp.array(dtype=wp.transform) | None) – Instance transforms.
scales (wp.array(dtype=wp.vec3) | None) – Instance scales.
colors (wp.array(dtype=wp.vec3) | None) – Instance colors.
materials (wp.array(dtype=wp.vec4) | None) – Instance materials.
hidden (bool) – Whether the instances are hidden.
- log_lines(name, starts, ends, colors, width=0.01, hidden=False)#
Log lines for visualization.
- Parameters:
name (str) – Name of the line batch.
starts (wp.array(dtype=wp.vec3) | None) – Line start points.
ends (wp.array(dtype=wp.vec3) | None) – Line end points.
colors (wp.array(dtype=wp.vec3) | wp.array(dtype=wp.float32) | tuple[float, float, float] | list[float] | None) – Line colors.
width (float) – Line width.
hidden (bool) – Whether the lines are hidden.
- log_mesh(name, points, indices, normals=None, uvs=None, texture=None, hidden=False, backface_culling=True)#
Log a mesh to viser for visualization.
- Parameters:
name (str) – Entity path for the mesh.
points (wp.array(dtype=wp.vec3)) – Vertex positions.
indices (wp.array(dtype=wp.int32) | wp.array(dtype=wp.uint32)) – Triangle indices.
normals (wp.array(dtype=wp.vec3) | None) – Vertex normals, unused in viser.
uvs (wp.array(dtype=wp.vec2) | None) – UV coordinates, used for textures if supported.
texture (np.ndarray | str | None) – Texture path/URL or image array (H, W, C).
hidden (bool) – Whether the mesh is hidden.
backface_culling (bool) – Whether to enable backface culling.
- log_points(name, points, radii=None, colors=None, hidden=False)#
Log points for visualization.
- Parameters:
name (str) – Name of the point batch.
points (wp.array(dtype=wp.vec3) | None) – Point positions (can be a wp.array or a numpy array).
radii (wp.array(dtype=wp.float32) | float | None) – Point radii (can be a wp.array or a numpy array).
colors (wp.array(dtype=wp.vec3) | wp.array(dtype=wp.float32) | tuple[float, float, float] | list[float] | None) – Point colors (can be a wp.array or a numpy array).
hidden (bool) – Whether the points are hidden.
- log_scalar(name, value)#
Viser viewer does not visualize scalar signals.
- save_recording()#
Save the current recording to a .viser file.
The recording can be played back in a static HTML viewer. See build_static_viewer() for creating the HTML player.
Note
Recording must be enabled by passing
record_to_viserto the constructor.Example
viewer = ViewerViser(record_to_viser="my_simulation.viser") # ... run simulation ... viewer.save_recording()
- set_camera(pos, pitch, yaw)#
Set camera position and orientation for connected Viser clients.
The requested view is also cached so that newly connected clients receive the same camera setup as soon as they report camera state.
- show_notebook(width='100%', height=400)#
Show the viewer in a Jupyter notebook.
If recording is active, saves the recording and displays using the static HTML viewer with timeline controls. Otherwise, displays the live server in an IFrame.
- Parameters:
- Returns:
The display object.
Example
viewer = newton.viewer.ViewerViser(record_to_viser="my_sim.viser") viewer.set_model(model) # ... run simulation ... viewer.show_notebook() # Saves recording and displays with timeline