XR_ANDROID_device_anchor_persistence OpenXR 扩展

名称字符串

XR_ANDROID_device_anchor_persistence

扩展类型

实例扩展

注册扩展编号

458

修订版

1

扩展和版本依赖项

XR_EXT_uuidXR_ANDROID_trackables

最后修改日期

2024-10-10

IP 状态

无已知 IP 声明。

贡献者

Nihav Jain, Google

Levana Chen, Google

Spencer Quin, Google

Kenny Vercaemer, Google

概述

此扩展允许应用程序在当前设备上为当前用户持久化、检索和解除持久化锚点,跨越应用程序和设备会话。

检查系统能力

XrSystemDeviceAnchorPersistencePropertiesANDROID 结构定义为

typedef struct XrSystemDeviceAnchorPersistencePropertiesANDROID {
    XrStructureType    type;
    void*              next;
    XrBool32           supportsAnchorPersistence;
} XrSystemDeviceAnchorPersistencePropertiesANDROID;

成员描述

  • type 是此结构的 XrStructureType
  • nextNULL 或指向结构链中下一个结构的指针。核心 OpenXR 或此扩展中未定义此类结构。
  • supportsAnchorPersistence 是一个 XrBool32,指示当前系统是否支持空间锚点的锚点持久化。

应用程序可以通过在调用 xrGetSystemProperties 时使用 XrSystemDeviceAnchorPersistencePropertiesANDROID 结构扩展 XrSystemProperties 来检查系统是否能够持久化空间锚点(参见 xrCreateAnchorSpaceANDROID)。对于支持的可追踪锚点,应用程序可以使用 xrEnumerateSupportedPersistenceAnchorTypesANDROID 查询支持的类型。

如果 supportsAnchorPersistence 返回 XR_FALSE,则对空间锚点进行操作的设备锚点持久化函数将返回 XR_ERROR_FEATURE_UNSUPPORTED

有效用法(隐式)

xrEnumerateSupportedPersistenceAnchorTypesANDROID 函数定义为

XrResult xrEnumerateSupportedPersistenceAnchorTypesANDROID(
    XrInstance                                  instance,
    XrSystemId                                  systemId,
    uint32_t                                    trackableTypeCapacityInput,
    uint32_t*                                   trackableTypeCountOutput,
    XrTrackableTypeANDROID*                     trackableTypes);

参数描述

  • session 是创建 XrDeviceAnchorPersistenceANDROIDXrSession
  • trackableTypeCapacityInputtrackableTypes 的容量,或 0 以检索所需容量。
  • trackableTypeCountOutput 是指向数组计数的指针,或者在 trackableTypeCapacityInput 不足时指向所需容量的指针。
  • trackableTypes 是指向 XrTrackableTypeANDROID 数组的指针,但如果 trackableTypeCapacityInput0,则可以NULL
  • 有关检索所需 trackableTypes 大小的详细描述,请参见缓冲区大小参数一节。

应用程序可以使用 xrEnumerateSupportedPersistenceAnchorTypesANDROID 来检查对其他 XrTrackableTypeANDROID 可追踪物的锚点持久化支持。

如果在 trackableTypes 数组中未返回给定的 XrTrackableTypeANDROID,则对该类型锚点进行操作的设备锚点持久化函数将返回 XR_ERROR_FEATURE_UNSUPPORTED

有效用法(隐式)

返回码

成功

  • XR_SUCCESS

失败

  • XR_ERROR_SYSTEM_INVALID
  • XR_ERROR_VALIDATION_FAILURE
  • XR_ERROR_RUNTIME_FAILURE
  • XR_ERROR_HANDLE_INVALID
  • XR_ERROR_INSTANCE_LOST
  • XR_ERROR_SIZE_INSUFFICIENT
  • XR_ERROR_FUNCTION_UNSUPPORTED

创建设备锚点持久化句柄

XrDeviceAnchorPersistenceANDROID 是一个句柄,表示持久化和跟踪持久化锚点所需的资源。

XR_DEFINE_HANDLE(XrDeviceAnchorPersistenceANDROID)

xrCreateDeviceAnchorPersistenceANDROID 函数定义为

XrResult xrCreateDeviceAnchorPersistenceANDROID(
    XrSession                                   session,
    const XrDeviceAnchorPersistenceCreateInfoANDROID* createInfo,
    XrDeviceAnchorPersistenceANDROID*           outHandle);

参数描述

应用程序可以通过调用 xrCreateDeviceAnchorPersistenceANDROID 创建 XrDeviceAnchorPersistenceANDROID 句柄。XrDeviceAnchorPersistenceANDROID 可以在后续 API 调用中用于持久化或解除持久化锚点。XrDeviceAnchorPersistenceANDROID 句柄必须最终使用 xrDestroyDeviceAnchorPersistenceANDROID 函数释放。

有效用法(隐式)

返回码

成功

  • XR_SUCCESS
  • XR_SESSION_LOSS_PENDING

失败

  • XR_ERROR_FUNCTION_UNSUPPORTED
  • XR_ERROR_VALIDATION_FAILURE
  • XR_ERROR_RUNTIME_FAILURE
  • XR_ERROR_HANDLE_INVALID
  • XR_ERROR_INSTANCE_LOST
  • XR_ERROR_SESSION_LOST
  • XR_ERROR_OUT_OF_MEMORY
  • XR_ERROR_LIMIT_REACHED

XrDeviceAnchorPersistenceCreateInfoANDROID 结构定义为

typedef struct XrDeviceAnchorPersistenceCreateInfoANDROID {
    XrStructureType    type;
    void*              next;
} XrDeviceAnchorPersistenceCreateInfoANDROID;

成员描述

  • type 是此结构的 XrStructureType
  • nextNULL 或指向结构链中下一个结构的指针。核心 OpenXR 或此扩展中未定义此类结构。

当传递给 xrCreateDeviceAnchorPersistenceANDROID 时,XrDeviceAnchorPersistenceCreateInfoANDROID 结构提供了 XrDeviceAnchorPersistenceANDROID 的创建选项。

有效用法(隐式)

xrDestroyDeviceAnchorPersistenceANDROID 函数定义为

XrResult xrDestroyDeviceAnchorPersistenceANDROID(
    XrDeviceAnchorPersistenceANDROID            handle);

参数描述

xrDestroyDeviceAnchorPersistenceANDROID 函数销毁设备锚点持久化句柄。

有效用法(隐式)

线程安全

  • handle 和任何子句柄的访问必须进行外部同步

返回码

成功

  • XR_SUCCESS

失败

  • XR_ERROR_FUNCTION_UNSUPPORTED
  • XR_ERROR_HANDLE_INVALID

持久化锚点

xrPersistAnchorANDROID 函数定义为

XrResult xrPersistAnchorANDROID(
    XrDeviceAnchorPersistenceANDROID            handle,
    const XrPersistedAnchorSpaceInfoANDROID*    persistedInfo,
    XrUuidEXT*                                  anchorIdOutput);

参数描述

应用程序可以通过调用 xrPersistAnchorANDROID 请求锚点持久化。应用程序不得假定成功返回值意味着锚点立即持久化。应用程序应该使用返回的锚点 XrUuidEXT 来检查锚点的持久化状态,通过调用 xrGetAnchorPersistStateANDROID。应用程序可以使用 xrUnpersistAnchorANDROID 来解除持久化锚点。

  • 如果在调用时锚点未被追踪,将返回 XR_ERROR_ANCHOR_NOT_TRACKING_ANDROID
  • 如果持久化数据未就绪,将返回 XR_ERROR_PERSISTED_DATA_NOT_READY_ANDROID
  • 一旦锚点已排队等待持久化,将返回 XR_SUCCESS

有效用法(隐式)

返回码

成功

  • XR_SUCCESS
  • XR_SESSION_LOSS_PENDING

失败

  • XR_ERROR_ANCHOR_NOT_TRACKING_ANDROID
  • XR_ERROR_FUNCTION_UNSUPPORTED
  • XR_ERROR_VALIDATION_FAILURE
  • XR_ERROR_RUNTIME_FAILURE
  • XR_ERROR_HANDLE_INVALID
  • XR_ERROR_INSTANCE_LOST
  • XR_ERROR_SESSION_LOST
  • XR_ERROR_OUT_OF_MEMORY
  • XR_ERROR_LIMIT_REACHED

XrPersistedAnchorSpaceInfoANDROID 结构定义为

typedef struct XrPersistedAnchorSpaceInfoANDROID {
    XrStructureType    type;
    void*              next;
    XrSpace            anchor;
} XrPersistedAnchorSpaceInfoANDROID;

成员描述

  • type 是此结构的 XrStructureType
  • nextNULL 或指向结构链中下一个结构的指针。核心 OpenXR 或此扩展中未定义此类结构。
  • anchor 是先前由 xrCreateAnchorSpaceANDROID 创建用于持久化的锚点 XrSpace

有效用法(隐式)

xrGetAnchorPersistStateANDROID 函数定义为

