Skip to main content

Class: User

Defined in: src/core/User.ts:18

User is an embodied instance to manage hands, controllers, speech, and avatars. It extends Script to update human-world interaction.

In the long run, User is to manages avatars, hands, and everything of Human I/O. In third-person view simulation, it should come with an low-poly avatar. To support multi-user social XR planned for future iterations.

Extends

Constructors

Constructor

new User(): User

Defined in: node_modules/@types/three/src/core/Object3D.d.ts:98

This creates a new Object3D object.

Returns

User

Inherited from

Script.constructor

Properties

controllers

controllers: Controller[]

Defined in: src/core/User.ts:78


handedness

handedness: number = 1

Defined in: src/core/User.ts:48

The handedness (primary hand) of the user (0 for left, 1 for right, 2 for both).


hands?

optional hands: Hands

Defined in: src/core/User.ts:74

Public data for user interactions, typically holding references to XRHand.


height

height: number = 1.6

Defined in: src/core/User.ts:37

The height of the user in meters.


input

input: Input

Defined in: src/core/User.ts:76


isXRScript

isXRScript: boolean = true

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

Inherited from

Script.isXRScript


local

local: boolean = true

Defined in: src/core/User.ts:27

Whether to represent a local user, or another user in a multi-user session.


numHands

numHands: number = 2

Defined in: src/core/User.ts:32

The number of hands associated with the XR user.


objectAngle

objectAngle: number

Defined in: src/core/User.ts:63

The angle of a newly spawned object from the user in radians.


objectDistance

objectDistance: number = 1.5

Defined in: src/core/User.ts:58

The distance of a newly spawned object from the user in meters.


panelDistance

panelDistance: number = 1.75

Defined in: src/core/User.ts:42

The default distance of a UI panel from the user in meters.


pivots

pivots: Object3D<Object3DEventMap>[] = []

Defined in: src/core/User.ts:69

An array of pivot objects. Pivot are sphere at the starting tip of user's hand / controller / mouse rays for debugging / drawing applications.


safeSpaceRadius

safeSpaceRadius: number = 0.2

Defined in: src/core/User.ts:53

The radius of the safe space around the user in meters.


xb?

optional xb: XBObjectOptions

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

Inherited from

Script.xb

Methods

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

Script.dispose


enablePivots()

enablePivots(): void

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

Adds pivots at the starting tip of user's hand / controller / mouse rays.

Returns

void


getControllerObjectDistance()

getControllerObjectDistance(id, object): number

Defined in: src/core/User.ts:190

Calculates the distance between a controller and an object.

Parameters

id

number

The controller id.

object

Object3D

The object to measure the distance to.

Returns

number

The distance between the controller and the object.


getControllerPosition()

getControllerPosition(id, target): Vector3

Defined in: src/core/User.ts:179

Gets the world position of a controller.

Parameters

id

number

The controller id.

target

Vector3 = ...

The target vector to store the result.

Returns

Vector3

The world position of the controller.


getIntersectionAt()

getIntersectionAt(obj, id): Intersection<Object3D<Object3DEventMap>> | null

Defined in: src/core/User.ts:165

Gets the intersection point on a specific object.

Parameters

obj

Object3D

The object to check for intersection.

id

number = -1

The controller ID, or -1 for any controller.

Returns

Intersection<Object3D<Object3DEventMap>> | null

The intersection details, or null if no intersection.


getPivot()

getPivot(id): Object3D<Object3DEventMap> | undefined

Defined in: src/core/User.ts:109

Gets the pivot object for a given controller id.

Parameters

id

number

The controller id.

Returns

Object3D<Object3DEventMap> | undefined

The pivot object.


getPivotPosition()

getPivotPosition(id): Vector3 | undefined

Defined in: src/core/User.ts:118

Gets the world position of the pivot for a given controller id.

Parameters

id

number

The controller id.

Returns

Vector3 | undefined

The world position of the pivot.


getRay()

getRay(controllerId, target): Ray

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

Parameters

controllerId

number

target

Ray = ...

Returns

Ray


getRayIntersection()

getRayIntersection(controllerId): Intersection<Object3D<Object3DEventMap>> | null

Defined in: src/core/User.ts:129

Parameters

controllerId

number

Returns

Intersection<Object3D<Object3DEventMap>> | null


init()

init(__namedParameters): void

Defined in: src/core/User.ts:83

Initializes the User.

Parameters

__namedParameters
input

Input

interaction

Interaction

Returns

void

Overrides

Script.init


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

Physics

Returns

void | Promise<void>

Inherited from

Script.initPhysics


isManipulating()

isManipulating(obj): boolean

Defined in: src/core/User.ts:155

Parameters

obj

Object3D

Returns

boolean


isPointingAt()

isPointingAt(obj): boolean

Defined in: src/core/User.ts:142

Checks if any controller is pointing at the given object or its children.

Parameters

obj

Object3D

The object to check against.

Returns

boolean

True if a controller is pointing at the object.


isSelecting()

isSelecting(id): any

Defined in: src/core/User.ts:202

Checks if either controller is selecting.

Parameters

id

number = -1

The controller id. If -1, check both controllers.

Returns

any

True if selecting, false otherwise.


isSelectingAt()

isSelectingAt(obj): boolean

Defined in: src/core/User.ts:151

Checks if any controller is selecting the given object or its children.

Parameters

obj

Object3D

The object to check against.

Returns

boolean

True if a controller is selecting the object.


isSqueezing()

isSqueezing(id): any

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

Checks if either controller is squeezing.

Parameters

id

number = -1

The controller id. If -1, check both controllers.

Returns

any

True if squeezing, false otherwise.


onHoverEnter()

onHoverEnter(_event): void

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

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

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

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

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

Parameters

_event

KeyEvent

Returns

void

Inherited from

Script.onKeyUp


onLongSelect()

onLongSelect(_event): void

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

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

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

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

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

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.

Returns

void

Inherited from

Script.onObjectLongSelect


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

ManipulationEvent

Returns

void

Inherited from

Script.onObjectManipulate


onObjectSelectEnd()

onObjectSelectEnd(_event): void

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

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.

Returns

void

Inherited from

Script.onObjectSelectEnd


onObjectSelectStart()

onObjectSelectStart(_event): void

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

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.

Returns

void

Inherited from

Script.onObjectSelectStart


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

ObjectTouchEvent

Returns

void

Inherited from

Script.onObjectTouchEnd


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

ObjectTouchEvent

Returns

void

Inherited from

Script.onObjectTouching


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

ObjectTouchStartEvent

Returns

void

Inherited from

Script.onObjectTouchStart


onSelect()

onSelect(_event): void

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

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

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

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

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

Returns

void

Inherited from

Script.onSimulatorStarted


onSqueeze()

onSqueeze(_event): void

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

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

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

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

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

Returns

void

Inherited from

Script.onXRSessionEnded


onXRSessionStarted()

onXRSessionStarted(_session?): void

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

Parameters

_session?

XRSession

Returns

void

Inherited from

Script.onXRSessionStarted


physicsStep()

physicsStep(): void

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

Returns

void

Inherited from

Script.physicsStep


setHeight()

setHeight(camera): void

Defined in: src/core/User.ts:93

Sets the user's height on the first frame.

Parameters

camera

Camera

Returns

void


update()

update(_time?, _frame?): void

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

Runs per frame.

Parameters

_time?

number

_frame?

XRFrame

Returns

void

Inherited from

Script.update