XR_EXT_spatial_plane_tracking

Name String

XR_EXT_spatial_plane_tracking

Erweiterungstyp

Instanzerweiterung

Registrierte Durchwahl

742

Revision

1

Ratification Status

Ratified

Erweiterungs- und Versionsabhängigkeiten

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 baut auf XR_EXT_spatial_entity auf und definiert die räumliche Funktion für das Ebenen-Tracking für das Spatial Entity Framework.

Laufzeitunterstützung

Wenn die Laufzeit das Plane Tracking unterstützt, muss sie dies durch Aufzählen von XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT in xrEnumerateSpatialCapabilitiesEXT angeben.

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, der die Anzahl der Elemente im Array enabledComponents beschreibt.
  • enabledComponents ist ein Zeiger auf ein Array von XrSpatialComponentTypeEXT .

Anwendungen können die räumliche Funktion XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT 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 unterstützt, muss die folgenden räumlichen Komponenten als garantierte Komponenten aller Entitäten bereitstellen, die von dieser Funktion erkannt werden, und sie 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 liefert den Mittelpunkt und die Ausdehnung der Ebene, die durch die Entität dargestellt wird, auf der sie sich befindet. Weitere Informationen finden Sie unter Begrenztes 2D.

Komponente zur Ausrichtung von Ebenen

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 der räumlichen Entität mit einer XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT-Komponente zugeordnet ist.

Die Aufzählungswerte haben die folgenden Bedeutungen:

Enum-Beschreibung

XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_UPWARD_EXT

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

XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_DOWNWARD_EXT

Das Element ist horizontal und nach unten gerichtet (z.B. Decke).

XR_SPATIAL_PLANE_ALIGNMENT_VERTICAL_EXT

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

XR_SPATIAL_PLANE_ALIGNMENT_ARBITRARY_EXT

Das Element hat eine beliebige, nicht vertikale und nicht horizontale Ausrichtung.

Komponentenlistenstruktur 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, der die Anzahl der Elemente im Array planeAlignments beschreibt.
  • planeAlignments ist ein Array von XrSpatialPlaneAlignmentEXT .

Wenn Sie die Komponente für die Ausrichtung der Ebene 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 zur Kette XrSpatialComponentDataQueryResultEXT :: next hinzu.

Die Laufzeit muss XR_ERROR_VALIDATION_FAILURE von xrQuerySpatialComponentDataEXT zurückgeben, wenn XrSpatialComponentPlaneAlignmentListEXT in der XrSpatialComponentDataQueryResultEXT :: next-Kette 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 bestimmte Funktion aufgeführt ist, kann eine Anwendung sie aktivieren, indem sie den Enumeranten in die Liste XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents der abgeleiteten Struktur XrSpatialCapabilityConfigurationBaseHeaderEXT der Funktion aufnimmt, die diese Komponente unterstützt.

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

Optionale Komponenten

Eine Laufzeit, die XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT unterstützt, kann zusätzlich zu 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 Komponenten abzurufen, die von einer Laufzeit unterstützt werden. Anschließend werden die gewünschten Komponenten beim Erstellen des räumlichen Kontexts konfiguriert.

Mesh-2D-Komponente

Komponentendaten

XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT verwendet die Struktur XrSpatialMeshDataEXT für seine Daten.

Komponentenlistenstruktur 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, 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 zur Kette XrSpatialComponentDataQueryResultEXT :: next hinzu.

Die Laufzeit muss XR_ERROR_VALIDATION_FAILURE von xrQuerySpatialComponentDataEXT zurückgeben, wenn XrSpatialComponentMesh2DListEXT in der XrSpatialComponentDataQueryResultEXT :: next-Kette 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 werden, muss XrSpatialBufferEXT :: bufferType für XrSpatialMeshDataEXT :: vertexBuffer XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT sein 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 bestimmte Funktion aufgeführt ist, kann eine Anwendung sie aktivieren, indem sie den Enumeranten in die Liste XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents der abgeleiteten Struktur XrSpatialCapabilityConfigurationBaseHeaderEXT der Funktion aufnimmt, die diese Komponente unterstützt.

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

Polygon-2D-Komponente

Komponentendaten

Die Struktur XrSpatialPolygon2DDataEXT ist so definiert:

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

Mitgliederbeschreibungen

  • origin ist ein XrPosef, der den Ursprung des Polygons definiert. Alle Eckpunkte des Polygons sind relativ zu diesem Ursprung in der X-Y-Ebene.
  • vertexBuffer ist ein XrSpatialBufferEXT, der die ID für einen Puffer vom Typ XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT bereitstellt und den Vertex-Puffer der Entität darstellt, auf der sich diese Komponente befindet. Die Eckpunkte müssen gegen den 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 XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT sein.

Gültige Verwendung (implizit)

Komponentenlistenstruktur 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, der die Anzahl der Elemente im Array polygons beschreibt.
  • polygons ist ein Array von XrSpatialPolygon2DDataEXT .

Wenn Sie die 2D-Polygonkomponente 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 zur Kette XrSpatialComponentDataQueryResultEXT :: next hinzu.

Die Laufzeit muss XR_ERROR_VALIDATION_FAILURE von xrQuerySpatialComponentDataEXT zurückgeben, wenn XrSpatialComponentPolygon2DListEXT in der XrSpatialComponentDataQueryResultEXT :: next-Kette 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 bestimmte Funktion aufgeführt ist, kann eine Anwendung sie aktivieren, indem sie den Enumeranten in die Liste XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents der abgeleiteten Struktur XrSpatialCapabilityConfigurationBaseHeaderEXT der Funktion aufnimmt, die diese Komponente unterstützt.

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

Semantisches Label für Ebene

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 Stockwerk.

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 eine Tabelle.

Komponentenlistenstruktur 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, der die Anzahl der Elemente im Array semanticLabels beschreibt.
  • semanticLabels ist ein Array von XrSpatialPlaneSemanticLabelEXT .

Wenn Sie die semantische Labelkomponente für Ebenen 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 zur Kette XrSpatialComponentDataQueryResultEXT :: next hinzu.

Die Laufzeit muss XR_ERROR_VALIDATION_FAILURE von xrQuerySpatialComponentDataEXT zurückgeben, wenn XrSpatialComponentPlaneSemanticLabelListEXT in der nächsten Kette von 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 bestimmte Funktion aufgeführt ist, kann eine Anwendung sie aktivieren, indem sie den Enumeranten in die Liste XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents der abgeleiteten Struktur XrSpatialCapabilityConfigurationBaseHeaderEXT der Funktion aufnimmt, die diese Komponente unterstützt.

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

Beispiel-Code

Funktion zur Ebenenerkennung konfigurieren

Im folgenden Beispielcode wird gezeigt, wie Sie die Funktion zur Ebenenerkennung beim Erstellen eines räumlichen Kontexts konfigurieren.

// 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 entdecken und Komponentendaten abfragen

Im folgenden Beispielcode wird gezeigt, wie Sie räumliche Entitäten für einen mit XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT konfigurierten Kontext ermitteln 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 Gebäude

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

  • Version 1, 02.07.2024 (Nihav Jain, Google)

    • Anfängliche Beschreibung der Erweiterung