Interactive Notebooks

Viser can display 3D visualizations inline in Jupyter notebooks and myst-nb documentation.

Static Scenes

Use viser.SceneApi.show() to display the current scene:

import viser

server = viser.ViserServer(verbose=False)
server.scene.add_box("/box", color=(255, 0, 0), dimensions=(1, 1, 1))
server.scene.show()

The visualization is interactive with orbit controls and works offline once loaded.

Optional parameters:

  • height: Height of the embedded viewer in pixels (default: 400)

  • dark_mode: Use dark color scheme (default: False)

Setting the Initial Camera

Use viser.ViserServer.initial_camera to set the camera pose when the visualization first loads:

import viser

server = viser.ViserServer()
server.scene.add_box("/box", color=(255, 0, 0), dimensions=(1, 1, 1))

# Set the initial camera pose.
server.initial_camera.position = (3.0, 3.0, 2.0)
server.initial_camera.look_at = (0.0, 0.0, 0.0)

server.scene.show()

Available properties: position, look_at, up, fov, near, far. See viser.InitialCameraConfig for details.

Animated Scenes

For animations, use viser.infra.StateSerializer.insert_sleep() to record timing between frames, then viser.infra.StateSerializer.show() to display:

import numpy as np

import viser

server = viser.ViserServer(verbose=False)
box = server.scene.add_box("/box", color=(255, 0, 0), dimensions=(1, 1, 1))

# Get the scene serializer for recording animations.
serializer = server.get_scene_serializer()

# Animate the box position over 3 seconds at 60 fps.
for i in range(180):
    t = i / 180 * 2 * np.pi
    box.position = (np.sin(t), np.cos(t), 0.5)
    serializer.insert_sleep(1.0 / 60.0)
serializer.show()