viser: 3D Visualization for Computer Vision and Robotics
Viser is a Python library designed for interactive 3D visualization, primarily targeting applications in computer vision and robotics. It provides a rich API for visualizing 3D primitives and constructing interactive GUI elements, all delivered through a responsive, web-based client that enables easy use over SSH and in Jupyter notebooks. The library is actively maintained with frequent releases, currently at version 1.0.26.
Warnings
- breaking When updating properties of `SceneNodeHandles` (e.g., position, orientation), explicit reassignment of the entire property is required, especially when modifying NumPy arrays in-place. Direct in-place modification of array elements might not trigger updates to the client for versions `0.2.10` and later.
- gotcha Viser enforces strict version compatibility between the Python backend and the web client. If the client (served by the browser) and the Python server versions do not match, the connection will be rejected with a protocol error (code 1002). This is a security and stability feature to prevent mismatched functionality.
- gotcha On some Windows systems, users have reported issues where the Viser web client fails to load due to a 'Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/plain"' error. This is often caused by missing or incorrect `.js` MIME type definitions in the Windows registry.
- gotcha Viser's API is inherently stateful, and all data transfers between the Python server and the web client occur over a WebSocket connection. This can introduce network overhead, especially for frequent, high-bandwidth updates or complex user interactions requiring round-trip communication. Static web page exports with full interactivity are not directly supported.
Install
-
pip install viser -
pip install "viser[examples]"
Imports
- ViserServer
from viser import ViserServer
Quickstart
import time
import numpy as np
from viser import ViserServer
# Create a Viser server
server = ViserServer(port=8080, label='My Viser App')
print(f"Viser server started at: http://localhost:{server.get_port()}")
# Add a red sphere to the scene
server.scene.add_sphere(
name="/my_sphere",
position=(0.0, 0.0, 0.0),
radius=0.5,
color=(1.0, 0.0, 0.0)
)
# Add a simple GUI slider to control sphere's X position
x_position_slider = server.gui.add_slider(
name="Sphere X Position",
min=-2.0,
max=2.0,
step=0.1,
initial_value=0.0
)
@x_position_slider.on_update
def _(field):
current_position = list(server.scene["/my_sphere"].position)
current_position[0] = field.value
server.scene["/my_sphere"].position = tuple(current_position)
# Keep the server running indefinitely
server.sleep_forever()