newton.viewer.ViewerViser#

class newton.viewer.ViewerViser(*, port=8080, label=None, verbose=True, share=False, record_to_viser=None)[source]#

Bases: ViewerBase

ViewerViser 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 *.viser recording file (e.g. “my_recording.viser”). If None, the viewer will not record to a file.

begin_frame(time)#

Begin a new frame.

Parameters:

time (float) – The current simulation time.

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:

bool

log_array(name, array)#

Viser viewer doesn’t log arrays visually, so this is a no-op.

log_geo(name, geo_type, geo_scale, geo_thickness, geo_is_solid, geo_src=None, hidden=False)#

Log geometry primitives.

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) – Instance transforms (wp.transform).

  • scales (wp.array) – Instance scales (wp.vec3).

  • colors (wp.array) – Instance colors (wp.vec3).

  • materials (wp.array) – Instance materials (wp.vec4).

  • 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 – Line start points.

  • ends – Line end points.

  • colors – 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) – Vertex positions (wp.vec3).

  • indices (wp.array) – Triangle indices (wp.uint32).

  • normals (wp.array, optional) – Vertex normals, unused in viser (wp.vec3).

  • uvs (wp.array, optional) – UV coordinates, used for textures if supported.

  • texture (np.ndarray | str, optional) – 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 – Point positions (can be a wp.array or a numpy array).

  • radii – Point radii (can be a wp.array or a numpy array).

  • colors – Point colors (can be a wp.array or a numpy array).

  • hidden (bool) – Whether the points are hidden.

log_scalar(name, value)#

Viser viewer doesn’t log scalars visually, so this is a no-op.

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_viser to the constructor.

Example

viewer = ViewerViser(record_to_viser="my_simulation.viser")
# ... run simulation ...
viewer.save_recording()
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:
  • width (int | str) – Width of the embedded player in pixels.

  • height (int | str) – Height of the embedded player in pixels.

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
property url: str#

Get the URL of the viser server.