Develop
Develop
Select your platform

Sample Apps demonstrating Anchor APIs

Updated: May 29, 2024
An anchor sample for OpenXR, XrSpatialAnchor, is included in the Oculus Mobile OpenXR SDK. It demonstrates the capabilities of the Spatial Anchor system and provides example code for creating, saving, erasing, discovering/querying, and sharing Spatial Anchors that you can use in your own project. The project is in the XrSamples\XrSpatialAnchor folder.

XrSpatialAnchor App User Experience

The controls are:
  • Press A (on the right Meta Quest Touch controller) to place a persistent Spatial Anchor that mirrors the pose of the right controller when A was pressed. When you do that, the system will place a rectangular object at the origin of the spatial anchor and begin tracking it according to its frame of reference; i.e. the rectangle is now world-locked.
  • Press B (on the right Meta Quest Touch controller) to destroy and erase the most recent persistent Spatial Anchor and remove the digital objects attached to it.
  • Press X (on the left Meta Quest Touch controller) to query and retrieve any previously persisted Spatial Anchors. Any anchors successfully retrieved will have a rectangle object tracked at its position.
  • Press Y (on the left Meta Quest Touch controller) to save and share the currently available Spatial Anchors.
The saved Spatial Anchors you create in the sample will persist between sessions and headset reboots.
The recommended way to achieve Anchor Sharing in a polished application would be to programmatically access your colocated friends’ user IDs, and send a message to them with the UUIDs that have been shared with them so that they know what to Query from the cloud. This could be achieved with a third-party networking library.
The XrSpatialAnchor sample app doesn’t use any such library, and instead uses text files on the device(s) to control the download and sharing behavior. These files may be added or found (depending on the file) on the /sdcard/Android/data/com.oculus.sdk.spatialanchor/files/ path on your headset.
The text files are the following:
  • shareUserList.txt: This file should contain one user ID per line, in decimal integer format. The user IDs specified in this file should match the list of users with whom you want to share Spatial Anchors. This file needs to be created and pushed to the device.
  • inboundSpatialAnchorList.txt: This file contains one UUID per line, in uppercase hexadecimal format with no spaces or dashes. These UUIDs represent Spatial Anchors that have been shared with the current user, and will be queried from the cloud on app startup. This file needs to be created and pushed to the device. Its contents should be what is emitted in sharedSpatialAnchorList.txt.
  • sharedSpatialAnchorList.txt: This file is emitted by the app when you press the Y button to save and share, as described previously, and contains the list of UUIDs of Spatial Anchors that were shared. The format is the same as in inboundSpatialAnchorList.txt.
Make sure these text files do not contain leading or trailing whitespace.

Launching the Samples

To try this out, install the application under XrSpatialAnchor\Projects\Android onto the Meta Quest device. For instructions on launching samples, refer to the README.md located at XrSamples/README.md in the OpenXR Mobile SDK.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon