XR_EXT_spatial_plane_tracking

Name String

XR_EXT_spatial_plane_tracking

Erweiterungstyp

Instanzerweiterung

Registrierte Erweiterungsnummer

742

Revision

1

Ratifizierungsstatus

Ratifiziert

Abhängigkeiten von Erweiterungen und Versionen

XR_EXT_spatial_entity

Mitwirkende

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

Übersicht

Diese Erweiterung basiert auf XR_EXT_spatial_entity und definiert die räumliche Funktion zur Ebenenverfolgung für das räumliche Entitätsframework.

Laufzeitunterstützung

Wenn die Laufzeit die Ebenenverfolgung unterstützt, muss sie dies angeben, indem sie XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT in xrEnumerateSpatialCapabilitiesEXT auflistet .

Konfiguration

Die Struktur XrSpatialCapabilityConfigurationPlaneTrackingEXT ist so definiert:

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

Mitgliederbeschreibungen

  • type ist der XrStructureType dieser Struktur.
  • next ist NULL oder ein Zeiger auf die nächste Struktur in einer Strukturkette.
  • capability ist ein XrSpatialCapabilityEXT und muss XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT sein .
  • enabledComponentCount ist ein uint32_t-Wert, der die Anzahl der Elemente im Array enabledComponents beschreibt.
  • enabledComponents ist ein Zeiger auf ein Array von XrSpatialComponentTypeEXT .

Anwendungen können die XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT räumliche Funktion aktivieren, indem sie einen Zeiger auf eine XrSpatialCapabilityConfigurationPlaneTrackingEXT-Struktur in XrSpatialContextCreateInfoEXT :: capabilityConfigs einfügen .

Die Laufzeit muss XR_ERROR_VALIDATION_FAILURE zurückgeben, wenn capability nicht XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT ist .

Gültige Verwendung (implizit)

Garantierte Komponenten

Eine Laufzeit, die XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT muss die folgenden räumlichen Komponenten als garantierte Komponenten aller Entitäten bereitstellen, die von dieser Funktion erkannt werden, und muss sie in xrEnumerateSpatialCapabilityComponentTypesEXT auflisten :

  • XR_SPATIAL_COMPONENT_TYPE_BOUNDED_2D_EXT
  • XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT

Begrenzte 2D-Komponente

Die begrenzte 2D-Komponente gibt den Mittelpunkt und die Ausdehnung der Ebene an, die durch die Entität dargestellt wird, auf der sie sich befindet. Weitere Informationen finden Sie unter Begrenzte 2D-Komponente.

Komponente zur Ebenenausrichtung

Komponentendaten

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;

Die Aufzählung XrSpatialPlaneAlignmentEXT beschreibt die Ausrichtung der Ebene, die mit der räumlichen Entität verknüpft ist, mit einer XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT-Komponente.

Die Aufzählungswerte haben die folgende Bedeutung:

Enum-Beschreibung

XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_UPWARD_EXT

Die Entität ist horizontal und nach oben ausgerichtet (z.B. Boden).

XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_DOWNWARD_EXT

Die Entität ist horizontal und nach unten ausgerichtet (z.B. Decke).

XR_SPATIAL_PLANE_ALIGNMENT_VERTICAL_EXT

Die Entität ist vertikal (z.B. Wand).

XR_SPATIAL_PLANE_ALIGNMENT_ARBITRARY_EXT

Die Entität hat eine beliebige, nicht vertikale und nicht horizontale Ausrichtung.

Struktur der Komponentenliste zum Abfragen von Daten

Die Struktur XrSpatialComponentPlaneAlignmentListEXT ist so definiert:

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

Mitgliederbeschreibungen

  • type ist der XrStructureType dieser Struktur.
  • next ist NULL oder ein Zeiger auf die nächste Struktur in einer Strukturkette.
  • planeAlignmentCount ist ein uint32_t-Wert, der die Anzahl der Elemente im Array planeAlignments beschreibt.
  • planeAlignments ist ein Array von XrSpatialPlaneAlignmentEXT .

Wenn Sie die Komponente zur Ebenenausrichtung der räumlichen Entitäten in einem XrSpatialSnapshotEXT abfragen möchten , fügen Sie XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT in XrSpatialComponentDataQueryConditionEXT :: componentTypes ein und fügen Sie XrSpatialComponentPlaneAlignmentListEXT der Kette XrSpatialComponentDataQueryResultEXT :: next hinzu.

Die Laufzeit muss XR_ERROR_VALIDATION_FAILURE von xrQuerySpatialComponentDataEXT zurückgeben, wenn XrSpatialComponentPlaneAlignmentListEXT in der Kette XrSpatialComponentDataQueryResultEXT :: next enthalten ist, aber XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT nicht in XrSpatialComponentDataQueryConditionEXT :: componentTypes enthalten ist .

Die Laufzeit muss XR_ERROR_SIZE_INSUFFICIENT von xrQuerySpatialComponentDataEXT zurückgeben, wenn planeAlignmentCount kleiner als XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput ist .

Gültige Verwendung (implizit)

Konfiguration

Wenn XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT in XrSpatialCapabilityComponentTypesEXT :: componentTypes für eine Funktion aufgelistet ist, kann eine Anwendung sie aktivieren, indem sie den Enumerator in die Liste XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents der von XrSpatialCapabilityConfigurationBaseHeaderEXT abgeleiteten Struktur der Funktion einfügt, die diese Komponente unterstützt.

Für diese Komponente ist keine spezielle Konfiguration erforderlich, um sie in die Kette XrSpatialCapabilityConfigurationBaseHeaderEXT :: next aufzunehmen.

Optionale Komponenten

Eine Laufzeit, die XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT kann neben den im Abschnitt „Garantierte Komponenten“ aufgeführten Komponenten auch andere räumliche Komponenten unterstützen. Eine Anwendung verwendet xrEnumerateSpatialCapabilityComponentTypesEXT, um die vollständige Liste der von einer Laufzeit unterstützten Komponenten abzurufen, und konfiguriert dann die Komponenten, die für sie von Interesse sind, wenn sie den räumlichen Kontext erstellt.

2D-Mesh-Komponente

Komponentendaten

XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT verwendet die XrSpatialMeshDataEXT Struktur für seine Daten.

Struktur der Komponentenliste zum Abfragen von Daten

Die Struktur XrSpatialComponentMesh2DListEXT ist so definiert:

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

Mitgliederbeschreibungen

  • type ist der XrStructureType dieser Struktur.
  • next ist NULL oder ein Zeiger auf die nächste Struktur in einer Strukturkette.
  • meshCount ist ein uint32_t-Wert, der die Anzahl der Elemente im Array meshes beschreibt.
  • meshes ist ein Array von XrSpatialMeshDataEXT .

Wenn Sie die 2D-Mesh-Komponente der räumlichen Entitäten in einem XrSpatialSnapshotEXT abfragen möchten , fügen Sie XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT in XrSpatialComponentDataQueryConditionEXT :: componentTypes ein und fügen Sie XrSpatialComponentMesh2DListEXT der Kette XrSpatialComponentDataQueryResultEXT :: next hinzu.

Die Laufzeit muss XR_ERROR_VALIDATION_FAILURE von xrQuerySpatialComponentDataEXT zurückgeben, wenn XrSpatialComponentMesh2DListEXT in der Kette XrSpatialComponentDataQueryResultEXT :: next enthalten ist, aber XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT nicht in XrSpatialComponentDataQueryConditionEXT :: componentTypes enthalten ist .

Die Laufzeit muss XR_ERROR_SIZE_INSUFFICIENT von xrQuerySpatialComponentDataEXT zurückgeben, wenn meshCount kleiner als XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput ist .

Für die XrSpatialMeshDataEXT, die von der Laufzeit im meshes Array ausgefüllt wird, muss XrSpatialBufferEXT :: bufferType für XrSpatialMeshDataEXT :: vertexBuffer XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT und XrSpatialBufferEXT :: bufferType für XrSpatialMeshDataEXT :: indexBuffer muss XR_SPATIAL_BUFFER_TYPE_UINT16_EXT sein .

Gültige Verwendung (implizit)

Konfiguration

Wenn XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT in XrSpatialCapabilityComponentTypesEXT :: componentTypes für eine Funktion aufgelistet ist, kann eine Anwendung sie aktivieren, indem sie den Enumerator in die Liste XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents der von XrSpatialCapabilityConfigurationBaseHeaderEXT abgeleiteten Struktur der Funktion einfügt, die diese Komponente unterstützt.

Für diese Komponente ist keine spezielle Konfiguration erforderlich, um sie in die Kette XrSpatialCapabilityConfigurationBaseHeaderEXT :: next aufzunehmen.

2D-Polygon-Komponente

Komponentendaten

Die Struktur XrSpatialPolygon2DDataEXT ist so definiert:

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

Mitgliederbeschreibungen

  • origin ist ein XrPosef, das den Ursprung des Polygons definiert. Alle Eckpunkte des Polygons sind relativ zu diesem Ursprung in der X-Y-Ebene.
  • vertexBuffer ist ein XrSpatialBufferEXT, das die ID für einen Puffer vom Typ XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT bereitstellt und den Eckpunktpuffer der Entität darstellt, auf der sich diese Komponente befindet. Die Eckpunkte müssen in entgegengesetzter Richtung zum Uhrzeigersinn zurückgegeben werden. Das durch diese Eckpunkte dargestellte Polygon darf sich nicht selbst schneiden und kann konkav sein.

XrSpatialBufferEXT :: bufferType für vertexBuffer muss sein XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT .

Gültige Verwendung (implizit)

Struktur der Komponentenliste zum Abfragen von Daten

Die Struktur XrSpatialComponentPolygon2DListEXT ist so definiert:

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

Mitgliederbeschreibungen

  • type ist der XrStructureType dieser Struktur.
  • next ist NULL oder ein Zeiger auf die nächste Struktur in einer Strukturkette.
  • polygonCount ist ein uint32_t-Wert, der die Anzahl der Elemente im Array polygons beschreibt.
  • polygons ist ein Array von XrSpatialPolygon2DDataEXT .

Wenn Sie die 2D-Polygon-Komponente der räumlichen Entitäten in einem XrSpatialSnapshotEXT abfragen möchten , fügen Sie XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT in XrSpatialComponentDataQueryConditionEXT :: componentTypes ein und fügen Sie XrSpatialComponentPolygon2DListEXT der Kette XrSpatialComponentDataQueryResultEXT :: next hinzu.

Die Laufzeit muss XR_ERROR_VALIDATION_FAILURE von xrQuerySpatialComponentDataEXT zurückgeben, wenn XrSpatialComponentPolygon2DListEXT in der Kette XrSpatialComponentDataQueryResultEXT :: next enthalten ist, aber XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT nicht in XrSpatialComponentDataQueryConditionEXT :: componentTypes enthalten ist .

Die Laufzeit muss XR_ERROR_SIZE_INSUFFICIENT von xrQuerySpatialComponentDataEXT zurückgeben, wenn polygonCount kleiner als XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput ist .

Gültige Verwendung (implizit)

Konfiguration

Wenn XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT in XrSpatialCapabilityComponentTypesEXT :: componentTypes für eine Funktion aufgelistet ist, kann eine Anwendung sie aktivieren, indem sie den Enumerator in die Liste XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents der von XrSpatialCapabilityConfigurationBaseHeaderEXT abgeleiteten Struktur der Funktion einfügt, die diese Komponente unterstützt.

Für diese Komponente ist keine spezielle Konfiguration erforderlich, um sie in die Kette XrSpatialCapabilityConfigurationBaseHeaderEXT :: next aufzunehmen.

Semantisches Ebenenlabel

Komponentendaten

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;

Die Aufzählung XrSpatialPlaneSemanticLabelEXT beschreibt eine Reihe semantischer Labels für Ebenen.