XrResult xrGetAnchorPersistStateANDROID(
    XrDeviceAnchorPersistenceANDROID            handle,
    const XrUuidEXT*                            anchorId,
    XrAnchorPersistStateANDROID*                persistState);

参数描述

有效用法(隐式)

返回码

成功

  • XR_SUCCESS
  • XR_SESSION_LOSS_PENDING

失败

  • XR_ERROR_FUNCTION_UNSUPPORTED
  • XR_ERROR_VALIDATION_FAILURE
  • XR_ERROR_RUNTIME_FAILURE
  • XR_ERROR_HANDLE_INVALID
  • XR_ERROR_INSTANCE_LOST
  • XR_ERROR_SESSION_LOST
  • XR_ERROR_ANCHOR_ID_NOT_FOUND_ANDROID

XrAnchorPersistStateANDROID 枚举定义为

typedef enum XrAnchorPersistStateANDROID {
    XR_ANCHOR_PERSIST_STATE_PERSIST_NOT_REQUESTED_ANDROID = 0,
    XR_ANCHOR_PERSIST_STATE_PERSIST_PENDING_ANDROID = 1,
    XR_ANCHOR_PERSIST_STATE_PERSISTED_ANDROID = 2
} XrAnchorPersistStateANDROID;

枚举

描述

XR_ANCHOR_PERSIST_STATE_PERSIST_NOT_REQUESTED_ANDROID

应用程序尚未请求持久化锚点。

XR_ANCHOR_PERSIST_STATE_PERSIST_PENDING_ANDROID

已请求持久化锚点但尚未持久化。

XR_ANCHOR_PERSIST_STATE_PERSISTED_ANDROID

锚点已由运行时成功持久化。

从持久化数据创建锚点

xrCreatePersistedAnchorSpaceANDROID 函数定义为

XrResult xrCreatePersistedAnchorSpaceANDROID(
    XrDeviceAnchorPersistenceANDROID            handle,
    const XrPersistedAnchorSpaceCreateInfoANDROID* createInfo,
    XrSpace*                                    anchorOutput);

参数描述

应用程序可以通过调用 xrCreatePersistedAnchorSpaceANDROID 并使用相同的 XrUuidEXT,从先前持久化的锚点创建 XrSpace 锚点。这是 XR_ANDROID_trackables 中定义的创建锚点的另一种方式。

  • 如果未找到锚点 XrUuidEXT,将返回 XR_ERROR_ANCHOR_ID_NOT_FOUND_ANDROID

有效用法(隐式)

返回码

成功

  • XR_SUCCESS
  • XR_SESSION_LOSS_PENDING

失败

  • XR_ERROR_FUNCTION_UNSUPPORTED
  • XR_ERROR_VALIDATION_FAILURE
  • XR_ERROR_RUNTIME_FAILURE
  • XR_ERROR_HANDLE_INVALID
  • XR_ERROR_INSTANCE_LOST
  • XR_ERROR_SESSION_LOST
  • XR_ERROR_OUT_OF_MEMORY
  • XR_ERROR_LIMIT_REACHED
  • XR_ERROR_ANCHOR_ID_NOT_FOUND_ANDROID
  • XR_ERROR_PERSISTED_DATA_NOT_READY_ANDROID

XrPersistedAnchorSpaceCreateInfoANDROID 结构定义为

typedef struct XrPersistedAnchorSpaceCreateInfoANDROID {
    XrStructureType    type;
    void*              next;
    XrUuidEXT          anchorId;
} XrPersistedAnchorSpaceCreateInfoANDROID;

成员描述

  • type 是此结构的 XrStructureType
  • nextNULL 或指向结构链中下一个结构的指针。核心 OpenXR 或此扩展中未定义此类结构。
  • anchorId 是要从中创建锚点 XrSpace 的持久化锚点的 XrUuidEXT

当传递给 xrCreateDeviceAnchorPersistenceANDROID 时,XrPersistedAnchorSpaceCreateInfoANDROID 结构提供了锚点的创建选项。

有效用法(隐式)

枚举持久化锚点

xrEnumeratePersistedAnchorsANDROID 函数定义为

XrResult xrEnumeratePersistedAnchorsANDROID(
    XrDeviceAnchorPersistenceANDROID            handle,
    uint32_t                                    anchorIdsCapacityInput,
    uint32_t*                                   anchorIdsCountOutput,
    XrUuidEXT*                                  anchorIds);

