-
Notifications
You must be signed in to change notification settings - Fork 113
SpatialAnchor
A spatial anchor represents a point in the world. Anchors can be created relative to the current world origin or relative to other anchors. For more information, please read this article
Spatial anchors can labeled and persisted across sessions using the SpatialAnchorStore.
- SpatialAnchor(options : optional)
Constructor for a new spatial anchor. You can set a relative position, orientation or a base anchor:
position : { x : <x_offset>, y : <y_offset>, z : <z_offset>}
The relative position of the new anchor along the axes. The position is relative to another anchor, if specified in options, and relative to the world origin otherwise.
orientation : { x : <x_quat>, y : <y_quat>, z : <z_quat>, z : <w_quat>}
The relative orientation of the new anchor.
relativeTo : <other_anchor>
Create a new anchor at position and orientation relative to this anchor. If this field is not set, the new anchor is created relative to the world origin.
- tryGetTransformTo(other : optional)
Tries to obtain the position and orientation of an anchor relative to another. Returns "undefined" if their relative positions cannot be determined. If "other" is not set, the relative position and orientation to the world origin is returned.
Returns an object with the relative position and orientation (quaternion)
{
position : {x : <x_value>, y : <y_value>, z : <z_value>},
orientation : {x : <x_quat>, y : <y_quat>, z : <z_quat>, w : <w_quat>}
}
- areAvailable()
Static method. Use to check if the current platform support spatial anchors. Spatial anchors are implemented for Windows Mixed Reality and HoloLens and are not available for Windows desktop.
- name
The name of the anchor. Only defined if the anchor was persisted in the anchor store.
if (SpatialAnchor.areAvailable()) {
// Create new anchor, 1 meters up relative to the world origin
let newAnchor = new SpatialAnchor({ position: { x: 0, y: 1, z: 0 } });
// Create a new anchor, 1 meter to the right of the anchor above
let relativeAnchor = new SpatialAnchor({ position: { x: 1, y: 0, z: 0 }, relativeTo : newAnchor });
// Get the relative position of the relative anchor to the origin; it is 1 meter up and to the right of the origin
let position = relativeAnchor.tryGetTransformTo();
// Use the returned position and orientation to place objects in the world ...
}