This document describes the Spatial Anchors OpenXR API reference.
XR_FB_spatial_entity
Extension Type: Instance Extension
Extension and Version Dependencies: Requires OpenXR 1.0.
Overview
This extension enables applications to place Spatial Anchors that specify world-locked frames of reference. The extension also lets your applications persist real-world content locations over time and contains definitions for the Entity-Component System. All Meta spatial entity extensions are dependent on this extension.
You track a Spatial Anchor by its anchor handle, which generates all the data for the Spatial Anchor. We use OpenXR XrSpace handles to give applications access to Spatial Anchors. In other words, any operation which involves Spatial Anchors uses XrSpace handles to identify the affected Spatial Anchors.
XrSystemSpatialEntityPropertiesFB describes a Spatial Entity system property (see XrSystemProperties). When the XR_FB_spatial_entity extension is enabled, calling the xrGetSystemProperties will result in this struct being present in the next chain of the XrSystemProperties struct retrieved.
next: A pointer to the next structure in a structure chain.
supportsSpatialEntity: A boolean value that lets you know if the system supports spatial entities.
Valid Usage (Implicit)
You must enable the XR_FB_spatial_entity extension prior to using XrSystemSpatialEntityPropertiesFB.
type: Must be XR_TYPE_SYSTEM_SPATIAL_ENTITY_PROPERTIES_FB.
next: Must be NULL or a valid pointer to the next structure in a structure chain.
supportsSpatialEntity: Must be a valid XrBool32 value.
Entity Component System
The entity/component system architectural pattern provides specialization by way of composition instead of inheritance. It thus avoids the type explosion that can occur when multiple entity types share some characteristics but differ in others.
Components represent the interfaces that are available to the anchor. Each anchor has a specific set of components it supports, and enabling these components allows access to the associated operations. Component support and state are unique to each anchor.
Anchors may support any subset of the components given in the XrComponentTypeFB enum. Operations supported on components are:
xrEnumerateSpaceSupportedComponentsFB.
xrSetSpaceComponentStatusFB.
xrGetSpaceComponentStatusFB.
xrEnumerateSpaceSupportedComponentsFB
The xrEnumerateSpaceSupportedComponentsFB function is defined as:
componentTypesCapacityInput: The maximum number of component types expected by the caller. The caller uses this maximum value to ensure the array returned through the componentTypes out-parameter does not exceed the bounds of the array allocated by the caller.
componentTypesCountOutput: An output parameter showing the number of enumerated component types.
componentTypes: An output parameter providing an array of the component types supported by the specified anchor.
The xrEnumerateSpaceSupportedComponentsFB function discovers any component interfaces that an entity supports. The list of supported components does not change as long as the entity exists. The list of component interfaces available for an entity may depend on which extensions are enabled. Component interfaces are not enumerated unless the corresponding extension that defines them is also enabled.
Valid Usage (Implicit)
You must enable the XR_FB_spatial_entity extension prior to calling xrEnumerateSpaceSupportedComponentsFB.
info: Pointer to an XrSpatialAnchorCreateInfoFB structure containing information about how to create the anchor.
requestId: A pointer to the returned XrAsyncRequestIdFB handle of the operation that was started.
The xrCreateSpatialAnchorFB function asynchronously creates a Spatial Anchor using the specified tracking origin and pose, relative to the specified tracking origin. The anchor can be made locatable at creation time, and you can query the 6 DOF pose, relative to the tracking origin, using the LocateSpace method.
Valid Usage (Implicit)
You must enable the XR_FB_spatial_entity extension prior to calling xrCreateSpatialAnchorFB.
next: Must be NULL or a pointer to the next structure in a structure chain. Core OpenXR doesn’t define such structures.
space: The XrSpace handle to the reference space defining the poseInSpace of the anchor you created.
poseInSpace: The XrPosef location and orientation of the Spatial Anchor in the specified reference space.
time: The XrTime timestamp associated with the specified pose.
Valid Usage (Implicit)
type: Must be XR_TYPE_SPATIAL_ANCHOR_CREATE_INFO_FB.
next: Must be NULL or a valid pointer to the next structure in a structure chain.
space: Must be a valid XrSpace handle.
XR_FB_spatial_entity_storage
Extension Type: Instance Extension
Extension and Version Dependencies: Requires OpenXR 1.0 & XR_FB_spatial_entity
Overview
This extension enables Spatial Anchors to be stored and persisted across sessions. If the XR_COMPONENT_TYPE_STORABLE_FB component has been enabled on the spatial entity, application developers may save, load, and erase persisted XrSpaces.
The function xrEraseSpaceFB erases a Spatial Anchor from storage at the specified location. This operation is asynchronous. The handle remains valid in memory after the erase operation until you destroy the anchor or the session ends.
Extension and Version Dependencies: Requires OpenXR 1.0 & XR_FB_spatial_entity
Overview
The XR_FB_spatial_entity_query extension enables an application to discover and restore persistent Spatial Anchors in the area. The application retrieves persistent Spatial Anchors from storage using the query system. The query system consists of filters that define the Spatial Anchor search query and the operation you want to perform on the search results.
XrSpaceQueryFilterBaseHeaderFB is the base filter struct used with the xrQuerySpacesFB function. Cast the queryInfo param of type XrSpaceQueryInfoFB* to XrSpaceQueryFilterBaseHeaderFB* when passing it to the xrQuerySpacesFB function.
The XrSpaceQueryInfoBaseHeaderFB structure is defined as:
typedef struct XrSpaceQueryInfoBaseHeaderFB {
XrStructureType type;
const void* next;
} XrSpaceQueryInfoBaseHeaderFB;
XrSpaceQueryInfoBaseHeaderFB is the base filter struct used with the xrQuerySpacesFB function. Cast the queryInfo param of type XrSpaceQueryInfoFB* to XrSpaceQueryFilterBaseHeaderFB* when passing it to the xrQuerySpacesFB function.
The function xrQuerySpacesFB enables your application to find and retrieve Spatial Anchors from storage. Cast a reference to an instance of the XrSpaceQueryInfoFB structure to XrSpaceQueryInfoBaseHeaderFB* when passing into the query function and structuring the query filters. This operation is asynchronous.
info: Must be a pointer to a valid XrSpaceQueryInfoBaseHeaderFB structure.
Events
XR_TYPE_EVENT_DATA_SPACE_QUERY_RESULTS_AVAILABLE_FB contains the requestId of the query and triggers once results are available for the query.
XR_TYPE_EVENT_DATA_SPACE_QUERY_COMPLETE_FB contains the requestId of the query and triggers when the query is complete.
Return Codes
Success
XR_SUCCESS
Failure
XR_ERROR_FUNCTION_UNSUPPORTED
XR_ERROR_VALIDATION_FAILURE
XR_ERROR_HANDLE_INVALID
xrRetrieveSpaceQueryResultsFB
The xrRetrieveSpaceQueryResultsFB function allows an application to retrieve all available results for a specified query. This function must only retrieve each query result once. After the application has used this function to retrieve a query result, the runtime frees its copy. Call this function once to get the number of results found and then once more to copy the results into a buffer provided by the application.
next: Must be NULL or a pointer to the next structure in a structure chain. No such structures are defined in core OpenXR or this extension.
resultCapacityInput: The capacity of the results array, or 0 to indicate a request to retrieve the required capacity.
resultCountOutput: An output parameter containing the count of results retrieved, or returns the required capacity in the case that resultCapacityInput is 0.
results: A pointer to an array of results, but can be NULL if resultCapacityInput is 0.
See the <<buffer-size-parameters, Buffer Size Parameters>> chapter for a detailed description of retrieving the required results size.
XrEventDataSpaceQueryResultsAvailableFB
The XrEventDataSpaceQueryResultsAvailableFB structure indicates results are available for the requestId associated with the xrQuerySpacesFB request: