Name String
XR_ANDROID_trackables
Extension Type
Instance extension
Registered Extension Number
456
Revision
1
Extension and Version Dependencies
Last Modified Date
2024-09-30
IP Status
No known IP claims.
Contributors
Spencer Quin, Google
Nihav Jain, Google
John Pursey, Google
Jared Finder, Google
Levana Chen, Google
Kenny Vercaemer, Google
Overview
This extension allows the application to access trackables from the physical environment, and create anchors attached to a trackable.
This extension defines plane trackables. Other extensions may add additional
trackable types. For example XR_ANDROID_trackables_object adds object
trackables, and XR_ANDROID_depth_texture adds depth buffers that allow
raycasting to arbitrary points in the environment.
A trackable is something that is tracked in the physical environment (see XrTrackableTypeANDROID):
- a plane (e.g. wall, floor, ceiling, table)
- an object (e.g. keyboard, mouse, laptop)
Create a trackable tracker
An XrTrackableTrackerANDROID is a handle that represents the resources required to discover and update trackables of a given XrTrackableTypeANDROID in the environment.
XR_DEFINE_HANDLE(XrTrackableTrackerANDROID)
The xrCreateTrackableTrackerANDROID function is defined as:
XrResult xrCreateTrackableTrackerANDROID(
XrSession session,
const XrTrackableTrackerCreateInfoANDROID* createInfo,
XrTrackableTrackerANDROID* trackableTracker);
Parameter Descriptions
sessionis the XrSession that creates the tracker.createInfois a pointer to an XrTrackableTrackerCreateInfoANDROID structure containing parameters to be used to create the tracker.trackableTrackeris a pointer to a handle in which the created XrTrackableTrackerANDROID is returned.
The application can use the xrCreateTrackableTrackerANDROID function to create a trackable tracker.
XR_ERROR_FEATURE_UNSUPPORTEDwill be returned if the system does not support trackables of the specified type.XR_ERROR_PERMISSION_INSUFFICIENTwill be returned if the required permissions have not been granted to the calling app.
The application can use the returned tracker handle in subsequent API calls. The XrTrackableTrackerANDROID handle must be eventually freed using the xrDestroyTrackableTrackerANDROID function.
Valid Usage (Implicit)
- The
XR_ANDROID_trackablesextension must be enabled prior to calling xrCreateTrackableTrackerANDROID sessionmust be a valid XrSession handlecreateInfomust be a pointer to a valid XrTrackableTrackerCreateInfoANDROID structuretrackableTrackermust be a pointer to an XrTrackableTrackerANDROID handle
Return Codes
XR_SUCCESSXR_SESSION_LOSS_PENDING
XR_ERROR_FUNCTION_UNSUPPORTEDXR_ERROR_VALIDATION_FAILUREXR_ERROR_RUNTIME_FAILUREXR_ERROR_HANDLE_INVALIDXR_ERROR_INSTANCE_LOSTXR_ERROR_SESSION_LOSTXR_ERROR_OUT_OF_MEMORYXR_ERROR_LIMIT_REACHEDXR_ERROR_FEATURE_UNSUPPORTED
The XrTrackableTrackerCreateInfoANDROID structure is defined as:
typedef struct XrTrackableTrackerCreateInfoANDROID {
XrStructureType type;
void* next;
XrTrackableTypeANDROID trackableType;
} XrTrackableTrackerCreateInfoANDROID;
Member Descriptions
typeis the XrStructureType of this structure.nextisNULLor a pointer to the next structure in a structure chain. No such structures are defined in core OpenXR or this extension.trackableTypeis the XrTrackableTypeANDROID that the tracker will track.
The XrTrackableTrackerCreateInfoANDROID structure provides creation options for the XrTrackableTrackerANDROID when passed to xrCreateTrackableTrackerANDROID.
Extensions may define structures that can be attached to next to allow
additional configuration for the trackable trackers.
Valid Usage (Implicit)
- The
XR_ANDROID_trackablesextension must be enabled prior to using XrTrackableTrackerCreateInfoANDROID typemust beXR_TYPE_TRACKABLE_TRACKER_CREATE_INFO_ANDROIDnextmust beNULLor a valid pointer to the next structure in a structure chain. See also: XrTrackableObjectConfigurationANDROIDtrackableTypemust be a valid XrTrackableTypeANDROID value
The XrTrackableTypeANDROID enum is defined as:
typedef enum XrTrackableTypeANDROID {
XR_TRACKABLE_TYPE_NOT_VALID_ANDROID = 0,
XR_TRACKABLE_TYPE_PLANE_ANDROID = 1,
XR_TRACKABLE_TYPE_DEPTH_ANDROID = 1000463000,
XR_TRACKABLE_TYPE_OBJECT_ANDROID = 1000466000
} XrTrackableTypeANDROID;
The xrDestroyTrackableTrackerANDROID function is defined as:
XrResult xrDestroyTrackableTrackerANDROID(
XrTrackableTrackerANDROID trackableTracker);
Parameter Descriptions
trackableTrackeris an XrTrackableTrackerANDROID handle previously created by xrCreateTrackableTrackerANDROID.
The xrDestroyTrackableTrackerANDROID function destroys the trackable tracker.
If there is no other valid XrTrackableTrackerANDROID that was created with the same XrTrackableTypeANDROID, the system may disable the tracking services required for that trackable type to save system resources.
Valid Usage (Implicit)
- The
XR_ANDROID_trackablesextension must be enabled prior to calling xrDestroyTrackableTrackerANDROID trackableTrackermust be a valid XrTrackableTrackerANDROID handle
Thread Safety
- Access to
trackableTracker, and any child handles, must be externally synchronized
Return Codes
XR_SUCCESS
XR_ERROR_FUNCTION_UNSUPPORTEDXR_ERROR_HANDLE_INVALID
Get all trackables
The XrTrackableANDROID atom is defined as:
XR_DEFINE_ATOM(XrTrackableANDROID)
XrTrackableANDROID is used to represent a single trackable
and is valid only within the lifecycle of its associated
XrTrackableTrackerANDROID.
The xrGetAllTrackablesANDROID function is defined as:
XrResult xrGetAllTrackablesANDROID(
XrTrackableTrackerANDROID trackableTracker,
uint32_t trackableCapacityInput,
uint32_t* trackableCountOutput,
XrTrackableANDROID* trackables);
Parameter Descriptions
trackableTrackeris the XrTrackableTrackerANDROID to query.trackableCapacityInputis the capacity of thetrackablesarray, or 0 to indicate a request to retrieve the required capacity.trackableCountOutputis a pointer to the count oftrackableswritten, or a pointer to the required capacity in the case thattrackablesis insufficient.trackablesis a pointer to an array ofXrTrackableANDROID. It can beNULLiftrackableCapacityInputis 0.See the Buffer Size Parameters section for a detailed description of retrieving the required
trackablessize.
xrGetAllTrackablesANDROID fills an array of
XrTrackableANDROID representing the trackables found in the
environment. The XrTrackableTypeANDROID of the returned
trackables must match the XrTrackableTypeANDROID of the
trackableTracker.
Get trackable plane
The xrGetTrackablePlaneANDROID function is defined as:
XrResult xrGetTrackablePlaneANDROID(
XrTrackableTrackerANDROID trackableTracker,
const XrTrackableGetInfoANDROID* getInfo,
XrTrackablePlaneANDROID* planeOutput);
Parameter Descriptions
trackableTrackeris the XrTrackableTrackerANDROID to query.getInfois the XrTrackableGetInfoANDROID with the information used to get the trackable plane.planeOutputis a pointer to the XrTrackablePlaneANDROID structure in which the trackable plane is returned.
The xrGetTrackablePlaneANDROID function returns details about the trackable plane, such as its geometry, orientation, and tracking state.
The plane information is resolved and relative to the base space at the time of the call to xrGetTrackablePlaneANDROID using XrTrackableGetInfoANDROID::time, XrTrackableGetInfoANDROID::baseSpace.
Valid Usage (Implicit)
- The
XR_ANDROID_trackablesextension must be enabled prior to calling xrGetTrackablePlaneANDROID trackableTrackermust be a valid XrTrackableTrackerANDROID handlegetInfomust be a pointer to a valid XrTrackableGetInfoANDROID structureplaneOutputmust be a pointer to an XrTrackablePlaneANDROID structure
Return Codes
XR_SUCCESSXR_SESSION_LOSS_PENDING
XR_ERROR_FUNCTION_UNSUPPORTEDXR_ERROR_VALIDATION_FAILUREXR_ERROR_RUNTIME_FAILUREXR_ERROR_HANDLE_INVALIDXR_ERROR_INSTANCE_LOSTXR_ERROR_SESSION_LOSTXR_ERROR_LIMIT_REACHEDXR_ERROR_TIME_INVALID
The XrTrackableGetInfoANDROID structure is defined as:
typedef struct XrTrackableGetInfoANDROID {
XrStructureType type;
void* next;
XrTrackableANDROID trackable;
XrSpace baseSpace;
XrTime time;
} XrTrackableGetInfoANDROID;
Member Descriptions
typeis the XrStructureType of this structure.nextisNULLor a pointer to the next structure in a structure chain. No such structures are defined in core OpenXR or this extension.trackableis theXrTrackableANDROIDplane to query.baseSpacethe plane pose will be relative to this XrSpace attime.timeis theXrTimeat which to evaluate the coordinates relative to thebaseSpace.
The XrTrackableGetInfoANDROID structure provides query options
when passed to xrGetTrackablePlaneANDROID. The trackable
must correspond to the trackableTracker used in
xrGetTrackablePlaneANDROID.
XR_ERROR_MISMATCHING_TRACKABLE_TYPE_ANDROID will be returned if the
trackable type of the trackable is not XR_TRACKABLE_TYPE_PLANE_ANDROID.
Valid Usage (Implicit)
- The
XR_ANDROID_trackablesextension must be enabled prior to using XrTrackableGetInfoANDROID typemust beXR_TYPE_TRACKABLE_GET_INFO_ANDROIDnextmust beNULLor a valid pointer to the next structure in a structure chainbaseSpacemust be a valid XrSpace handle
The XrTrackablePlaneANDROID structure is defined as:
typedef struct XrTrackablePlaneANDROID {
XrStructureType type;
void* next;
XrTrackingStateANDROID trackingState;
XrPosef centerPose;
XrExtent2Df extents;
XrPlaneTypeANDROID planeType;
XrPlaneLabelANDROID planeLabel;
XrTrackableANDROID subsumedByPlane;
XrTime lastUpdatedTime;
uint32_t vertexCapacityInput;
uint32_t* vertexCountOutput;
XrVector2f* vertices;
} XrTrackablePlaneANDROID;
Member Descriptions
typeis the XrStructureType of this structure.nextisNULLor a pointer to the next structure in a structure chain. No such structures are defined in core OpenXR or this extension.trackingStateis the XrTrackingStateANDROID of the plane.centerPoseis an XrPosef defining the position and orientation of the plane within the reference frame of the corresponding XrTrackableGetInfoANDROID::baseSpace. An identity orientation here represents a coordinate axes with +Y parallel to the plane's normal.extentsis the XrExtent2Df dimension of the plane.planeTypeis the XrPlaneTypeANDROID that the runtime has determined for this plane.planeLabelis the XrPlaneLabelANDROID that the runtime has determined for this plane.subsumedByPlaneis theXrTrackableANDROIDof the plane that subsumes this plane (XR_NULL_TRACKABLE_ANDROIDif none exists).lastUpdatedTimeis theXrTimeof the last update of the plane.vertexCapacityInputis the capacity of theverticesarray, or 0 to indicate a request to retrieve the required capacity.vertexCountOutputis a pointer to the count ofverticeswritten, or a pointer to the required capacity in the case thatverticesis insufficient.verticesis a pointer to an array of XrVector2f. It can beNULLifvertexCapacityInputis 0. The vertices are in counter-clockwise order. The polygon may be concave and must not be self-intersecting.- See the Buffer Size Parameters section for a detailed
description of retrieving the required
verticessize.
Valid Usage (Implicit)
- The
XR_ANDROID_trackablesextension must be enabled prior to using XrTrackablePlaneANDROID typemust beXR_TYPE_TRACKABLE_PLANE_ANDROIDnextmust beNULLor a valid pointer to the next structure in a structure chaintrackingStatemust be a valid XrTrackingStateANDROID valueplaneTypemust be a valid XrPlaneTypeANDROID valueplaneLabelmust be a valid XrPlaneLabelANDROID valuevertexCountOutputmust be a pointer to auint32_tvalueverticesmust be a pointer to an array ofvertexCapacityInputXrVector2f structures- The
vertexCapacityInputparameter must be greater than0
The XrTrackingStateANDROID enum describes the tracking state
of an XrTrackableANDROID.
typedef enum XrTrackingStateANDROID {
XR_TRACKING_STATE_PAUSED_ANDROID = 0,
XR_TRACKING_STATE_STOPPED_ANDROID = 1,
XR_TRACKING_STATE_TRACKING_ANDROID = 2
} XrTrackingStateANDROID;
Description |
|
|
Indicates that the trackable or anchor tracking is paused but may be resumed in the future. |
|
Tracking has stopped on this Trackable and will never be resumed. |
|
The object is tracked and its pose is current. |
The XrPlaneTypeANDROID enum is the type of an
XrTrackableANDROID plane.
typedef enum XrPlaneTypeANDROID {
XR_PLANE_TYPE_HORIZONTAL_DOWNWARD_FACING_ANDROID = 0,
XR_PLANE_TYPE_HORIZONTAL_UPWARD_FACING_ANDROID = 1,
XR_PLANE_TYPE_VERTICAL_ANDROID = 2,
XR_PLANE_TYPE_ARBITRARY_ANDROID = 3
} XrPlaneTypeANDROID;
The XrPlaneLabelANDROID enum is a label for a
XrTrackableANDROID plane.
typedef enum XrPlaneLabelANDROID {
XR_PLANE_LABEL_UNKNOWN_ANDROID = 0,
XR_PLANE_LABEL_WALL_ANDROID = 1,
XR_PLANE_LABEL_FLOOR_ANDROID = 2,
XR_PLANE_LABEL_CEILING_ANDROID = 3,
XR_PLANE_LABEL_TABLE_ANDROID = 4
} XrPlaneLabelANDROID;
Create anchor space
XrResult xrCreateAnchorSpaceANDROID(
XrSession session,
const XrAnchorSpaceCreateInfoANDROID* createInfo,
XrSpace* anchorOutput);
Parameter Descriptions
sessionis the XrSession that creates the anchor space.createInfois a pointer to an XrAnchorSpaceCreateInfoANDROID structure containing parameters to be used to create the anchor space.anchorOutputis a pointer to a handle in which the created XrSpace is returned.
At any point of time both the position and direction of the anchor is tracked or
untracked. This means that both
XR_SPACE_LOCATION_POSITION_TRACKED_BIT and
XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT must be set or both must be cleared
when the application calls
xrLocateSpace or xrLocateSpaces for
anchorOutput.
The application must eventually free the returned XrSpace using xrDestroySpace.
XR_ERROR_FEATURE_UNSUPPORTEDmust be returned if the system does not support anchors.XR_ERROR_TRACKABLE_TYPE_NOT_SUPPORTED_ANDROIDmust be returned if the specific anchor attachment is not supported.
Valid Usage (Implicit)
- The
XR_ANDROID_trackablesextension must be enabled prior to calling xrCreateAnchorSpaceANDROID sessionmust be a valid XrSession handlecreateInfomust be a pointer to a valid XrAnchorSpaceCreateInfoANDROID structureanchorOutputmust be a pointer to an XrSpace handle
Return Codes
XR_SUCCESSXR_SESSION_LOSS_PENDING
XR_ERROR_FUNCTION_UNSUPPORTEDXR_ERROR_TRACKABLE_TYPE_NOT_SUPPORTED_ANDROIDXR_ERROR_VALIDATION_FAILUREXR_ERROR_RUNTIME_FAILUREXR_ERROR_HANDLE_INVALIDXR_ERROR_INSTANCE_LOSTXR_ERROR_SESSION_LOSTXR_ERROR_LIMIT_REACHEDXR_ERROR_POSE_INVALIDXR_ERROR_TIME_INVALIDXR_ERROR_OUT_OF_MEMORY
The XrAnchorSpaceCreateInfoANDROID structure is defined as:
typedef struct XrAnchorSpaceCreateInfoANDROID {
XrStructureType type;
void* next;
XrSpace space;
XrTime time;
XrPosef pose;
XrTrackableANDROID trackable;
} XrAnchorSpaceCreateInfoANDROID;
Member Descriptions
typeis the XrStructureType of this structure.nextisNULLor a pointer to the next structure in a structure chain. No such structures are defined in core OpenXR or this extension.spaceis the XrSpace on which the anchor will be created.timeis theXrTimeof the anchor creation.poseis the XrPosef of the anchor.trackableis theXrTrackableANDROIDon which the anchor will be attached. It may beXR_NULL_TRACKABLE_ANDROIDto create an spatial anchor.
Valid Usage (Implicit)
- The
XR_ANDROID_trackablesextension must be enabled prior to using XrAnchorSpaceCreateInfoANDROID typemust beXR_TYPE_ANCHOR_SPACE_CREATE_INFO_ANDROIDnextmust beNULLor a valid pointer to the next structure in a structure chainspacemust be a valid XrSpace handle
Example code for getting all trackables
The following example code demonstrates how to get all trackables of a given type.
XrSession session; // previously initialized
// The function pointers are previously initialized using xrGetInstanceProcAddr.
PFN_xrCreateTrackableTrackerANDROID xrCreateTrackableTrackerANDROID; // previously initialized
PFN_xrGetAllTrackablesANDROID xrGetAllTrackablesANDROID; // previously initialized
PFN_xrDestroyTrackableTrackerANDROID xrDestroyTrackableTrackerANDROID; // previously initialized
XrTrackableTrackerCreateInfoANDROID createInfo{XR_TYPE_TRACKABLE_TRACKER_CREATE_INFO_ANDROID};
createInfo.trackableType = XR_TRACKABLE_TYPE_PLANE_ANDROID;
XrTrackableTrackerANDROID planeTrackableTracker;
XrResult result = xrCreateTrackableTrackerANDROID(
session,
&createInfo,
&planeTrackableTracker);
if (result != XR_SUCCESS) { /* Handle failures. */ }
uint32_t trackableCountOutput = 0;
std::vector<XrTrackableANDROID> allPlaneTrackables;
// Query the number of trackables available.
result = xrGetAllTrackablesANDROID(
planeTrackableTracker,
0,
&trackableCountOutput,
nullptr
);
if (result == XR_SUCCESS) {
allPlaneTrackables.resize(trackableCountOutput, XR_NULL_HANDLE);
// Fetch the actual trackable handles in the appropriately resized array.
result = xrGetAllTrackablesANDROID(
planeTrackableTracker,
trackableCountOutput,
&trackableCountOutput,
allPlaneTrackables.data());
if (result == XR_SUCCESS) {
for (XrTrackableANDROID trackable : allPlaneTrackables) {
// You now have all trackables of the specified type.
}
}
}
// Release trackable tracker.
result = xrDestroyTrackableTrackerANDROID(planeTrackableTracker);
Example code for getting trackable plane
The following example code demonstrates how to get a trackable plane from an
existing XrTrackableANDROID, obtained from a hit result
XR_ANDROID_raycast or xrGetTrackablesANDROID.
XrTrackableTrackerANDROID planeTracker; // previously created
// The function pointers are previously initialized using xrGetInstanceProcAddr.
PFN_xrGetTrackablePlaneANDROID xrGetTrackablePlaneANDROID; // previously initialized
XrTime updateTime; // Time used for the current frame's simulation update.
XrSpace appSpace; // Space created for XR_REFERENCE_SPACE_TYPE_LOCAL.
XrTrackableANDROID planeTrackable; // Acquired from a hit result or getTrackables().
XrTrackableGetInfoANDROID planeGetInfo;
planeGetInfo.type = XR_TYPE_TRACKABLE_GET_INFO_ANDROID;
planeGetInfo.next = nullptr;
planeGetInfo.trackable = planeTrackable;
planeGetInfo.space = appSpace;
planeGetInfo.time = updateTime;
XrTrackablePlaneANDROID plane = { XR_TYPE_TRACKABLE_PLANE_ANDROID };
result = xrGetTrackablePlaneANDROID(
planeTracker,
&planeGetInfo,
&plane
);
if (result == XR_SUCCESS) {
// Plane tracking state, center pose, extents, type now available in plane.
}
Example code for creating anchor space
The following example code demonstrates how to create an anchor space attached to a trackable.
XrSession session; // Created at app startup.
XrTime updateTime; // Time used for the current frame's simulation update.
XrSpace appSpace; // Space created for XR_REFERENCE_SPACE_TYPE_LOCAL.
XrTrackableANDROID planeTrackable; // Acquired from a hit result or getTrackables().
// Create an anchor at (2, 2, 2) world-coordinates.
XrAnchorSpaceCreateInfoANDROID spatialAnchorCreateInfo;
spatialAnchorCreateInfo.type = XR_TYPE_ANCHOR_SPACE_CREATE_INFO_ANDROID;
spatialAnchorCreateInfo.next = nullptr;
spatialAnchorCreateInfo.space = appSpace;
spatialAnchorCreateInfo.time = updateTime;
spatialAnchorCreateInfo.pose = { { 0, 0, 0, 1 }, { 2, 2, 2 } };
XrSpace spatialAnchor = XR_NULL_HANDLE;
XrResult result = xrCreateAnchorSpaceANDROID(
session,
&spatialAnchorCreateInfo,
&spatialAnchor
);
// Create an anchor attached to a trackable.
XrTrackablePlane plane = ...;
XrAnchorSpaceCreateInfoANDROID trackableAnchorCreateInfo;
trackableAnchorCreateInfo.type = XR_TYPE_ANCHOR_SPACE_CREATE_INFO_ANDROID;
trackableAnchorCreateInfo.next = nullptr;
trackableAnchorCreateInfo.space = appState;
trackableAnchorCreateInfo.pose = plane.centerPose;
trackableAnchorCreateInfo.trackable = planeTrackable;
XrSpace trackableAnchor = XR_NULL_HANDLE;
XrResult result = xrCreateAnchorSpaceANDROID(
session,
&trackableAnchorCreateInfo,
&trackableAnchor
);
while (true) {
// app update loop
// ...
// Get the current location of the anchor's space w.r.t the world.
XrSpaceLocation anchorLocation = { XR_TYPE_SPACE_LOCATION };
result = xrLocateSpace(trackableAnchor, appSpace, updateTime, &anchorLocation);
if (anchor.trackingState == XR_TRACKING_STATE_TRACKING_ANDROID) {
// Update anchor pose.
doDrawingForAnchor(anchorLocation.pose);
} else {
// ...
}
}
// Cleanup - destroy the space, detatch the anchor so its no longer tracked by the
// runtime and then release all resources held by it.
xrDestroySpace(spatialAnchor);
xrDestroySpace(trackableAnchor);
New Base Types
New Object Types
New Enum Constants
XrStructureType enumeration is extended with:
XR_TYPE_TRACKABLE_GET_INFO_ANDROIDXR_TYPE_ANCHOR_SPACE_CREATE_INFO_ANDROIDXR_TYPE_TRACKABLE_PLANE_ANDROIDXR_TYPE_TRACKABLE_TRACKER_CREATE_INFO_ANDROID
XrObjectType enumeration is extended with:
XR_OBJECT_TYPE_TRACKABLE_TRACKER_ANDROID
XrResult enumeration is extended with:
XR_ERROR_MISMATCHING_TRACKABLE_TYPE_ANDROIDXR_ERROR_TRACKABLE_TYPE_NOT_SUPPORTED_ANDROID
New Enums
New Structures
- XrTrackableTrackerCreateInfoANDROID
- XrTrackableGetInfoANDROID
- XrTrackablePlaneANDROID
- XrAnchorSpaceCreateInfoANDROID
New Functions
- xrCreateTrackableTrackerANDROID
- xrDestroyTrackableTrackerANDROID
- xrGetAllTrackablesANDROID
- xrGetTrackablePlaneANDROID
- xrCreateAnchorSpaceANDROID
Issues
Version History
- Revision 1, 2024-09-27 (Kenny Vercaemer)
- Initial extension description.
OpenXR™ and the OpenXR logo are trademarks owned by The Khronos Group Inc. and are registered as a trademark in China, the European Union, Japan and the United Kingdom.