XR_EXT_spatial_plane_tracking

名称字符串

XR_EXT_spatial_plane_tracking

扩展类型

实例扩展程序

已注册的扩展程序编号

742

修订版本

1

批准状态

批准日期

扩展程序和版本依赖项

XR_EXT_spatial_entity

创作贡献者

Nihav Jain,Google
Natalie Fleury,Meta
Yuichi Taguchi,Meta
Ron Bessems,Meta
Yin Li,Microsoft
Jimmy Alamparambil,ByteDance
Zhipeng Liu,ByteDance
Jun Yan,ByteDance

概览

此扩展程序基于 XR_EXT_spatial_entity 构建,并为空间实体框架定义了平面跟踪空间功能。

运行时支持

如果运行时支持平面跟踪,则必须通过在 xrEnumerateSpatialCapabilitiesEXT 中枚举 XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT 来指明这一点。

配置

XrSpatialCapabilityConfigurationPlaneTrackingEXT 结构的定义如下:

typedef struct XrSpatialCapabilityConfigurationPlaneTrackingEXT {
    XrStructureType                     type;
    const void*                         next;
    XrSpatialCapabilityEXT              capability;
    uint32_t                            enabledComponentCount;
    const XrSpatialComponentTypeEXT*    enabledComponents;
} XrSpatialCapabilityConfigurationPlaneTrackingEXT;

成员说明

  • type 是相应结构的 XrStructureType
  • nextNULL 或指向结构链中下一个结构的指针。
  • capability 是一个 XrSpatialCapabilityEXT必须XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT
  • enabledComponentCount 是一个 uint32_t,用于描述 enabledComponents 数组中的元素数量。
  • enabledComponents 是指向 XrSpatialComponentTypeEXT 数组的指针。

应用可以通过在 XrSpatialContextCreateInfoEXT :: capabilityConfigs 中添加指向 XrSpatialCapabilityConfigurationPlaneTrackingEXT 结构的指针来启用 XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT 空间功能。

如果 capability 不为 XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT,则运行时必须返回 XR_ERROR_VALIDATION_FAILURE

有效使用情况(隐式)

保证组件

支持 XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT 必须提供以下空间组件,作为此功能发现的所有实体的保证组件,并且必须xrEnumerateSpatialCapabilityComponentTypesEXT 中枚举这些组件:

  • XR_SPATIAL_COMPONENT_TYPE_BOUNDED_2D_EXT
  • XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT

有界限的 2D 组件

有界 2D 组件提供其所在平面的中心和范围。如需了解详情,请参阅有界 2D

平面对齐组件

组件数据

typedef enum XrSpatialPlaneAlignmentEXT {
    XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_UPWARD_EXT = 0,
    XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_DOWNWARD_EXT = 1,
    XR_SPATIAL_PLANE_ALIGNMENT_VERTICAL_EXT = 2,
    XR_SPATIAL_PLANE_ALIGNMENT_ARBITRARY_EXT = 3,
    XR_SPATIAL_PLANE_ALIGNMENT_MAX_ENUM_EXT = 0x7FFFFFFF
} XrSpatialPlaneAlignmentEXT;

XrSpatialPlaneAlignmentEXT 枚举描述了与具有 XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT 组件的空间实体关联的平面的对齐方式。

枚举值具有以下含义:

枚举说明

XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_UPWARD_EXT

实体是水平的,并朝上(例如地面)。

XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_DOWNWARD_EXT

实体是水平的,朝下(例如天花板)。

XR_SPATIAL_PLANE_ALIGNMENT_VERTICAL_EXT

实体是垂直的(例如墙壁)。

XR_SPATIAL_PLANE_ALIGNMENT_ARBITRARY_EXT

实体具有任意的非垂直和非水平方向。

用于查询数据的组件列表结构

XrSpatialComponentPlaneAlignmentListEXT 结构的定义如下:

typedef struct XrSpatialComponentPlaneAlignmentListEXT {
    XrStructureType                type;
    void*                          next;
    uint32_t                       planeAlignmentCount;
    XrSpatialPlaneAlignmentEXT*    planeAlignments;
} XrSpatialComponentPlaneAlignmentListEXT;

成员说明

  • type 是相应结构的 XrStructureType
  • nextNULL 或指向结构链中下一个结构的指针。
  • planeAlignmentCount 是一个 uint32_t,用于描述 planeAlignments 数组中的元素数量。
  • planeAlignments 是一个 XrSpatialPlaneAlignmentEXT 数组。

