Skip to main content

Class: GazeController

Defined in: src/input/GazeController.ts:31

Implements a gaze-based controller for XR interactions. This allows users to select objects by looking at them for a set duration. It functions as a virtual controller that is always aligned with the user's camera (head pose). WebXR Eye Tracking is not yet available. This API simulates a reticle at the center of the field of view for simulating gaze-based interaction.

Extends

  • Script<GazeControllerEventMap>

Implements

  • Controller

Constructors

Constructor

new GazeController(): GazeController

Defined in: node_modules/@types/three/src/core/Object3D.d.ts:95

This creates a new Object3D object.

Returns

GazeController

Inherited from

Script.constructor

Properties

activationAmount

activationAmount: AnimatableNumber

Defined in: src/input/GazeController.ts:55

An animatable number that tracks the progress of the gaze selection, from 0.0 to 1.0.


activationTimeSeconds

activationTimeSeconds: number = 1.5

Defined in: src/input/GazeController.ts:49

The time in seconds the user must gaze at an object to trigger a selection.


camera

camera: Camera

Defined in: src/input/GazeController.ts:70


clock

clock: Clock

Defined in: src/input/GazeController.ts:68

A clock to measure the time delta between frames for smooth animation and movement calculation.


isXRScript

isXRScript: boolean = true

Defined in: src/core/Script.ts:53

Inherited from

Script.isXRScript


lastReticlePosition

lastReticlePosition: Vector3

Defined in: src/input/GazeController.ts:62

Stores the reticle's position from the previous frame to calculate movement speed.


reticle

reticle: Reticle

Defined in: src/input/GazeController.ts:44

The visual indicator for where the user is looking.

Implementation of

Controller.reticle


userData

userData: object

Defined in: src/input/GazeController.ts:39

User data for the controller, including its connection status, unique ID, and selection state.

connected

connected: boolean = false

id

id: number = 2

selected

selected: boolean = false

Implementation of

Controller.userData

Overrides

Script.userData


ux

ux: UX

Defined in: src/core/Script.ts:52

Inherited from

Script.ux


dependencies

static dependencies: object

Defined in: src/input/GazeController.ts:33

camera

camera: typeof Camera = THREE.Camera

Methods

callSelectEnd()

callSelectEnd(): void

Defined in: src/input/GazeController.ts:125

Dispatches a 'selectend' event, signaling that a gaze selection has been released (e.g., by moving gaze).

Returns

void


callSelectStart()

callSelectStart(): void

Defined in: src/input/GazeController.ts:117

Dispatches a 'selectstart' event, signaling that a gaze selection has been initiated.

Returns

void


connect()

connect(): void

Defined in: src/input/GazeController.ts:132

Connects the gaze controller to the input system.

Returns

void


disconnect()

disconnect(): void

Defined in: src/input/GazeController.ts:139

Disconnects the gaze controller from the input system.

Returns

void


dispose()

dispose(): void

Defined in: src/core/Script.ts:196

Called when the script is removed from the scene. Opposite of init.

Returns

void

Inherited from

Script.dispose


init()

init(__namedParameters): void

Defined in: src/input/GazeController.ts:72

