Skip to main content

Class: GamepadController

Defined in: src/input/GamepadController.ts:23

Simulates an XR controller using a connected gamepad (Xbox/PS). The controller ray always points forward from the camera center, similar to GazeController but with button-driven selection.

Extends​

  • Script<GamepadControllerEventMap>

Implements​

Constructors​

Constructor​

new GamepadController(): GamepadController

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

Returns​

GamepadController

Overrides​

Script.constructor

Properties​

activeGamepad?​

optional activeGamepad: Gamepad | null

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

The browser Gamepad object, refreshed each frame.


bindings​

bindings: GamepadBindings

Defined in: src/input/GamepadController.ts:36


camera?​

optional camera: Camera

Defined in: src/input/GamepadController.ts:35


gamepad?​

optional gamepad: Gamepad

Defined in: src/input/GamepadController.ts:40

Implementation of​

Controller.gamepad


hasShownToast​

hasShownToast: boolean = false

Defined in: src/input/GamepadController.ts:43

True if the toast has been shown this session.


isXRScript​

isXRScript: boolean = true

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

Inherited from​

ModelViewer.isXRScript


menuActive: boolean = false

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

When true, normal gamepad UI/select actions are suppressed (modal menu).


name​

name: string = 'Gamepad Controller'

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

Optional name of the object

Remarks​

