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
Controller
Constructors
Constructor
new GamepadController():
GamepadController
Defined in: src/input/GamepadController.ts:55
Returns
GamepadController
Overrides
Properties
activeGamepad?
optionalactiveGamepad:null|Gamepad
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?
optionalcamera:Camera
Defined in: src/input/GamepadController.ts:35
gamepad?
optionalgamepad: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:54
Inherited from
menuActive
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()?
optionalonOpenSettings: () =>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
ux
ux:
UX
Defined in: src/core/Script.ts:53
Inherited from
dependencies
staticdependencies: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:138
Returns
void
callSelectStart()
callSelectStart():
void
Defined in: src/input/GamepadController.ts:134
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:142
Returns
void
disconnect()
disconnect():
void
Defined in: src/input/GamepadController.ts:146
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
getAxes()
getAxes(): [
number,number,number,number]
Defined in: src/input/GamepadController.ts:154
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:176
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:185
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, 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
Returns
void
Overrides
initPhysics()
initPhysics(
_physics):void|Promise<void>
Defined in: src/core/Script.ts:73
Enables depth-aware interactions with physics. See /demos/ballpit
Parameters
_physics
Returns
void | Promise<void>
Inherited from
isButtonJustPressed()
isButtonJustPressed(
buttonIndex):boolean
Defined in: src/input/GamepadController.ts:195
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(
_controller):boolean|void
Defined in: src/core/Script.ts:155
Called when the controller starts hovering over this object with reticle.
Parameters
_controller
An XR controller.
Returns
boolean | void
Whether the event was handled. If true, the event will not bubble up.
Inherited from
onHoverExit()
onHoverExit(
_controller):boolean|void
Defined in: src/core/Script.ts:161
Called when the controller hovers over this object with reticle.
Parameters
_controller
An XR controller.
Returns
boolean | void
Whether the event was handled. If true, the event will not bubble up.
Inherited from
onHovering()
onHovering(
_controller):boolean|void
Defined in: src/core/Script.ts:167
Called when the controller hovers over this object with reticle.
Parameters
_controller
An XR controller.
Returns
boolean | void
Whether the event was handled. If true, the event will not bubble up.
Inherited from
onKeyDown()
onKeyDown(
_event):void
Defined in: src/core/Script.ts:110
Called on keyboard keypress.
Parameters
_event
Event containing .code to read the keyboard key.
Returns
void
Inherited from
onKeyUp()
onKeyUp(
_event):void
Defined in: src/core/Script.ts:111
Parameters
_event
Returns
void
Inherited from
onObjectGrabbing()
onObjectGrabbing(
_event):void
Defined in: src/core/Script.ts:187
Called every frame a hand is grabbing this object.
Parameters
_event
Returns
void
Inherited from
onObjectGrabEnd()
onObjectGrabEnd(
_event):void
Defined in: src/core/Script.ts:191
Called when a hand stops grabbing this object.
Parameters
_event
Returns
void
Inherited from
onObjectGrabStart()
onObjectGrabStart(
_event):void
Defined in: src/core/Script.ts:183
Called when a hand starts grabbing this object (touching + pinching).
Parameters
_event
Returns
void
Inherited from
onObjectSelectEnd()
onObjectSelectEnd(
_event):boolean|void
Defined in: src/core/Script.ts:149
Called when the controller stops selecting this object the script represents, e.g. View, ModelView.
Parameters
_event
event.target holds its controller.
Returns
boolean | void
Whether the event was handled. If true, the event will not bubble up.
Inherited from
onObjectSelectStart()
onObjectSelectStart(
_event):boolean|void
Defined in: src/core/Script.ts:142
Called when the controller starts selecting this object the script represents, e.g. View, ModelView.
Parameters
_event
event.target holds its controller.
Returns
boolean | void
Whether the event was handled. If true, the event will not bubble up.
Inherited from
onObjectTouchEnd()
onObjectTouchEnd(
_event):void
Defined in: src/core/Script.ts:179
Called when a hand's index finger stops touching this object.
Parameters
_event
Returns
void
Inherited from
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
Returns
void
Inherited from
onObjectTouchStart()
onObjectTouchStart(
_event):void
Defined in: src/core/Script.ts:171
Called when a hand's index finger starts touching this object.
Parameters
_event
Returns
void
Inherited from
onSelect()
onSelect(
_event):void
Defined in: src/core/Script.ts:99
Called whenever pinch / mouse click successfully completes, globally.
Parameters
_event
event.target holds its controller.
Returns
void
Inherited from
onSelectEnd()
onSelectEnd(
_event):void
Defined in: src/core/Script.ts:93
Called whenever pinch / mouse click discontinues, globally.
Parameters
_event
event.target holds its controller
Returns
void
Inherited from
onSelecting()
onSelecting(
_event):void
Defined in: src/core/Script.ts:104
Called whenever pinch / mouse click is happening, globally.
Parameters
_event
Returns
void
Inherited from
onSelectStart()
onSelectStart(
_event):void
Defined in: src/core/Script.ts:87
Called whenever pinch / mouse click starts, globally.
Parameters
_event
event.target holds its controller
Returns
void
Inherited from
onSimulatorStarted()
onSimulatorStarted():
void
Defined in: src/core/Script.ts:79
Returns
void
Inherited from
onSqueeze()
onSqueeze(
_event):void
Defined in: src/core/Script.ts:133
Called whenever gamepad trigger successfully completes, globally.
Parameters
_event
event.target holds its controller.
Returns
void
Inherited from
onSqueezeEnd()
onSqueezeEnd(
_event):void
Defined in: src/core/Script.ts:122
Called whenever gamepad trigger stops, globally.
Parameters
_event
event.target holds its controller.
Returns
void
Inherited from
onSqueezeStart()
onSqueezeStart(
_event):void
Defined in: src/core/Script.ts:117
Called whenever gamepad trigger starts, globally.
Parameters
_event
event.target holds its controller.
Returns
void
Inherited from
onSqueezing()
onSqueezing(
_event):void
Defined in: src/core/Script.ts:127
Called whenever gamepad is being triggered, globally.
Parameters
_event
Returns
void
Inherited from
onXRSessionEnded()
onXRSessionEnded():
void
Defined in: src/core/Script.ts:77
Returns
void
Inherited from
onXRSessionStarted()
onXRSessionStarted(
_session?):void
Defined in: src/core/Script.ts:76
Parameters
_session?
Returns
void
Inherited from
physicsStep()
physicsStep():
void
Defined in: src/core/Script.ts:74
Returns
void
Inherited from
update()
update():
void
Defined in: src/input/GamepadController.ts:79
Runs per frame.
Returns
void
Overrides
applyDeadzone()
staticapplyDeadzone(value):number
Defined in: src/input/GamepadController.ts:165
Parameters
value
number
Returns
number