Class: MouseController
Defined in: src/input/MouseController.ts:22
Simulates an XR controller using the mouse for desktop environments. This class translates 2D mouse movements on the screen into a 3D ray in the scene, allowing for point-and-click interactions in a non-immersive context. It functions as a virtual controller that is always aligned with the user's pointer.
Extends
Script<MouseControllerEventMap>
Implements
Controller
Constructors
Constructor
new MouseController():
MouseController
Defined in: src/input/MouseController.ts:50
Returns
MouseController
Overrides
Properties
camera?
optionalcamera:Camera
Defined in: src/input/MouseController.ts:46
A reference to the main scene camera.
editorIcon
editorIcon:
string='mouse'
Defined in: src/input/MouseController.ts:31
forwardVector
forwardVector:
Vector3
Defined in: src/input/MouseController.ts:43
A normalized vector representing the default forward direction.
isXRScript
isXRScript:
boolean=true
Defined in: src/core/Script.ts:99
Inherited from
name
name:
string='Mouse Controller'
Defined in: src/input/MouseController.ts:30
Optional name of the object
Remarks
(doesn't need to be unique).
Default Value
""
Implementation of
Controller.name
Overrides
Script.name
raycaster
raycaster:
Raycaster
Defined in: src/input/MouseController.ts:40
A THREE.Raycaster used to determine the 3D direction of the mouse.
type
type:
string='MouseController'
Defined in: src/input/MouseController.ts:29
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/MouseController.ts:37
User data for the controller, including its connection status, unique ID, and selection state (mouse button pressed).
connected
connected:
boolean=false
id
id:
number=3
selected
selected:
boolean=false
Implementation of
Controller.userData
Overrides
Script.userData
xb?
optionalxb:XBObjectOptions
Defined in: src/interaction/InteractionTypes.ts:32
Implementation of
Controller.xb
Inherited from
dependencies
staticdependencies:object
Defined in: src/input/MouseController.ts:26
camera
camera: typeof
Camera=THREE.Camera
Methods
callSelectEnd()
callSelectEnd():
void
Defined in: src/input/MouseController.ts:113
Dispatches a 'selectend' event, simulating the end of a controller press (e.g., mouse up).
Returns
void
callSelectStart()
callSelectStart():
void
Defined in: src/input/MouseController.ts:105
Dispatches a 'selectstart' event, simulating the start of a controller press (e.g., mouse down).
Returns
void
connect()
connect():
void
Defined in: src/input/MouseController.ts:121
"Connects" the virtual controller, notifying the input system that it is active.
Returns
void
disconnect()
disconnect():
void
Defined in: src/input/MouseController.ts:128
"Disconnects" the virtual controller.
Returns
void
dispose()
dispose():
void
Defined in: src/core/Script.ts:263
Called when the script is removed from the scene. Opposite of init.
Returns
void
Inherited from
init()
init(
__namedParameters):void
Defined in: src/input/MouseController.ts:57
Initialize the MouseController
Parameters
__namedParameters
camera
Returns
void
Overrides
initPhysics()
initPhysics(
_physics):void|Promise<void>
Defined in: src/core/Script.ts:118
Enables depth-aware interactions with physics. See /samples/advanced/ballpit
Parameters
_physics
Returns
void | Promise<void>
Inherited from
onHoverEnter()
onHoverEnter(
_event):void
Defined in: src/core/Script.ts:215
Called when a source starts hovering over this object.
Parameters
_event
The hover source, target, surface, and intersection.
Call event.stopPropagation() to stop bubbling to ancestor Scripts.
Returns
void
Inherited from
onHoverExit()
onHoverExit(
_event):void
Defined in: src/core/Script.ts:221
Called when a source stops hovering over this object.
Parameters
_event
The hover source, target, surface, and intersection.
Call event.stopPropagation() to stop bubbling to ancestor Scripts.
Returns
void
Inherited from
onHovering()
onHovering(
_event):void
Defined in: src/core/Script.ts:227
Called while a source hovers over this object.
Parameters
_event
The hover source, target, surface, and intersection.
Call event.stopPropagation() to stop bubbling to ancestor Scripts.
Returns
void
Inherited from
onKeyDown()
onKeyDown(
_event):void
Defined in: src/core/Script.ts:158
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:159
Parameters
_event
Returns
void
Inherited from
onLongSelect()
onLongSelect(
_event):void
Defined in: src/core/Script.ts:152
Called when an object selection reaches the long-select delay.
Parameters
_event
Returns
void
Inherited from
onObjectGrabbing()
onObjectGrabbing(
_event):void
Defined in: src/core/Script.ts:253
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:258
Called when a hand stops grabbing this object. This ends built-in direct-touch manipulation without ending contact.
Parameters
_event
Returns
void
Inherited from
onObjectGrabStart()
onObjectGrabStart(
_event):void
Defined in: src/core/Script.ts:249
Called when a hand starts grabbing this object (touching + pinching). A grab starts built-in direct-touch manipulation when enabled.
Parameters
_event
Returns
void
Inherited from
onObjectLongSelect()
onObjectLongSelect(
_event):void
Defined in: src/core/Script.ts:203
Called once when a captured selection is held for the long-select delay. Manipulation captures do not emit this callback.
Parameters
_event
The controller and completed hold duration.
Call event.stopPropagation() to stop bubbling to ancestor Scripts.
Returns
void
Inherited from
onObjectManipulate()
onObjectManipulate(
_event):void
Defined in: src/core/Script.ts:209
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
Returns
void
Inherited from
onObjectSelectEnd()
onObjectSelectEnd(
_event):void
Defined in: src/core/Script.ts:196
Called when a source stops selecting the object this Script represents.
Parameters
_event
The completed state and end reason.
Call event.stopPropagation() to stop bubbling to ancestor Scripts.
Returns
void
Inherited from
onObjectSelectStart()
onObjectSelectStart(
_event):void
Defined in: src/core/Script.ts:190
Called when a source starts selecting the object this Script represents.
Parameters
_event
event.target is the logical object and
event.source.controller identifies the controller.
Call event.stopPropagation() to stop bubbling to ancestor Scripts.
Returns
void
Inherited from
onObjectTouchEnd()
onObjectTouchEnd(
_event):void
Defined in: src/core/Script.ts:244
Called when a hand's index finger stops touching this object. This ends the default selection lifecycle after the touch callback.
Parameters
_event
Returns
void
Inherited from
onObjectTouching()
onObjectTouching(
_event):void
Defined in: src/core/Script.ts:239
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
Returns
void
Inherited from
onObjectTouchStart()
onObjectTouchStart(
_event):void
Defined in: src/core/Script.ts:233
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
Returns
void
Inherited from
onSelect()
onSelect(
_event):void
Defined in: src/core/Script.ts:144
Called whenever pinch / mouse click successfully completes, globally.
Parameters
_event
The interaction source and completed target.
Returns
void
Inherited from
onSelectEnd()
onSelectEnd(
_event):void
Defined in: src/core/Script.ts:138
Called whenever pinch / mouse click discontinues, globally.
Parameters
_event
The completed state and end reason.
Returns
void
Inherited from
onSelecting()
onSelecting(
_event):void
Defined in: src/core/Script.ts:149
Called whenever pinch / mouse click is happening, globally.
Parameters
_event
Returns
void
Inherited from
onSelectStart()
onSelectStart(
_event):void
Defined in: src/core/Script.ts:132
Called whenever pinch / mouse click starts, globally.
Parameters
_event
The interaction source and optional captured target.
Returns
void
Inherited from
onSimulatorStarted()
onSimulatorStarted():
void
Defined in: src/core/Script.ts:124
Returns
void
Inherited from
onSqueeze()
onSqueeze(
_event):void
Defined in: src/core/Script.ts:181
Called whenever gamepad trigger successfully completes, globally.
Parameters
_event
event.source.controller identifies the controller.
Returns
void
Inherited from
onSqueezeEnd()
onSqueezeEnd(
_event):void
Defined in: src/core/Script.ts:170
Called whenever gamepad trigger stops, globally.
Parameters
_event
event.source.controller identifies the controller.
Returns
void
Inherited from
onSqueezeStart()
onSqueezeStart(
_event):void
Defined in: src/core/Script.ts:165
Called whenever gamepad trigger starts, globally.
Parameters
_event
event.source.controller identifies the controller.
Returns
void
Inherited from
onSqueezing()
onSqueezing(
_event):void
Defined in: src/core/Script.ts:175
Called whenever gamepad is being triggered, globally.
Parameters
_event
Returns
void
Inherited from
onXRSessionEnded()
onXRSessionEnded():
void
Defined in: src/core/Script.ts:122
Returns
void
Inherited from
onXRSessionStarted()
onXRSessionStarted(
_session?):void
Defined in: src/core/Script.ts:121
Parameters
_session?
Returns
void
Inherited from
physicsStep()
physicsStep():
void
Defined in: src/core/Script.ts:119
Returns
void
Inherited from
update()
update():
void
Defined in: src/input/MouseController.ts:78
The main update loop, called every frame. If connected, it syncs the controller's origin point with the camera's position.
Returns
void
Overrides
updateMousePositionFromEvent()
updateMousePositionFromEvent(
event):void
Defined in: src/input/MouseController.ts:92
Updates the controller's transform based on the mouse's position on the screen. This method sets both the position and rotation, ensuring the object has a valid world matrix for raycasting.
Parameters
event
The mouse event containing clientX and clientY coordinates.
Returns
void
updatePose()
updatePose():
void
Defined in: src/input/MouseController.ts:62
Updates the mouse position/rotation using camera state.
Returns
void
Implementation of
Controller.updatePose