如需查询 XrSpatialSnapshotEXT 中空间实体的平面对齐组件,请在 XrSpatialComponentDataQueryConditionEXT :: componentTypes 中添加 XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT,并将 XrSpatialComponentPlaneAlignmentListEXT 添加到 XrSpatialComponentDataQueryResultEXT :: next 链中。

如果 XrSpatialComponentPlaneAlignmentListEXT 位于 XrSpatialComponentDataQueryResultEXT :: next 链中,但 XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT 未包含在 XrSpatialComponentDataQueryConditionEXT :: componentTypes 中,运行时必须xrQuerySpatialComponentDataEXT 返回 XR_ERROR_VALIDATION_FAILURE

如果 planeAlignmentCount 小于 XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput,运行时必须xrQuerySpatialComponentDataEXT 返回 XR_ERROR_SIZE_INSUFFICIENT

有效使用情况(隐式)

配置

如果 XrSpatialCapabilityComponentTypesEXT :: componentTypes 中针对某个功能枚举了 XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT,则应用可以通过在支持相应组件的功能的 XrSpatialCapabilityConfigurationBaseHeaderEXT 派生结构的 XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents 列表中包含该枚举常量来启用该功能。

此组件不需要任何特殊配置即可包含在 XrSpatialCapabilityConfigurationBaseHeaderEXT :: next 链中。

可选组件

支持 XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT 的运行时可能支持除保证的组件部分中列出的组件之外的其他空间组件。应用使用 xrEnumerateSpatialCapabilityComponentTypesEXT 获取运行时支持的组件的完整列表,然后在创建空间上下文时配置感兴趣的组件。

网格 2D 组件

组件数据

XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT 使用 XrSpatialMeshDataEXT 结构来存储其数据。

用于查询数据的组件列表结构

XrSpatialComponentMesh2DListEXT 结构的定义如下:

typedef struct XrSpatialComponentMesh2DListEXT {
    XrStructureType          type;
    void*                    next;
    uint32_t                 meshCount;
    XrSpatialMeshDataEXT*    meshes;
} XrSpatialComponentMesh2DListEXT;

成员说明

  • type 是相应结构的 XrStructureType
  • nextNULL 或指向结构链中下一个结构的指针。
  • meshCount 是一个 uint32_t,用于描述 meshes 数组中的元素数量。
  • meshes 是一个 XrSpatialMeshDataEXT 数组。

如需查询 XrSpatialSnapshotEXT 中空间实体的网格 2D 组件,请在 XrSpatialComponentDataQueryConditionEXT :: componentTypes 中包含 XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT,并将 XrSpatialComponentMesh2DListEXT 添加到 XrSpatialComponentDataQueryResultEXT :: next 链中。

如果 XrSpatialComponentMesh2DListEXT 位于 XrSpatialComponentDataQueryResultEXTnext 链中,但 XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT 未包含在 XrSpatialComponentDataQueryConditionEXTcomponentTypes 中,运行时必须xrQuerySpatialComponentDataEXT 返回 XR_ERROR_VALIDATION_FAILURE

如果 meshCount 小于 XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput,运行时必须xrQuerySpatialComponentDataEXT 返回 XR_ERROR_SIZE_INSUFFICIENT

对于运行时在 meshes 数组中填充的 XrSpatialMeshDataEXTXrSpatialMeshDataEXT :: vertexBufferXrSpatialBufferEXT :: bufferType 必须XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT,而 XrSpatialMeshDataEXT :: indexBufferXrSpatialBufferEXT :: bufferType 必须XR_SPATIAL_BUFFER_TYPE_UINT16_EXT

有效使用情况(隐式)

配置

如果 XrSpatialCapabilityComponentTypesEXT :: componentTypes 中针对某个功能枚举了 XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT,则应用可以通过在支持相应组件的功能的 XrSpatialCapabilityConfigurationBaseHeaderEXT 派生结构的 XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents 列表中包含该枚举常量来启用该功能。

此组件不需要任何特殊配置即可包含在 XrSpatialCapabilityConfigurationBaseHeaderEXT :: next 链中。

多边形 2D 组件

组件数据

XrSpatialPolygon2DDataEXT 结构的定义如下:

typedef struct XrSpatialPolygon2DDataEXT {
    XrPosef               origin;
    XrSpatialBufferEXT    vertexBuffer;
} XrSpatialPolygon2DDataEXT;

