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:43
Returns
MouseController
Overrides
Properties
camera
camera:
Camera
Defined in: src/input/MouseController.ts:41
A reference to the main scene camera.
forwardVector
forwardVector:
Vector3
Defined in: src/input/MouseController.ts:38
A normalized vector representing the default forward direction.
isXRScript
isXRScript:
boolean
=true
Defined in: src/core/Script.ts:53
Inherited from
raycaster
raycaster:
Raycaster
Defined in: src/input/MouseController.ts:35
A THREE.Raycaster used to determine the 3D direction of the mouse.
userData
userData:
object
Defined in: src/input/MouseController.ts:32
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:52
Inherited from
dependencies
static
dependencies:object
Defined in: src/input/MouseController.ts:24
camera
camera: typeof
Camera
=THREE.Camera
Methods
callSelectEnd()
callSelectEnd():
void
Defined in: src/input/MouseController.ts:102
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:94
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:110
"Connects" the virtual controller, notifying the input system that it is active.
Returns
void
disconnect()
disconnect():
void
Defined in: src/input/MouseController.ts:117
"Disconnects" the virtual controller.
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
init()
init(
__namedParameters
):void
Defined in: src/input/MouseController.ts:50
Initialize the MouseController
Parameters
__namedParameters
camera
Returns
void
Overrides
initPhysics()
initPhysics(
_physics
):void
|Promise
<void
>
Defined in: src/core/Script.ts:72
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:157
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:162
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:167
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:109
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:110
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
Defined in: src/core/Script.ts:150
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:141
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: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:98
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:92
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:103
Called whenever pinch / mouse click is happening, globally.
Parameters
_event
Returns
void
Inherited from
onSelectStart()
onSelectStart(
_event
):void
Defined in: src/core/Script.ts:86
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:78
Returns
void
Inherited from
onSqueeze()
onSqueeze(
_event
):void
Defined in: src/core/Script.ts:132
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:121
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:116
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:126
Called whenever gamepad is being triggered, globally.
Parameters
_event
Returns
void
Inherited from
onXRSessionEnded()
onXRSessionEnded():
void
Defined in: src/core/Script.ts:76
Returns
void
Inherited from
onXRSessionStarted()
onXRSessionStarted(
_session?
):void
Defined in: src/core/Script.ts:75
Parameters
_session?
Returns
void
Inherited from
physicsStep()
physicsStep():
void
Defined in: src/core/Script.ts:73
Returns
void
Inherited from
update()
update():
void
Defined in: src/input/MouseController.ts:59
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:73
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