Skip to main content

Class: AnchoredObjects

Defined in: src/world/anchors/AnchoredObjects.ts:62

Keeps THREE.Object3Ds attached to spatial anchors.

AnchorManager deals in anchors and poses; every app on top of it otherwise repeats the same work of holding a map from anchor to object and copying poses across each frame. This owns that, so an app anchors an object and then forgets about it.

Constructors

Constructor

new AnchoredObjects(manager, parent): AnchoredObjects

Defined in: src/world/anchors/AnchoredObjects.ts:69

Parameters

manager

AnchorManager

The anchor subsystem to attach through.

parent

Object3D

Object to add anchored content to, usually the scene.

Returns

AnchoredObjects

Methods

anchor()

anchor(object, label): Promise<TrackedAnchor | null>

Defined in: src/world/anchors/AnchoredObjects.ts:81

Anchors an object where it currently sits, and saves it.

Parameters

object

Object3D

Object to pin. Added to the parent if not already in it.

label

string

Label to restore it by later.

Returns

Promise<TrackedAnchor | null>

The tracked anchor, or null when anchoring is unavailable.


clear()

clear(): void

Defined in: src/world/anchors/AnchoredObjects.ts:180

Detaches everything and forgets every saved anchor.

Returns

void


get()

get(id): Object3D<Object3DEventMap> | undefined

Defined in: src/world/anchors/AnchoredObjects.ts:167

The object attached to an anchor.

Parameters

id

string

Id of the anchor.

Returns

Object3D<Object3DEventMap> | undefined

The object, or undefined.


getAll()

getAll(): ReadonlyMap<string, Object3D<Object3DEventMap>>

Defined in: src/world/anchors/AnchoredObjects.ts:175

Every attached object, keyed by anchor id.

Returns

ReadonlyMap<string, Object3D<Object3DEventMap>>

The attached objects.


remove()

remove(id): void

Defined in: src/world/anchors/AnchoredObjects.ts:153

Detaches an anchored object and forgets its anchor.

Parameters

id

string

Id of the anchor to remove.

Returns

void


restore()

restore(factory): Promise<number>

Defined in: src/world/anchors/AnchoredObjects.ts:108

Rebuilds objects for every anchor saved in a previous session.

Parameters

factory

AnchoredObjectFactory

Builds the object for a restored anchor.

Returns

Promise<number>

How many objects were restored.


update()

update(referenceSpace?): void

Defined in: src/world/anchors/AnchoredObjects.ts:134

Moves every attached object onto its anchor's current pose.

Call once per frame. Anchors drift as the platform refines its map of the room, which is the whole point of anchoring rather than storing a position.

Parameters

referenceSpace?

XRReferenceSpace

Space to read poses in. Not needed for simulated anchors, which hold their own pose.

Returns

void