Enum-Beschreibung

XR_SPATIAL_PLANE_SEMANTIC_LABEL_UNCATEGORIZED_EXT

Die Laufzeit konnte diese Entität nicht klassifizieren.

XR_SPATIAL_PLANE_SEMANTIC_LABEL_FLOOR_EXT

Die Entität ist ein Boden.

XR_SPATIAL_PLANE_SEMANTIC_LABEL_WALL_EXT

Die Entität ist eine Wand.

XR_SPATIAL_PLANE_SEMANTIC_LABEL_CEILING_EXT

Die Entität ist eine Decke.

XR_SPATIAL_PLANE_SEMANTIC_LABEL_TABLE_EXT

Die Entität ist ein Tisch.

Struktur der Komponentenliste zum Abfragen von Daten

Die Struktur XrSpatialComponentPlaneSemanticLabelListEXT ist so definiert:

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

Mitgliederbeschreibungen

  • type ist der XrStructureType dieser Struktur.
  • next ist NULL oder ein Zeiger auf die nächste Struktur in einer Strukturkette.
  • semanticLabelCount ist ein uint32_t-Wert, der die Anzahl der Elemente im Array semanticLabels beschreibt.
  • semanticLabels ist ein Array von XrSpatialPlaneSemanticLabelEXT .

Wenn Sie die Komponente für das semantische Ebenenlabel der räumlichen Entitäten in einem XrSpatialSnapshotEXT abfragen möchten , fügen Sie XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT in XrSpatialComponentDataQueryConditionEXT :: componentTypes ein und fügen Sie XrSpatialComponentPlaneSemanticLabelListEXT der Kette XrSpatialComponentDataQueryResultEXT :: next hinzu.

Die Laufzeit muss XR_ERROR_VALIDATION_FAILURE von xrQuerySpatialComponentDataEXT zurückgeben, wenn XrSpatialComponentPlaneSemanticLabelListEXT in der Kette XrSpatialComponentDataQueryResultEXT :: next enthalten ist, aber XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT nicht in XrSpatialComponentDataQueryConditionEXT :: componentTypes enthalten ist .

Die Laufzeit muss XR_ERROR_SIZE_INSUFFICIENT von xrQuerySpatialComponentDataEXT zurückgeben, wenn semanticLabelCount kleiner als XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput ist .

Gültige Verwendung (implizit)

Konfiguration

Wenn XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT in XrSpatialCapabilityComponentTypesEXT :: componentTypes für eine Funktion aufgelistet ist, kann eine Anwendung sie aktivieren, indem sie den Enumerator in die Liste XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents der von XrSpatialCapabilityConfigurationBaseHeaderEXT abgeleiteten Struktur der Funktion einfügt, die diese Komponente unterstützt.

Für diese Komponente ist keine spezielle Konfiguration erforderlich, um sie in die Kette XrSpatialCapabilityConfigurationBaseHeaderEXT :: next aufzunehmen.

Beispiel-Code

Funktion zur Ebenenverfolgung konfigurieren

Der folgende Beispielcode zeigt, wie Sie die Funktion zur Ebenenverfolgung konfigurieren, wenn Sie einen räumlichen Kontext erstellen.

// 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));

Räumliche Entitäten erkennen und Komponentendaten abfragen

Der folgende Beispielcode zeigt, wie Sie räumliche Entitäten für einen Kontext erkennen, der mit XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT konfiguriert wurde, und die zugehörigen Komponentendaten abfragen.

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
  // ...
}

Neue Strukturen

Neue Enums

Neue Enum-Konstanten

  • XR_EXT_SPATIAL_PLANE_TRACKING_EXTENSION_NAME
  • XR_EXT_spatial_plane_tracking_SPEC_VERSION
  • Erweiterung von XrSpatialCapabilityEXT :

    • XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT
  • Erweiterung von 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
  • Erweiterung von 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

Probleme

Versionsverlauf

  • Revision 1, 02.07.2024 (Nihav Jain, Google)

    • Erste Beschreibung der Erweiterung