-
Notifications
You must be signed in to change notification settings - Fork 113
SpatialAnchorStore
The spatial anchor store is used to persist spatial anchors between app sessions. This allows persisting object placements in a scene between invocations of the app.
- isAvailable()
Static method. Check if the spatial anchor store is supported on the current platform
- SpatialAnchorStore()
Constructor. Throws an exception of the anchor store cannot be created.
- initialize()
Asynchronous initialization method. Must be called before requesting any operations in the store (enumerate, save, etc.) When initialization is complete, the "initialized" event is raised. See the Events section for more details.
- enumerate()
Enumerates all persisted anchors in the store. Returns an array of SpatialAnchor objects.
- open(anchorName : string)
Opens the anchor by the specified name. If an anchor with the requested name does not exist, returns null.
- save(anchor : SpatialAnchor, anchorName : string)
Saves an anchor using the specified anchor name. If an anchor by this name already exists, it will be overwritten.
- delete(anchorOrAnchorName : SpatialAnchor or string)
Deletes the specified anchor. The argument can be the name of an anchor or a SpatialAnchor object.
- initialized
let anchorStore = new SpatialAnchorStore();
anchorStore.oninitialized = function () { };
// or
anchorStore.addEventListener('initialized', function(){});
Invoked when initialization completes.
- error
Invoked if initialization fails.
var anchorStore;
if (SpatialAnchorStore.isAvailable()) {
// Create the anchor store object
anchorStore = new SpatialAnchorStore();
// Once initialized ...
anchorStore.oninitialized = function () {
// Enumerate all anchors
let allAnchors = anchorStore.enumerate();
for(let i = 0; i < allAnchors.length; i++) {
console.log(allAnchors[i].name);
}
// Open an anchor
let myAnchor = anchorStore.open("myAnchor");
if (myAnchor !== null) {
// Delete the anchor from the store. The anchor can still be located and used to position objects
anchorStore.delete(myAnchor);
// Create a new anchor relative to the anchor we just deleted from the store
let otherAnchor = new SpatialAnchor({relativeTo : myAnchor, position : { x : 1, y : 0, z : 0}});
// Save the new anchor
anchorStore.save(otherAnchor, "mySecondAnchor");
}
}
anchorStore.initialize();
}