Events¶
We define a small set of event types, which are passed to callback functions when events like clicks or GUI updates are triggered.
- class viser.CommandEvent[source]¶
Information associated with a command trigger from the command palette.
Passed as input to callback functions.
clientandclient_idare typed Optional for parity withGuiEvent(which can fire server-side) and to leave room for a future programmatichandle.trigger()path. In practice, every command trigger today originates from a real client – the dispatcher drops the event if the client can’t be resolved, so callbacks only see non-None values.- client: ClientHandle | None¶
Client that triggered this command.
- target: CommandHandle¶
Command handle that was triggered.
- class viser.GuiEvent[source]¶
Information associated with a GUI event, such as an update or click.
Passed as input to callback functions.
- client: ClientHandle | None¶
Client that triggered this event.
- target: TGuiHandle¶
GUI element that was affected.
- class viser.SceneClickEvent[source]¶
Event passed to scene-level click callbacks (
SceneApi.on_click).- client: ClientHandle¶
Client that triggered this event.
- ray_origin: tuple[float, float, float]¶
Origin of the 3D ray corresponding to this click, in world coordinates.
- ray_direction: tuple[float, float, float]¶
Direction of the 3D ray corresponding to this click, in world coordinates.
- class viser.SceneNodeDragEvent[source]¶
Event passed to scene-node drag callbacks.
- client: ClientHandle¶
Client that triggered this event.
- target: TSceneNodeHandle¶
Scene node that is being dragged.
- phase: DragPhase¶
"start"at press,"update"on every throttled pointermove (~20Hz),"end"at release. A single drag fires exactly one"start", zero or more"update"``s, and exactly one ``"end".- Type:
Drag lifecycle phase
- instance_index: int | None¶
Instance index within a batched scene node (e.g. batched meshes, batched GLBs, batched axes);
Nonefor non-batched nodes. Frozen at drag-start – the drag always refers to the instance that was under the cursor when the gesture began.
- start_position: Tuple[float, float, float]¶
World-coords position of the click point on the object. Live – updates each event as the object moves, so it always reflects where the grab point currently is in world coords (useful for rotate-around-grab gestures).
- end_position: Tuple[float, float, float]¶
Current pointer projected onto the camera-aligned drag plane, in world coords.
- button: Literal['left', 'middle', 'right']¶
Mouse button that initiated the drag.
- class viser.SceneNodePointerEvent[source]¶
Event passed to pointer callbacks for scene nodes (currently only clicks).
- client: ClientHandle¶
Client that triggered this event.
- event: Literal['click']¶
Type of event that was triggered. Currently we only support clicks.
- target: TSceneNodeHandle¶
Scene node that was clicked.
- ray_origin: tuple[float, float, float]¶
Origin of 3D ray corresponding to this click, in world coordinates.
- ray_direction: tuple[float, float, float]¶
Direction of 3D ray corresponding to this click, in world coordinates.
- screen_pos: tuple[float, float]¶
Screen position of the click on the screen (OpenCV image coordinates, 0 to 1). (0, 0) is the upper-left corner, (1, 1) is the bottom-right corner.
- instance_index: int | None¶
Instance ID of the clicked object, if applicable. Currently this is None for all objects except for the output of
SceneApi.add_batched_axes().
- class viser.ScenePointerEvent[source]¶
Event passed to scene pointer callbacks (legacy
on_pointer_event).Deprecated since version Use:
SceneApi.on_click()withSceneClickEventorSceneApi.on_rect_select()withSceneRectSelectEventinstead. This shape unions the click and rect-select cases into a single dataclass with awkward Optional/variable-length fields.- client: ClientHandle¶
Client that triggered this event.
- event_type: _messages.ScenePointerEventType¶
Type of event that was triggered. Currently we only support clicks and box selections.
- ray_origin: tuple[float, float, float] | None¶
Origin of 3D ray corresponding to this click, in world coordinates.
- ray_direction: tuple[float, float, float] | None¶
Direction of 3D ray corresponding to this click, in world coordinates.
- screen_pos: tuple[tuple[float, float], ...]¶
Screen position of the click on the screen (OpenCV image coordinates, 0 to 1). (0, 0) is the upper-left corner, (1, 1) is the bottom-right corner. For a box selection, this includes the min- and max- corners of the box.
- modifier: _messages.KeyModifier | None¶
Modifier-combo held when this event fired.
Noneif no modifiers were held; otherwise a canonicalKeyModifierstring.
- property event¶
Deprecated. Use event_type instead.
Deprecated since version 0.2.23: The event property is deprecated. Use event_type instead.
- class viser.SceneRectSelectEvent[source]¶
Event passed to scene rectangle-select callbacks (
SceneApi.on_rect_select).- client: ClientHandle¶
Client that triggered this event.
- class viser.TransformControlsEvent[source]¶
Event passed to callbacks for transform control updates.
- client: ClientHandle | None¶
Client that triggered this event.
- target: TransformControlsHandle¶
Transform controls handle that was affected.
- phase: DragPhase¶
"start"when the user grabs a handle,"update"on every pose change while dragging,"end"at release.target.wxyzandtarget.positionreflect the current pose on every phase (start/end fire at the same pose as the surrounding update).- Type:
Drag lifecycle phase