Skip to main content

Class: World

Defined in: src/world/World.ts:27

Manages all interactions with the real-world environment perceived by the XR device. This class abstracts the complexity of various perception APIs (Depth, Planes, Meshes, etc.) and provides a simple, event-driven interface for developers to use this.world.depth.mesh, this.world.planes.

Extends

Constructors

Constructor

new World(): World

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

This creates a new Object3D object.

Returns

World

Inherited from

Script.constructor

Properties

anchors?

optional anchors: AnchorManager

Defined in: src/world/World.ts:57


editorIcon

editorIcon: string = 'sensors'

Defined in: src/world/World.ts:35


faces?

optional faces: FaceRecognizer

Defined in: src/world/World.ts:82

The face landmark detection module instance. Null if not enabled.


humans?

optional humans: HumanRecognizer

Defined in: src/world/World.ts:77

The human recognition/pose module instance. Null if not enabled.


initializedPromise

readonly initializedPromise: Promise<void>

Defined in: src/world/World.ts:102


isXRScript

isXRScript: boolean = true

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

Inherited from

Script.isXRScript


meshes?

optional meshes: MeshDetector

Defined in: src/world/World.ts:67

The mesh detection module instance. Null if not enabled.


objects?

optional objects: ObjectDetector

Defined in: src/world/World.ts:62

The object recognition module instance. Null if not enabled.


options

options: WorldOptions

Defined in: src/world/World.ts:40

Configuration options for all world-sensing features.


planes?

optional planes: PlaneDetector

Defined in: src/world/World.ts:56

The plane detection module instance. Null if not enabled. Not recommended for anchoring.


segmentation?

optional segmentation: Segmenter

Defined in: src/world/World.ts:87

The semantic segmentation module instance. Null if not enabled.


sounds?

optional sounds: SoundDetector

Defined in: src/world/World.ts:72

The sound detection module instance. Null if not enabled.


xb?

optional xb: XBObjectOptions

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

Inherited from

Script.xb


dependencies

static dependencies: object

Defined in: src/world/World.ts:28

camera

camera: typeof Camera = THREE.Camera

options

options: typeof WorldOptions = WorldOptions

timer

timer: typeof Timer = THREE.Timer

waitFrame

waitFrame: typeof WaitFrame = WaitFrame

Methods

anchorObjectAtReticle()

anchorObjectAtReticle(_object, _reticle): void

Defined in: src/world/World.ts:187

Places an object at the reticle.

Parameters

_object

Object3D

_reticle

Object3D

Returns

void


dispose()

dispose(): void

Defined in: src/world/World.ts:301

Called when the script is removed from the scene. Opposite of init.

Returns

void

Overrides

Script.dispose


init()

init(__namedParameters): Promise<void>

Defined in: src/world/World.ts:110

Initializes the world-sensing modules based on the provided configuration. This method is called automatically by the XRCore.

Parameters

__namedParameters
camera

Camera

options

WorldOptions

timer

Timer

waitFrame

WaitFrame

Returns

Promise<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


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


placeOnHorizontalSurface()

placeOnHorizontalSurface(objectToPlace, timeout, gridSteps): Promise<boolean>

Defined in: src/world/World.ts:264

Places an object onto a suitable horizontal plane in the environment. It prioritizes planes in front of the user, prefers tables/elevated surfaces over floors, and ensures the object does not intersect other existing objects or other planes in the scene. If placement fails in the current frame, it continues retrying frame-by-frame until the timeout is reached.

Parameters

objectToPlace

Object3D

The Three.js Object3D to place.

timeout

DurationLike = ...

Optional timeout duration as a Temporal.Duration or Temporal.DurationLike object (defaults to 500ms).

gridSteps

number = 9

Optional number of steps along each axis for grid sampling candidate positions (defaults to 5).

Returns

Promise<boolean>

A promise resolving to true if successfully placed, false otherwise.


placeOnSurface()

placeOnSurface(objectToPlace, controller): boolean

Defined in: src/world/World.ts:225

Performs a raycast from a controller against detected real-world surfaces (currently planes) and places a 3D object at the intersection point, oriented to face the user.

See /templates/3_spatial_placement/ for a complete placement example.

Parameters

objectToPlace

Object3D

The object to position in the world.

controller

Object3D

The controller to use for raycasting.

Returns

boolean

True if the object was successfully placed, false otherwise.


showDebugVisualizations()

showDebugVisualizations(visible): void

Defined in: src/world/World.ts:296

Toggles the visibility of all debug visualizations for world features.

Parameters

visible

boolean = true

Whether the visualizations should be visible.

Returns

void


update()

update(_timestamp, frame?): void

Defined in: src/world/World.ts:199

Updates all active world-sensing modules with the latest XRFrame data. This method is called automatically by the XRCore on each frame.

Parameters

_timestamp

number

The timestamp for the current frame.

frame?

XRFrame

The current XRFrame, containing environmental data.

Returns

void

Overrides

Script.update