(doesn't need to be unique).

Default Value​

""

Implementation of​

Controller.name

Overrides​

Script.name


onOpenSettings()?​

optional onOpenSettings: () => void

Defined in: src/input/GamepadController.ts:46

Callback set by SimulatorInterface for opening settings.

Returns​

void


type​

type: string = 'GamepadController'

Defined in: src/input/GamepadController.ts:30

A Read-only string to check this object type.

Remarks​

This can be used to find a specific type of Object3D in a scene. Sub-classes will update this value.

Default Value​

Object3D

Implementation of​

Controller.type

Overrides​

Script.type


userData​

userData: object

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

An object that can be used to store custom data about the Object3D.

connected​

connected: boolean = false

id​

id: number = 4

selected​

selected: boolean = false

Remarks​

It should not hold references to functions as these will not be cloned.

Default​

{}

Implementation of​

Controller.userData

Overrides​

Script.userData


xb?​

optional xb: XBObjectOptions

Defined in: src/interaction/InteractionTypes.ts:34

Implementation of​

Controller.xb

Inherited from​

Script.xb


dependencies​

static dependencies: object

Defined in: src/input/GamepadController.ts:27

camera​

camera: typeof Camera = THREE.Camera

Accessors​

captureActive​

Get Signature​

get captureActive(): boolean

Defined in: src/input/GamepadController.ts:75

Returns​

boolean

Methods​

callSelectEnd()​

callSelectEnd(): void

Defined in: src/input/GamepadController.ts:143

Returns​

void


callSelectStart()​

callSelectStart(): void

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

Returns​

void


cancelCapture()​

cancelCapture(): void

Defined in: src/input/GamepadController.ts:71

Returns​

void


captureNextButtonPress()​

captureNextButtonPress(callback): void

Defined in: src/input/GamepadController.ts:67

Enters capture mode — the next button press will invoke the callback instead of triggering normal actions, then exit capture mode.

Parameters​

callback​

(buttonIndex) => void

Returns​

void


connect()​

connect(): void

Defined in: src/input/GamepadController.ts:147

Returns​

void


disconnect()​

disconnect(): void

Defined in: src/input/GamepadController.ts:151

Returns​

void


dispose()​

dispose(): void

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

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

Returns​

void

Implementation of​

Controller.dispose

Inherited from​

Script.dispose


getAxes()​

getAxes(): [number, number, number, number]

Defined in: src/input/GamepadController.ts:159

Returns the axes of the active gamepad with deadzone applied. [leftX, leftY, rightX, rightY]

Returns​

[number, number, number, number]


getButtonValue()​

getButtonValue(index): number

Defined in: src/input/GamepadController.ts:181

Returns the analog value (0..1) of the given button index, or 0 if unbound or no gamepad. Useful for triggers (which expose .value).

Parameters​

index​

number

Returns​

number


getTriggers()​

getTriggers(): [number, number]

Defined in: src/input/GamepadController.ts:190

Returns the analog values of the left and right triggers (LT, RT) on a standard-mapped gamepad, in [0, 1]. Returns [0, 0] when no gamepad.

Returns​

[number, number]


init()​

init(__namedParameters): void

Defined in: src/input/GamepadController.ts:59

Initializes an instance with XR controllers, grips, hands, 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:119

Enables depth-aware interactions with physics. See /samples/advanced/ballpit

Parameters​

_physics​

Physics

Returns​

void | Promise<void>

Inherited from​

Script.initPhysics


isButtonJustPressed()​

isButtonJustPressed(buttonIndex): boolean

Defined in: src/input/GamepadController.ts:200

Returns true if the given button index had a rising edge this frame. Safe to call from any update order — uses pre-computed edges.

Parameters​

buttonIndex​

number

Returns​

boolean


onHoverEnter()​

onHoverEnter(_event): void

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

Called when a source starts hovering over this object.

Parameters​

_event​

HoverEvent

The hover source, target, surface, and intersection. Call event.stopPropagation() to stop bubbling to ancestor Scripts.

Returns​

void

Inherited from​

Script.onHoverEnter


onHoverExit()​

onHoverExit(_event): void

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

Called when a source stops hovering over this object.

Parameters​

_event​

HoverEvent

The hover source, target, surface, and intersection. Call event.stopPropagation() to stop bubbling to ancestor Scripts.

Returns​

void

Inherited from​

Script.onHoverExit


onHovering()​

onHovering(_event): void

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

Called while a source hovers over this object.

Parameters​

_event​

HoverEvent

The hover source, target, surface, and intersection. Call event.stopPropagation() to stop bubbling to ancestor Scripts.

Returns​

void

Inherited from​

Script.onHovering


onKeyDown()​

onKeyDown(_event): void

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

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:160

Parameters​

_event​

KeyEvent

Returns​

void

Inherited from​

Script.onKeyUp


onLongSelect()​

onLongSelect(_event): void

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

Called when an object selection reaches the long-select delay.

Parameters​

_event​

LongSelectEvent

Returns​

void

Inherited from​

Script.onLongSelect


onObjectGrabbing()​

onObjectGrabbing(_event): void

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

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:265

Called when a hand stops grabbing this object. This ends built-in direct-touch manipulation without ending contact.

Parameters​

_event​

ObjectGrabEvent

Returns​

void

Inherited from​

Script.onObjectGrabEnd


onObjectGrabStart()​

onObjectGrabStart(_event): void

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

Called when a hand starts grabbing this object (touching + pinching). A grab starts built-in direct-touch manipulation when enabled.

Parameters​

_event​

ObjectGrabEvent

Returns​

void

Inherited from​

Script.onObjectGrabStart


onObjectLongSelect()​

onObjectLongSelect(_event): void

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

Called once when a captured selection is held for the long-select delay. Manipulation captures do not emit this callback.

Parameters​

_event​

LongSelectEvent

The controller and completed hold duration. Call event.stopPropagation() to stop bubbling to ancestor Scripts. Call event.stopGlobalPropagation() to suppress global selection callbacks for the rest of this capture

Returns​

void

Inherited from​

Script.onObjectLongSelect


onObjectManipulate()​

onObjectManipulate(_event): void

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

Called for each phase of an automatic object manipulation. Call event.stopPropagation() to stop bubbling. Calling preventDefault() on a start event suppresses the automatic action.

Parameters​

_event​

ManipulationEvent

Returns​

void

Inherited from​

Script.onObjectManipulate


onObjectSelectEnd()​

onObjectSelectEnd(_event): void

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

Called when a source stops selecting the object this Script represents.

Parameters​

_event​

SelectEndEvent

The completed state and end reason. Call event.stopPropagation() to stop bubbling to ancestor Scripts. Call event.stopGlobalPropagation() to suppress global selection callbacks for the rest of this capture

Returns​

void

Inherited from​

Script.onObjectSelectEnd


onObjectSelectStart()​

onObjectSelectStart(_event): void

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

Called when a source starts selecting the object this Script represents.

Parameters​

_event​

SelectEvent

event.target is the logical object and event.source.controller identifies the controller. Call event.stopPropagation() to stop bubbling to ancestor Scripts. Call event.stopGlobalPropagation() to suppress global selection callbacks for the rest of this capture

Returns​

void

Inherited from​

Script.onObjectSelectStart


onObjectTouchEnd()​

onObjectTouchEnd(_event): void

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

Called when a hand's index finger stops touching this object. This ends the default selection lifecycle after the touch callback.

Parameters​

_event​

ObjectTouchEvent

Returns​

void

Inherited from​

Script.onObjectTouchEnd


onObjectTouching()​

onObjectTouching(_event): void

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

Called every frame that a hand's index finger is touching this object. The object remains selected during these frames unless touch selection was prevented when contact started.

Parameters​

_event​

ObjectTouchEvent

Returns​

void

Inherited from​

Script.onObjectTouching


onObjectTouchStart()​

onObjectTouchStart(_event): void

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

Called when a hand's index finger starts touching this object. Direct touch starts the object's selection lifecycle by default. Call event.preventDefault() to handle contact without selecting.

Parameters​

_event​

ObjectTouchStartEvent

Returns​

void

Inherited from​

Script.onObjectTouchStart


onSelect()​

onSelect(_event): void

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

Called whenever pinch / mouse click successfully completes, globally.

Parameters​

_event​

SelectEvent

The interaction source and completed target.

Returns​

void

Inherited from​

Script.onSelect


onSelectEnd()​

onSelectEnd(_event): void

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

Called whenever pinch / mouse click discontinues, globally.

Parameters​

_event​

SelectEndEvent

The completed state and end reason.

Returns​

void

Inherited from​

Script.onSelectEnd


onSelecting()​

onSelecting(_event): void

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

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:133

Called whenever pinch / mouse click starts, globally.

Parameters​

_event​

SelectEvent

The interaction source and optional captured target.

Returns​

void

Inherited from​

Script.onSelectStart


onSimulatorStarted()​

onSimulatorStarted(): void

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

Returns​

void

Inherited from​

Script.onSimulatorStarted


onSqueeze()​

onSqueeze(_event): void

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

Called whenever gamepad trigger successfully completes, globally.

Parameters​

_event​

SelectEvent

event.source.controller identifies the controller.

Returns​

void

Inherited from​

Script.onSqueeze


onSqueezeEnd()​

onSqueezeEnd(_event): void

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

Called whenever gamepad trigger stops, globally.

Parameters​

_event​

SelectEvent

event.source.controller identifies the controller.

Returns​

void

Inherited from​

Script.onSqueezeEnd


onSqueezeStart()​

onSqueezeStart(_event): void

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

Called whenever gamepad trigger starts, globally.

Parameters​

_event​

SelectEvent

event.source.controller identifies the controller.

Returns​

void

Inherited from​

Script.onSqueezeStart


onSqueezing()​

onSqueezing(_event): void

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

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:123

Returns​

void

Inherited from​

Script.onXRSessionEnded


onXRSessionStarted()​

onXRSessionStarted(_session?): void

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

Parameters​

_session?​

XRSession

Returns​

void

Inherited from​

Script.onXRSessionStarted


physicsStep()​

physicsStep(): void

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

Returns​

void

Inherited from​

Script.physicsStep


update()​

update(): void

Defined in: src/input/GamepadController.ts:87

Runs per frame.

Returns​

void

Overrides​

Script.update


updatePose()​

updatePose(): void

Defined in: src/input/GamepadController.ts:79

Returns​

void

Implementation of​

Controller.updatePose


applyDeadzone()​

static applyDeadzone(value): number

Defined in: src/input/GamepadController.ts:170

Parameters​

value​

number

Returns​

number