参数描述

  • handleXrDeviceAnchorPersistenceANDROID
  • anchorIdsCapacityInputanchorIds 数组的容量,或 0 表示请求检索所需容量。
  • anchorIdsCountOutput 是指向已写入 anchorIds 计数的指针,或者在 anchorIdsCapacityInput 不足时指向所需容量的指针。
  • anchorIds 是指向 XrUuidEXT 结构数组的指针。如果 anchorIdsCapacityInput 为 0,则可以NULL
  • 有关检索所需 anchorIds 大小的详细描述,请参见缓冲区大小参数一节。

应用程序可以通过调用 xrEnumeratePersistedAnchorsANDROID 来枚举所有当前持久化的锚点。anchorIds 将保存持久化锚点的 UUID,直至达到数组容量。如果容量不足,应用程序无法保证返回哪些锚点。

有效用法(隐式)

返回码

成功

  • XR_SUCCESS
  • XR_SESSION_LOSS_PENDING

失败

  • XR_ERROR_PERSISTED_DATA_NOT_READY_ANDROID
  • XR_ERROR_FUNCTION_UNSUPPORTED
  • XR_ERROR_VALIDATION_FAILURE
  • XR_ERROR_RUNTIME_FAILURE
  • XR_ERROR_HANDLE_INVALID
  • XR_ERROR_INSTANCE_LOST
  • XR_ERROR_SESSION_LOST
  • XR_ERROR_SIZE_INSUFFICIENT

解除持久化锚点

xrUnpersistAnchorANDROID 函数定义为

XrResult xrUnpersistAnchorANDROID(
    XrDeviceAnchorPersistenceANDROID            handle,
    const XrUuidEXT*                            anchorId);

参数描述

应用程序可以通过调用 xrUnpersistAnchorANDROID 并传递要解除持久化的锚点的 XrUuidEXT 来解除持久化锚点。

  • 如果持久化数据未就绪,将返回 XR_ERROR_PERSISTED_DATA_NOT_READY_ANDROID
  • 如果未找到锚点 XrUuidEXT,将返回 XR_ERROR_ANCHOR_ID_NOT_FOUND_ANDROID

有效用法(隐式)

返回码

成功

  • XR_SUCCESS
  • XR_SESSION_LOSS_PENDING

失败

  • XR_ERROR_FUNCTION_UNSUPPORTED
  • XR_ERROR_VALIDATION_FAILURE
  • XR_ERROR_RUNTIME_FAILURE
  • XR_ERROR_HANDLE_INVALID
  • XR_ERROR_INSTANCE_LOST
  • XR_ERROR_SESSION_LOST
  • XR_ERROR_OUT_OF_MEMORY
  • XR_ERROR_LIMIT_REACHED
  • XR_ERROR_ANCHOR_ID_NOT_FOUND_ANDROID
  • XR_ERROR_PERSISTED_DATA_NOT_READY_ANDROID

锚点持久化示例代码

以下示例代码演示了如何检查系统能力、持久化、枚举和解除持久化锚点,以及从持久化锚点 XrUuidEXT 创建锚点。

XrSession session; // previously initialized
XrSpace anchor; // previously initialized

// The function pointers are previously initialized using xrGetInstanceProcAddr.
PFN_xrEnumerateSupportedPersistenceAnchorTypesANDROID xrEnumerateSupportedPersistenceAnchorTypesANDROID; // previously initialized
PFN_xrCreateDeviceAnchorPersistenceANDROID xrCreateDeviceAnchorPersistenceANDROID; // previously initialized
PFN_xrDestroyDeviceAnchorPersistenceANDROID xrDestroyDeviceAnchorPersistenceANDROID; // previously initialized
PFN_xrPersistAnchorANDROID xrPersistAnchorANDROID; // previously initialized
PFN_xrGetAnchorPersistStateANDROID xrGetAnchorPersistStateANDROID; // previously initialized
PFN_xrCreatePersistedAnchorSpaceANDROID xrCreatePersistedAnchorSpaceANDROID; // previously initialized
PFN_xrEnumeratePersistedAnchorsANDROID xrEnumeratePersistedAnchorsANDROID; // previously initialized
PFN_xrUnpersistAnchorANDROID xrUnpersistAnchorANDROID; // previously initialized

// Create a device anchor persistence handle
XrDeviceAnchorPersistenceCreateInfoANDROID persistenceHandleCreateInfo;
persistenceHandleCreateInfo.type = XR_TYPE_DEVICE_ANCHOR_PERSISTENCE_CREATE_INFO_ANDROID;
persistenceHandleCreateInfo.next = nullptr;

XrDeviceAnchorPersistenceANDROID persistenceHandle;
CHK_XR(xrCreateDeviceAnchorPersistenceANDROID(session, &persistenceHandleCreateInfo, &persistenceHandle));

