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:45
Returns
MouseController
Overrides
Properties
camera
camera:
Camera
Defined in: src/input/MouseController.ts:43
A reference to the main scene camera.
forwardVector
forwardVector:
Vector3
Defined in: src/input/MouseController.ts:40
A normalized vector representing the default forward direction.
isXRScript
isXRScript:
boolean=true
Defined in: src/core/Script.ts:54
Inherited from
raycaster
raycaster:
Raycaster
Defined in: src/input/MouseController.ts:37
A THREE.Raycaster used to determine the 3D direction of the mouse.
userData
userData:
object
Defined in: src/input/MouseController.ts:34
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
ux
ux:
UX
Defined in: src/core/Script.ts:53
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:104
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:96
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:112
"Connects" the virtual controller, notifying the input system that it is active.
Returns
void
disconnect()
disconnect():
void
Defined in: src/input/MouseController.ts:119
"Disconnects" the virtual controller.
Returns
void
dispose()
dispose():
void
Defined in: src/core/Script.ts:197
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:52
Initialize the MouseController
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
onHoverEnter()
onHoverEnter(
_controller):void
Defined in: src/core/Script.ts:158
Called when the controller starts hovering over this object with reticle.
Parameters
_controller
An XR controller.
Returns
void
Inherited from
onHoverExit()
onHoverExit(
_controller):void
Defined in: src/core/Script.ts:163
Called when the controller hovers over this object with reticle.
Parameters
_controller
An XR controller.
Returns
void
Inherited from
onHovering()
onHovering(
_controller):void
Defined in: src/core/Script.ts:168
Called when the controller hovers over this object with reticle.
Parameters
_controller
An XR controller.
Returns
void
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:188
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:192
Called when a hand stops grabbing this object.
Parameters
_event
Returns
void
Inherited from
onObjectGrabStart()
onObjectGrabStart(
_event):void
Defined in: src/core/Script.ts:184
Called when a hand starts grabbing this object (touching + pinching).
Parameters
_event
Returns
void
Inherited from
onObjectSelectEnd()
onObjectSelectEnd(
_event):boolean
Defined in: src/core/Script.ts:151
Called when the controller stops selecting this object the script represents, e.g. View, ModelView.
Parameters
_event
event.target holds its controller.
Returns
boolean
Whether the event was handled
Inherited from
onObjectSelectStart()
onObjectSelectStart(
_event):boolean
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
Whether the event was handled
Inherited from
onObjectTouchEnd()
onObjectTouchEnd(
_event):void
Defined in: src/core/Script.ts:180
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:176
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:172
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/MouseController.ts:61
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:75
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