成员说明

  • origin 是一个 XrPosef,用于定义多边形的起点。多边形的所有顶点都相对于 X-Y 平面中的此原点。
  • vertexBuffer 是一个 XrSpatialBufferEXT,用于提供类型为 XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT 的缓冲区的 ID,并表示相应组件所在实体的顶点缓冲区。顶点必须按逆时针顺序返回。这些顶点所表示的多边形不得自相交,可以是凹形的。

XrSpatialBufferEXT :: bufferType 对于 vertexBuffer 必须XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT

有效使用情况(隐式)

用于查询数据的组件列表结构

XrSpatialComponentPolygon2DListEXT 结构的定义如下:

typedef struct XrSpatialComponentPolygon2DListEXT {
    XrStructureType               type;
    void*                         next;
    uint32_t                      polygonCount;
    XrSpatialPolygon2DDataEXT*    polygons;
} XrSpatialComponentPolygon2DListEXT;

成员说明

  • type 是相应结构的 XrStructureType
  • nextNULL 或指向结构链中下一个结构的指针。
  • polygonCount 是一个 uint32_t,用于描述 polygons 数组中的元素数量。
  • polygonsXrSpatialPolygon2DDataEXT 的数组。

如需查询 XrSpatialSnapshotEXT 中空间实体的多边形 2D 组件,请在 XrSpatialComponentDataQueryConditionEXT :: componentTypes 中包含 XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT,并将 XrSpatialComponentPolygon2DListEXT 添加到 XrSpatialComponentDataQueryResultEXT :: next 链中。

如果 XrSpatialComponentPolygon2DListEXT 位于 XrSpatialComponentDataQueryResultEXTnext 链中,但 XrSpatialComponentDataQueryConditionEXTcomponentTypes 中不包含 XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT,则运行时必须xrQuerySpatialComponentDataEXT 返回 XR_ERROR_VALIDATION_FAILURE

如果 polygonCount 小于 XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput,运行时必须xrQuerySpatialComponentDataEXT 返回 XR_ERROR_SIZE_INSUFFICIENT

有效使用情况(隐式)

配置

如果 XrSpatialCapabilityComponentTypesEXT :: componentTypes 中针对某个功能枚举了 XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT,则应用可以通过在支持相应组件的功能的 XrSpatialCapabilityConfigurationBaseHeaderEXT 派生结构的 XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents 列表中包含该枚举常量来启用该功能。

此组件不需要任何特殊配置即可包含在 XrSpatialCapabilityConfigurationBaseHeaderEXT :: next 链中。

“飞机”语义标签

组件数据

typedef enum XrSpatialPlaneSemanticLabelEXT {
    XR_SPATIAL_PLANE_SEMANTIC_LABEL_UNCATEGORIZED_EXT = 1,
    XR_SPATIAL_PLANE_SEMANTIC_LABEL_FLOOR_EXT = 2,
    XR_SPATIAL_PLANE_SEMANTIC_LABEL_WALL_EXT = 3,
    XR_SPATIAL_PLANE_SEMANTIC_LABEL_CEILING_EXT = 4,
    XR_SPATIAL_PLANE_SEMANTIC_LABEL_TABLE_EXT = 5,
    XR_SPATIAL_PLANE_SEMANTIC_LABEL_MAX_ENUM_EXT = 0x7FFFFFFF
} XrSpatialPlaneSemanticLabelEXT;

XrSpatialPlaneSemanticLabelEXT 枚举描述了一组平面的语义标签。

枚举说明

XR_SPATIAL_PLANE_SEMANTIC_LABEL_UNCATEGORIZED_EXT

运行时无法对相应实体进行分类。

XR_SPATIAL_PLANE_SEMANTIC_LABEL_FLOOR_EXT

实体是地面。

XR_SPATIAL_PLANE_SEMANTIC_LABEL_WALL_EXT

实体是一面墙。

XR_SPATIAL_PLANE_SEMANTIC_LABEL_CEILING_EXT

实体是天花板。

XR_SPATIAL_PLANE_SEMANTIC_LABEL_TABLE_EXT

实体是表格。

用于查询数据的组件列表结构

XrSpatialComponentPlaneSemanticLabelListEXT 结构的定义如下:

typedef struct XrSpatialComponentPlaneSemanticLabelListEXT {
    XrStructureType                    type;
    void*                              next;
    uint32_t                           semanticLabelCount;
    XrSpatialPlaneSemanticLabelEXT*    semanticLabels;
} XrSpatialComponentPlaneSemanticLabelListEXT;