/// Persist an anchor
XrPersistedAnchorSpaceInfo anchorSpaceInfo;
anchorSpaceInfo.type = XR_TYPE_PERSISTED_ANCHOR_SPACE_INFO_ANDROID;
anchorSpaceInfo.next = nullptr;
anchorSpaceInfo.anchor = anchor;

XrUuidEXT anchorId;
do {
  XrResult result = xrPersistAnchorANDROID(
    persistenceHandle, &anchorSpaceInfo, &anchorId);
} while (result == XR_ERROR_PERSISTED_DATA_NOT_READY_ANDROID ||
         result == XR_ERROR_ANCHOR_NOT_TRACKING_ANDROID);
if (result != XR_SUCCESS) {
  // Handle errors
}


// ... Update loop ...
// Poll for anchor persist state to confirm if it was successfully persisted
XrAnchorPersistStateANDROID persistState;
CHK_XR(xrGetAnchorPersistStateANDROID(persistenceHandle, &anchorId, &persistState));
if (persistState == XR_ANCHOR_PERSIST_STATE_PERSISTED_ANDROID)  {
  // The anchor was persisted successfully
}

// Enumerate all persisted anchors
uint32_t anchorCountOutput = 0;
std::vector<XrUuidEXT> allAnchors;

CHK_XR(xrEnumeratePersistedAnchorsANDROID(
  persistenceHandle,
  anchorCountOutput,
  &anchorCountOutput,
  nullptr
));
allAnchors.resize(anchorCountOutput, XR_NULL_HANDLE);

// Fetch the actual anchors in an appropriately resized array.
CHK_XR(xrEnumeratePersistedAnchorsANDROID(
  persistenceHandle,
  anchorCountOutput,
  &anchorCountOutput,
  allAnchors.data()
));

// Creating an anchor from a previously persisted anchor using its UUID
XrTime updateTime; // Time used for the current frame's simulation update.
XrUuidEXT anchorId = allAnchors[0];

XrPersistedAnchorSpaceCreateInfo createInfo;
createInfo.type = XR_TYPE_PERSISTED_ANCHOR_CREATE_INFO_ANDROID;
createInfo.next = nullptr;
createInfo.anchorId = anchorId;

XrSpace anchorSpace = XR_NULL_HANDLE;
CHK_XR(xrCreatePersistedAnchorSpaceANDROID(
  persistenceHandle,
  &createInfo,
  &anchorSpace
));

// The anchor was found and retrieved from the local device successfully.
XrSpaceLocation anchorLocation = { XR_TYPE_SPACE_LOCATION };
CHK_XR(xrLocateSpace(anchorSpace, appSpace, updateTime, &anchorLocation));
XrPosef pose = anchorLocation.pose;

// Unpersist the anchor
do {
  XrResult result = xrUnpersistAnchorANDROID(persistenceHandle, &anchorId);
} while (result == XR_ERROR_PERSISTED_DATA_NOT_READY_ANDROID);
if (result != XR_SUCCESS) {
  // Handle errors
}

// Once app is done with all persistence related tasks
CHK_XR(xrDestroySpace(anchorSpace));
CHK_XR(xrDestroyDeviceAnchorPersistenceANDROID(persistenceHandle));

新对象类型

新枚举常量

XrObjectType 枚举扩展了

  • XR_OBJECT_TYPE_DEVICE_ANCHOR_PERSISTENCE_ANDROID

XrResult 枚举扩展了

  • XR_ERROR_ANCHOR_ID_NOT_FOUND_ANDROID
  • XR_ERROR_ANCHOR_ALREADY_PERSISTED_ANDROID
  • XR_ERROR_ANCHOR_NOT_TRACKING_ANDROID
  • XR_ERROR_PERSISTED_DATA_NOT_READY_ANDROID

XrStructureType 枚举扩展了

  • XR_TYPE_PERSISTED_ANCHOR_ANDROID
  • XR_TYPE_PERSISTED_ANCHOR_SPACE_CREATE_INFO_ANDROID
  • XR_TYPE_PERSISTED_ANCHOR_SPACE_INFO_ANDROID
  • XR_TYPE_DEVICE_ANCHOR_PERSISTENCE_CREATE_INFO_ANDROID

新枚举

新结构体

新函数

问题

版本历史

  • 修订版 1,2024-10-10(Kenny Vercaemer)
    • 初始扩展描述

OpenXR™ 和 OpenXR 徽标是 The Khronos Group Inc. 拥有的商标,并在中国、欧盟、日本和英国注册为商标。