Initializes an instance with XR controllers, grips, hands, raycaster, and default options. We allow all scripts to quickly access its user (e.g., user.isSelecting(), user.hands), world (e.g., physical depth mesh, lighting estimation, and recognized objects), and scene (the root of three.js's scene graph). If this returns a promise, we will wait for it.

Parameters

__namedParameters
camera

Camera

Returns

void

Overrides

Script.init


initPhysics()

initPhysics(_physics): void | Promise<void>

Defined in: src/core/Script.ts:72

Enables depth-aware interactions with physics. See /demos/ballpit

Parameters

_physics

Physics

Returns

void | Promise<void>

Inherited from

Script.initPhysics


onHoverEnter()

onHoverEnter(_controller): void

Defined in: src/core/Script.ts:157

Called when the controller starts hovering over this object with reticle.

Parameters

_controller

Object3D

An XR controller.

Returns

void

Inherited from

Script.onHoverEnter


onHoverExit()

onHoverExit(_controller): void

Defined in: src/core/Script.ts:162

Called when the controller hovers over this object with reticle.

Parameters

_controller

Object3D

An XR controller.

Returns

void

Inherited from

Script.onHoverExit


onHovering()

onHovering(_controller): void

Defined in: src/core/Script.ts:167

Called when the controller hovers over this object with reticle.

Parameters

_controller

Object3D

An XR controller.

Returns

void

Inherited from

Script.onHovering


onKeyDown()

onKeyDown(_event): void

Defined in: src/core/Script.ts:109

Called on keyboard keypress.

Parameters

_event

KeyEvent

Event containing .code to read the keyboard key.

Returns

void

Inherited from

Script.onKeyDown


onKeyUp()

onKeyUp(_event): void

Defined in: src/core/Script.ts:110

Parameters

_event

KeyEvent

Returns

void

Inherited from

Script.onKeyUp


onObjectGrabbing()

onObjectGrabbing(_event): void

Defined in: src/core/Script.ts:187

Called every frame a hand is grabbing this object.

Parameters

_event

ObjectGrabEvent

Returns

void

Inherited from

Script.onObjectGrabbing


onObjectGrabEnd()

onObjectGrabEnd(_event): void

Defined in: src/core/Script.ts:191

Called when a hand stops grabbing this object.

Parameters

_event

ObjectGrabEvent

Returns

void

Inherited from

Script.onObjectGrabEnd


onObjectGrabStart()

onObjectGrabStart(_event): void

Defined in: src/core/Script.ts:183

Called when a hand starts grabbing this object (touching + pinching).

Parameters

_event

ObjectGrabEvent

Returns

void

Inherited from

Script.onObjectGrabStart


onObjectSelectEnd()

onObjectSelectEnd(_event): boolean

Defined in: src/core/Script.ts:150

Called when the controller stops selecting this object the script represents, e.g. View, ModelView.

Parameters

_event

SelectEvent

event.target holds its controller.

Returns

boolean

Whether the event was handled

Inherited from

Script.onObjectSelectEnd


onObjectSelectStart()

onObjectSelectStart(_event): boolean

Defined in: src/core/Script.ts:141

Called when the controller starts selecting this object the script represents, e.g. View, ModelView.

Parameters

_event

SelectEvent

event.target holds its controller.

Returns

boolean

Whether the event was handled

Inherited from

Script.onObjectSelectStart


onObjectTouchEnd()

onObjectTouchEnd(_event): void

Defined in: src/core/Script.ts:179

Called when a hand's index finger stops touching this object.

Parameters

_event

ObjectTouchEvent

Returns

void

Inherited from

Script.onObjectTouchEnd


onObjectTouching()

onObjectTouching(_event): void

Defined in: src/core/Script.ts:175

Called every frame that a hand's index finger is touching this object.

Parameters

_event

ObjectTouchEvent

Returns

void

Inherited from

Script.onObjectTouching


onObjectTouchStart()

onObjectTouchStart(_event): void

Defined in: src/core/Script.ts:171

Called when a hand's index finger starts touching this object.

Parameters

_event

ObjectTouchEvent

Returns

void

Inherited from

Script.onObjectTouchStart


onSelect()

onSelect(_event): void

Defined in: src/core/Script.ts:98

Called whenever pinch / mouse click successfully completes, globally.

Parameters

_event

SelectEvent

event.target holds its controller.

Returns

void

Inherited from

Script.onSelect


onSelectEnd()

onSelectEnd(_event): void

Defined in: src/core/Script.ts:92

Called whenever pinch / mouse click discontinues, globally.

Parameters

_event

SelectEvent

event.target holds its controller

Returns

void

Inherited from

Script.onSelectEnd


onSelecting()

onSelecting(_event): void

Defined in: src/core/Script.ts:103

Called whenever pinch / mouse click is happening, globally.

Parameters

_event

SelectEvent

Returns

void

Inherited from

Script.onSelecting


onSelectStart()

onSelectStart(_event): void

Defined in: src/core/Script.ts:86

Called whenever pinch / mouse click starts, globally.

Parameters

_event

SelectEvent

event.target holds its controller

Returns

void

Inherited from

Script.onSelectStart


onSimulatorStarted()

onSimulatorStarted(): void

Defined in: src/core/Script.ts:78

Returns

void

Inherited from

Script.onSimulatorStarted


onSqueeze()

onSqueeze(_event): void

Defined in: src/core/Script.ts:132

Called whenever gamepad trigger successfully completes, globally.

Parameters

_event

SelectEvent

event.target holds its controller.

Returns

void

Inherited from

Script.onSqueeze


onSqueezeEnd()

onSqueezeEnd(_event): void

Defined in: src/core/Script.ts:121

Called whenever gamepad trigger stops, globally.

Parameters

_event

SelectEvent

event.target holds its controller.

Returns

void

Inherited from

Script.onSqueezeEnd


onSqueezeStart()

onSqueezeStart(_event): void

Defined in: src/core/Script.ts:116

Called whenever gamepad trigger starts, globally.

Parameters

_event

SelectEvent

event.target holds its controller.

Returns

void

Inherited from

Script.onSqueezeStart


onSqueezing()

onSqueezing(_event): void

Defined in: src/core/Script.ts:126

Called whenever gamepad is being triggered, globally.

Parameters

_event

SelectEvent

Returns

void

Inherited from

Script.onSqueezing


onXRSessionEnded()

onXRSessionEnded(): void

Defined in: src/core/Script.ts:76

Returns

void

Inherited from

Script.onXRSessionEnded


onXRSessionStarted()

onXRSessionStarted(_session?): void

Defined in: src/core/Script.ts:75

Parameters

_session?

XRSession

Returns

void

Inherited from

Script.onXRSessionStarted


physicsStep()

physicsStep(): void

Defined in: src/core/Script.ts:73

Returns

void

Inherited from

Script.physicsStep


update()

update(): void

Defined in: src/input/GazeController.ts:81

The main update loop, called every frame by the core engine. It handles syncing the controller with the camera and manages the gaze selection logic.

Returns

void

Overrides

Script.update


updateReticleScale()

updateReticleScale(): void

Defined in: src/input/GazeController.ts:109

Updates the reticle's scale and shader uniforms to provide visual feedback for gaze activation. The reticle shrinks and fills in as the activation timer progresses.

Returns

void