Three.js Shared Anchors (Multi-Device AR Alignment)
The idea behind shared or cloud anchors for multi-user AR in Three.js, where two devices track the same room in different local frames, a jointly observed anchor yields T_B←A = anchor_B · anchor_A⁻¹, and content placed by one appears correctly for the other despite drift and noise.
Key topics: shared anchors, cloud anchors, multiplayer ar, coordinate alignment, webxr anchors, colocation
Game Over
What this code does
- Local Frames: each session's origin is wherever tracking started, so the same object has different coordinates on each device.
- Shared Anchor: both devices localise one physical anchor (a cloud anchor or marker), each measuring its pose in its own frame.
- Alignment: T_B←A = anchor_inB · anchor_inA⁻¹ maps any pose from A's frame into B's, re-solved every frame so tracking drift is absorbed.
- Visual Check: solid cubes are where A placed objects, wireframes are where B renders them, and red lines show any mismatch; switch alignment off to see the failure.
- Robustness: anchor noise and per-device drift are adjustable; storing content relative to the anchor avoids needing A's frame at all.
- Controls: align with the shared anchor, anchor noise, tracking drift, auto placement and clear.
Related Demos
Continue Learning
JavaScript Implementation
// Multi-device alignment with a shared (cloud) anchor
// Each device resolves the same physical anchor in its own local tracking frame:
const anchorInA = poseOf(anchorSpace, refSpaceA) // 4×4
const anchorInB = poseOf(anchorSpace, refSpaceB)
const BfromA = anchorInB.clone().multiply(anchorInA.clone().invert())
// Content placed by A (pose in A's frame) is shown by B at:
objectOnB.matrix.copy(BfromA).multiply(objectPoseInA)
// Better: store content *relative to the anchor* (anchorInA⁻¹ · pose) so it never needs A's frame at all