成员说明

  • type 是相应结构的 XrStructureType
  • nextNULL 或指向结构链中下一个结构的指针。
  • semanticLabelCount 是一个 uint32_t,用于描述 semanticLabels 数组中的元素数量。
  • semanticLabels 是一个 XrSpatialPlaneSemanticLabelEXT 数组。

如需查询 XrSpatialSnapshotEXT 中空间实体的平面语义标签组件,请在 XrSpatialComponentDataQueryConditionEXT :: componentTypes 中包含 XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT,并将 XrSpatialComponentPlaneSemanticLabelListEXT 添加到 XrSpatialComponentDataQueryResultEXT :: next 链中。

如果 XrSpatialComponentPlaneSemanticLabelListEXT 位于 XrSpatialComponentDataQueryResultEXT 的下一个链中,但 XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT 未包含在 XrSpatialComponentDataQueryConditionEXTcomponentTypes 中,则运行时必须xrQuerySpatialComponentDataEXT 返回 XR_ERROR_VALIDATION_FAILUREnext

如果 semanticLabelCount 小于 XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput,运行时必须xrQuerySpatialComponentDataEXT 返回 XR_ERROR_SIZE_INSUFFICIENT

有效使用情况(隐式)

配置

如果 XrSpatialCapabilityComponentTypesEXT :: componentTypes 中针对某个功能枚举了 XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT,则应用可以通过在支持相应组件的功能的 XrSpatialCapabilityConfigurationBaseHeaderEXT 派生结构的 XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents 列表中包含该枚举常量来启用该功能。

此组件不需要任何特殊配置即可包含在 XrSpatialCapabilityConfigurationBaseHeaderEXT :: next 链中。

示例代码

配置平面跟踪功能

以下示例代码演示了如何在创建空间情境时配置平面跟踪功能。

// Check if plane tracking capability is supported
uint32_t capabilityCount;
CHK_XR(xrEnumerateSpatialCapabilitiesEXT(instance, systemId, 0, &capabilityCount, nullptr));
std::vector<XrSpatialCapabilityEXT> capabilities(capabilityCount);
CHK_XR(xrEnumerateSpatialCapabilitiesEXT(instance, systemId, capabilityCount, &capabilityCount, capabilities.data()));

if (std::find(capabilities.begin(), capabilities.end(), XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT) == capabilities.end()) {
  return;
}

// Enumerate supported components for plane tracking capability
XrSpatialCapabilityComponentTypesEXT planeComponents{XR_TYPE_SPATIAL_CAPABILITY_COMPONENT_TYPES_EXT};
CHK_XR(xrEnumerateSpatialCapabilityComponentTypesEXT(instance, systemId, XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT, &planeComponents));
std::vector<XrSpatialComponentTypeEXT> planeCapabilityComponents(planeComponents.componentTypeCountOutput);
planeComponents.componentTypeCapacityInput = planeCapabilityComponents.size();
planeComponents.componentTypes = planeCapabilityComponents.data();
CHK_XR(xrEnumerateSpatialCapabilityComponentTypesEXT(instance, systemId, XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT, &planeComponents));

// Check if polygon 2D and plane semantic labels optional components are supported
const auto supportsComponent = [&planeCapabilityComponents](XrSpatialComponentTypeEXT component) {
  return std::find(planeCapabilityComponents.begin(), planeCapabilityComponents.end(), component) != planeCapabilityComponents.end();
};

const bool supportsPolygon2DComponent = supportsComponent(XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT);
const bool supportsSemanticLabelComponent = supportsComponent(XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT);

// Create a spatial context
XrSpatialContextEXT spatialContext{};

// Enable the 2 guaranteed components of the plane tracking capability
std::vector<XrSpatialComponentTypeEXT> enabledComponents = {
  XR_SPATIAL_COMPONENT_TYPE_BOUNDED_2D_EXT,
  XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT,
};
// Optionally enable polygon2D if it is supported
if (supportsPolygon2DComponent) {
  enabledComponents.push_back(XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT);
}
// Optionally enable semantic labels if it is supported
if (supportsSemanticLabelComponent) {
  enabledComponents.push_back(XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT);
}

XrSpatialCapabilityConfigurationPlaneTrackingEXT planeConfig{XR_TYPE_SPATIAL_CAPABILITY_CONFIGURATION_PLANE_TRACKING_EXT};
planeConfig.capability = XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT;
planeConfig.enabledComponentCount = enabledComponents.size();
planeConfig.enabledComponents = enabledComponents.data();

