Coordinate frames

Visualize 3D coordinate systems and hierarchical transformations.

This example demonstrates how to create and organize coordinate frames using viser.SceneApi.add_frame(). Coordinate frames are essential for understanding spatial relationships in 3D scenes and are commonly used in robotics, computer graphics, and 3D reconstruction applications.

Key concepts:

  • Hierarchical naming: Scene nodes follow a filesystem-like structure (/tree/branch/leaf)

  • Relative positioning: Child frames are positioned relative to their parent frames

  • Dynamic scene management: Frames can be added and removed during runtime with viser.SceneNodeHandle.remove()

The hierarchical structure allows for complex transformations where moving a parent frame automatically moves all its children, making it perfect for modeling articulated objects, robot arms, or nested coordinate systems.

Source: examples/01_scene/00_coordinate_frames.py

Coordinate frames

Code

 1import random
 2import time
 3
 4import viser
 5
 6server = viser.ViserServer()
 7
 8while True:
 9    # Add some coordinate frames to the scene. These will be visualized in the viewer.
10    server.scene.add_frame(
11        "/tree",
12        wxyz=(1.0, 0.0, 0.0, 0.0),
13        position=(random.random() * 2.0, 2.0, 0.2),
14    )
15    server.scene.add_frame(
16        "/tree/branch",
17        wxyz=(1.0, 0.0, 0.0, 0.0),
18        position=(random.random() * 2.0, 2.0, 0.2),
19    )
20    leaf = server.scene.add_frame(
21        "/tree/branch/leaf",
22        wxyz=(1.0, 0.0, 0.0, 0.0),
23        position=(random.random() * 2.0, 2.0, 0.2),
24    )
25
26    # Move the leaf randomly. Assigned properties are automatically updated in
27    # the visualizer.
28    for i in range(10):
29        leaf.position = (random.random() * 2.0, 2.0, 0.2)
30        time.sleep(0.5)
31
32    # Remove the leaf node from the scene.
33    leaf.remove()
34    time.sleep(0.5)