Camera Handles

class viser.CameraHandle[source]

A handle for reading and writing the camera state of a particular client. Typically accessed via ClientHandle.camera.

property client: ClientHandle

Client that this camera corresponds to.

property wxyz: ndarray[tuple[Any, ...], dtype[float64]]

Corresponds to the R in P_world = [R | t] p_camera. Synchronized automatically when assigned.

property position: ndarray[tuple[Any, ...], dtype[float64]]

Corresponds to the t in P_world = [R | t] p_camera. Synchronized automatically when assigned.

To preserve the camera orientation, position updates translate both the camera and its look_at point together. To change position while looking at a fixed point, set look_at after updating position.

property fov: float

Vertical field of view of the camera, in radians. Synchronized automatically when assigned.

property near: float

Near clipping plane distance. Synchronized automatically when assigned.

property far: float

Far clipping plane distance. Synchronized automatically when assigned.

property aspect: float

Canvas width divided by height. Not assignable.

property image_height: int

Image height in pixels. Not assignable.

property image_width: int

Image width in pixels. Not assignable.

property update_timestamp: float
property look_at: ndarray[tuple[Any, ...], dtype[float64]]

Look at point for the camera. Synchronized automatically when set.

property up_direction: ndarray[tuple[Any, ...], dtype[float64]]

Up direction for the camera. Synchronized automatically when set.

on_update(callback: Callable[[CameraHandle], NoneOrCoroutine]) Callable[[CameraHandle], NoneOrCoroutine][source]

Attach a callback to run when a new camera message is received.

The callback can be either a standard function or an async function: - Standard functions (def) will be executed in a threadpool. - Async functions (async def) will be executed in the event loop.

Using async functions can be useful for reducing race conditions.

Parameters:

callback (Callable[[CameraHandle], NoneOrCoroutine])

Return type:

Callable[[CameraHandle], NoneOrCoroutine]

get_render(height: int, width: int, transport_format: Literal['png', 'jpeg'] = 'jpeg') ndarray[source]

Request a render from a client, block until it’s done and received, then return it as a numpy array. This is an alias for ClientHandle.get_render().

Parameters:
  • height (int) – Height of rendered image. Should be <= the browser height.

  • width (int) – Width of rendered image. Should be <= the browser width.

  • transport_format (Literal['png', 'jpeg']) – Image transport format. JPEG will return a lossy (H, W, 3) RGB array. PNG will return a lossless (H, W, 4) RGBA array, but can cause memory issues on the frontend if called too quickly for higher-resolution images.

Return type:

ndarray

Initial Camera Configuration

class viser.InitialCameraConfig[source]

Configuration for the initial camera pose.

Accessed via ViserServer.initial_camera. Values set here determine:

  1. The starting camera pose for new client connections

  2. The pose that “Reset View” returns to in the client

Default values:
  • position: (3.0, 3.0, 3.0)

  • look_at: (0.0, 0.0, 0.0)

  • up: (0.0, 0.0, 1.0)

  • fov: 50 degrees (~0.873 radians, Three.js default)

  • near: 0.01

  • far: 1000.0

When properties are changed after clients are connected, only the “Reset View” target is updated. Clients’ current camera positions are not moved, allowing users to continue working undisturbed.

Note that URL parameters (e.g., ?initialCameraPosition=1,2,3) take priority over server-set values.

The API is designed to match CameraHandle, which is used for per-client camera control.

DEFAULT_FOV: float = 0.8726646259971648
property position: ndarray[tuple[Any, ...], dtype[float64]]

Camera position in world coordinates.

property look_at: ndarray[tuple[Any, ...], dtype[float64]]

Point the camera looks at in world coordinates.

property up: ndarray[tuple[Any, ...], dtype[float64]]

Camera up direction.

property fov: float

Vertical field of view in radians.

property near: float

Near clipping plane distance.

property far: float

Far clipping plane distance.