std::array<XrSpatialCapabilityConfigurationBaseHeaderEXT*, 1> capabilityConfigs = {
  reinterpret_cast<XrSpatialCapabilityConfigurationBaseHeaderEXT*>(&planeConfig),
};

XrSpatialContextCreateInfoEXT spatialContextCreateInfo{XR_TYPE_SPATIAL_CONTEXT_CREATE_INFO_EXT};
spatialContextCreateInfo.capabilityConfigCount = capabilityConfigs.size();
spatialContextCreateInfo.capabilityConfigs = capabilityConfigs.data();
XrFutureEXT createContextFuture;
CHK_XR(xrCreateSpatialContextAsyncEXT(session, &spatialContextCreateInfo, &createContextFuture));

waitUntilReady(createContextFuture);

XrCreateSpatialContextCompletionEXT completion{XR_TYPE_CREATE_SPATIAL_CONTEXT_COMPLETION_EXT};
CHK_XR(xrCreateSpatialContextCompleteEXT(session, createContextFuture, &completion));
if (completion.futureResult != XR_SUCCESS) {
  return;
}

spatialContext = completion.spatialContext;

// ...
// Discover entities with the spatial context
// ...

CHK_XR(xrDestroySpatialContextEXT(spatialContext));

发现空间实体和查询组件数据

以下示例代码演示了如何发现配置了 XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT 的上下文的空间实体,并查询其组件数据。

XrFutureEXT future = XR_NULL_FUTURE_EXT;

// We want to look for entities that have the following components.
std::vector<XrSpatialComponentTypeEXT> snapshotComponents = {
  XR_SPATIAL_COMPONENT_TYPE_BOUNDED_2D_EXT,
  XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT,
};
if (supportsPolygon2DComponent) {
  snapshotComponents.push_back(XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT);
}
if (supportsSemanticLabelComponent) {
  snapshotComponents.push_back(XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT);
}

auto discoverSpatialEntities = [&](XrSpatialContextEXT spatialContext, XrTime time) {
  XrSpatialDiscoverySnapshotCreateInfoEXT snapshotCreateInfo{XR_TYPE_SPATIAL_DISCOVERY_SNAPSHOT_CREATE_INFO_EXT};
  snapshotCreateInfo.componentTypeCount = snapshotComponents.size();
  snapshotCreateInfo.componentTypes = snapshotComponents.data();
  CHK_XR(xrCreateSpatialDiscoverySnapshotAsyncEXT(spatialContext, &snapshotCreateInfo, &future));

  waitUntilReady(future);

  XrCreateSpatialDiscoverySnapshotCompletionInfoEXT completionInfo{XR_TYPE_CREATE_SPATIAL_DISCOVERY_SNAPSHOT_COMPLETION_INFO_EXT};
  completionInfo.baseSpace = localSpace;
  completionInfo.time = time;
  completionInfo.future = future;

  XrCreateSpatialDiscoverySnapshotCompletionEXT completion{XR_TYPE_CREATE_SPATIAL_DISCOVERY_SNAPSHOT_COMPLETION_EXT};
  CHK_XR(xrCreateSpatialDiscoverySnapshotCompleteEXT(spatialContext, &completionInfo, &completion));
  if (completion.futureResult == XR_SUCCESS) {

    // Query for the semantic label component data
    XrSpatialComponentDataQueryConditionEXT queryCond{XR_TYPE_SPATIAL_COMPONENT_DATA_QUERY_CONDITION_EXT};
    queryCond.componentTypeCount = snapshotComponents.size();
    queryCond.componentTypes = snapshotComponents.data();

    XrSpatialComponentDataQueryResultEXT queryResult{XR_TYPE_SPATIAL_COMPONENT_DATA_QUERY_RESULT_EXT};
    CHK_XR(xrQuerySpatialComponentDataEXT(completion.snapshot, &queryCond, &queryResult));

    std::vector<XrSpatialEntityIdEXT> entityIds(queryResult.entityIdCountOutput);
    std::vector<XrSpatialEntityTrackingStateEXT> entityStates(queryResult.entityIdCountOutput);
    queryResult.entityIdCapacityInput = entityIds.size();
    queryResult.entityIds = entityIds.data();
    queryResult.entityStateCapacityInput = entityStates.size();
    queryResult.entityStates = entityStates.data();

    std::vector<XrSpatialBounded2DDataEXT> bounded2D(queryResult.entityIdCountOutput);
    XrSpatialComponentBounded2DListEXT bounded2DList{XR_TYPE_SPATIAL_COMPONENT_BOUNDED_2D_LIST_EXT};
    bounded2DList.boundCount = bounded2D.size();
    bounded2DList.bounds = bounded2D.data();
    queryResult.next = &bounded2DList;

    std::vector<XrSpatialPolygon2DDataEXT> polygons;
    XrSpatialComponentPolygon2DListEXT polygonList{XR_TYPE_SPATIAL_COMPONENT_POLYGON_2D_LIST_EXT};
    if (supportsPolygon2DComponent) {
      polygons.resize(queryResult.entityIdCountOutput);
      polygonList.polygonCount = polygons.size();
      polygonList.polygons = polygons.data();
      polygonList.next = queryResult.next;
      queryResult.next = &polygonList;
    }

    std::vector<XrSpatialPlaneSemanticLabelEXT> semanticLabels;
    XrSpatialComponentPlaneSemanticLabelListEXT semanticLabelsList{XR_TYPE_SPATIAL_COMPONENT_PLANE_SEMANTIC_LABEL_LIST_EXT};
    if (supportsSemanticLabelComponent) {
      semanticLabels.resize(queryResult.entityIdCountOutput);
      semanticLabelsList.semanticLabelCount = semanticLabels.size();
      semanticLabelsList.semanticLabels = semanticLabels.data();
      semanticLabelsList.next = queryResult.next;
      queryResult.next = &semanticLabelsList;
    }

    CHK_XR(xrQuerySpatialComponentDataEXT(completion.snapshot, &queryCond, &queryResult));

    for (int32_t i = 0; i < queryResult.entityIdCountOutput; ++i) {
      if (entityStates[i] != XR_SPATIAL_ENTITY_TRACKING_STATE_TRACKING_EXT) {
        continue;
      }

      // 2D bounds for entity entityIds[i] is bounded2D[i].extents centered on bounded2D[i].center.

      if (supportsPolygon2DComponent) {
        // 2D polygon for entity entityIds[i] is the buffer represented by polygons[i].bufferId.
        // Application uses flink:xrGetSpatialBufferVector2fEXT to get the buffer data.
      }

      if (supportsSemanticLabelComponent) {
        // semantic label for entity entityIds[i] is semanticLabels[i].
      }
    }

    CHK_XR(xrDestroySpatialSnapshotEXT(completion.snapshot));
  }
};

