Camera posesΒΆ

Example showing how we can detect new clients and read camera poses from them.

 1import time
 2
 3import viser
 4
 5server = viser.ViserServer()
 6server.scene.world_axes.visible = True
 7
 8
 9@server.on_client_connect
10def _(client: viser.ClientHandle) -> None:
11    print("new client!")
12
13    # This will run whenever we get a new camera!
14    @client.camera.on_update
15    def _(_: viser.CameraHandle) -> None:
16        print(f"New camera on client {client.client_id}!")
17
18    # Show the client ID in the GUI.
19    gui_info = client.gui.add_text("Client ID", initial_value=str(client.client_id))
20    gui_info.disabled = True
21
22
23while True:
24    # Get all currently connected clients.
25    clients = server.get_clients()
26    print("Connected client IDs", clients.keys())
27
28    for id, client in clients.items():
29        print(f"Camera pose for client {id}")
30        print(f"\twxyz: {client.camera.wxyz}")
31        print(f"\tposition: {client.camera.position}")
32        print(f"\tfov: {client.camera.fov}")
33        print(f"\taspect: {client.camera.aspect}")
34        print(f"\tlast update: {client.camera.update_timestamp}")
35
36    time.sleep(2.0)