while (1) {
  // ...
  // For every frame in frame loop
  // ...

  XrFrameState frameState;  // previously returned from xrWaitFrame
  const XrTime time = frameState.predictedDisplayTime;

  // Poll for the XR_TYPE_EVENT_DATA_SPATIAL_DISCOVERY_RECOMMENDED_EXT event
  XrEventDataBuffer event = {XR_TYPE_EVENT_DATA_BUFFER};
  XrResult result = xrPollEvent(instance, &event);
  if (result == XR_SUCCESS) {
      switch (event.type) {
          case XR_TYPE_EVENT_DATA_SPATIAL_DISCOVERY_RECOMMENDED_EXT: {
              const XrEventDataSpatialDiscoveryRecommendedEXT& eventdata =
                  *reinterpret_cast<XrEventDataSpatialDiscoveryRecommendedEXT*>(&event);
              // Discover spatial entities for the context that we received the "discovery
              // recommended" event for.
              discoverSpatialEntities(eventdata.spatialContext, time);
              break;
          }
      }
  }

  // ...
  // Finish frame loop
  // ...
}

新结构

新枚举

新的枚举常量

  • XR_EXT_SPATIAL_PLANE_TRACKING_EXTENSION_NAME
  • XR_EXT_spatial_plane_tracking_SPEC_VERSION
  • 扩展 XrSpatialCapabilityEXT

    • XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT
  • 扩展 XrSpatialComponentTypeEXT

    • XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT
    • XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT
    • XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT
    • XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT
  • 扩展 XrStructureType

    • XR_TYPE_SPATIAL_CAPABILITY_CONFIGURATION_PLANE_TRACKING_EXT
    • XR_TYPE_SPATIAL_COMPONENT_MESH_2D_LIST_EXT
    • XR_TYPE_SPATIAL_COMPONENT_PLANE_ALIGNMENT_LIST_EXT
    • XR_TYPE_SPATIAL_COMPONENT_PLANE_SEMANTIC_LABEL_LIST_EXT
    • XR_TYPE_SPATIAL_COMPONENT_POLYGON_2D_LIST_EXT

问题

版本历史记录

  • 修订版本 1,2024 年 7 月 2 日(Nihav Jain,Google)

    • 初始扩展程序说明