XR_EXT_spatial_plane_tracking
Stringa del nome
XR_EXT_spatial_plane_tracking
Tipo di estensione
Estensione dell'istanza
Numero di estensione registrato
742
Revisione
1
Stato di ratifica
Ratificato
Dipendenze di estensione e versione
XR_EXT_spatial_entity
Collaboratori
Nihav Jain, Google
Natalie Fleury, Meta
Yuichi Taguchi, Meta
Ron Bessems, Meta
Yin Li, Microsoft
Jimmy Alamparambil, ByteDance
Zhipeng Liu, ByteDance
Jun Yan, ByteDance
Panoramica
Questa estensione si basa su XR_EXT_spatial_entity e definisce la funzionalità spaziale di rilevamento del piano per il framework delle entità spaziali.
Supporto di runtime
Se il runtime supporta il rilevamento del piano, deve indicarlo enumerando XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT in xrEnumerateSpatialCapabilitiesEXT .
Configurazione
La struttura XrSpatialCapabilityConfigurationPlaneTrackingEXT è definita come segue:
typedef struct XrSpatialCapabilityConfigurationPlaneTrackingEXT {
XrStructureType type;
const void* next;
XrSpatialCapabilityEXT capability;
uint32_t enabledComponentCount;
const XrSpatialComponentTypeEXT* enabledComponents;
} XrSpatialCapabilityConfigurationPlaneTrackingEXT;
Descrizioni dei membri
typeè l'XrStructureType di questa struttura.nextèNULLo un puntatore alla struttura successiva in una catena di strutture.capabilityè un XrSpatialCapabilityEXT e deve essereXR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT.enabledComponentCountè unuint32_tche descrive il conteggio degli elementi nell'arrayenabledComponents.enabledComponentsè un puntatore a un array di XrSpatialComponentTypeEXT .
Le applicazioni possono abilitare la funzionalità spaziale XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT includendo un puntatore a una struttura XrSpatialCapabilityConfigurationPlaneTrackingEXT in XrSpatialContextCreateInfoEXT :: capabilityConfigs .
Il runtime deve restituire XR_ERROR_VALIDATION_FAILURE se capability non è XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT .
Utilizzo valido (implicito)
- L'estensione
XR_EXT_spatial_plane_trackingdeve essere abilitata prima di utilizzare XrSpatialCapabilityConfigurationPlaneTrackingEXT -
typedeve essereXR_TYPE_SPATIAL_CAPABILITY_CONFIGURATION_PLANE_TRACKING_EXT -
nextdeve essereNULLo un puntatore valido alla struttura successiva in una catena di strutture -
capabilitydeve essere un valore XrSpatialCapabilityEXT valido -
enabledComponentsdeve essere un puntatore a un array dienabledComponentCountvalori XrSpatialComponentTypeEXT validi - Il parametro
enabledComponentCountdeve essere maggiore di0
Componenti garantiti
Un runtime che supporta XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT deve fornire i seguenti componenti spaziali come componenti garantiti di tutte le entità rilevate da questa funzionalità e deve enumerarli in xrEnumerateSpatialCapabilityComponentTypesEXT :
XR_SPATIAL_COMPONENT_TYPE_BOUNDED_2D_EXTXR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT
Componente 2D delimitato
Il componente 2D delimitato fornisce il centro e le estensioni del piano rappresentato dall'entità su cui si trova. Per maggiori dettagli, consulta la sezione 2D delimitato.
Componente di allineamento del piano
Dati dei componenti
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;
L'enumerazione XrSpatialPlaneAlignmentEXT descrive l'allineamento del piano associato all'entità spaziale con un componente XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT.
I valori di enumerazione hanno i seguenti significati:
Descrizione dell'enumerazione
XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_UPWARD_EXT
L'entità è orizzontale e rivolta verso l'alto (ad es. il pavimento).
XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_DOWNWARD_EXT
L'entità è orizzontale e rivolta verso il basso (ad es. il soffitto).
XR_SPATIAL_PLANE_ALIGNMENT_VERTICAL_EXT
L'entità è verticale (ad es. una parete).
XR_SPATIAL_PLANE_ALIGNMENT_ARBITRARY_EXT
L'entità ha un orientamento arbitrario, non verticale e non orizzontale.
Struttura dell'elenco dei componenti per eseguire query sui dati
La struttura XrSpatialComponentPlaneAlignmentListEXT è definita come segue:
typedef struct XrSpatialComponentPlaneAlignmentListEXT {
XrStructureType type;
void* next;
uint32_t planeAlignmentCount;
XrSpatialPlaneAlignmentEXT* planeAlignments;
} XrSpatialComponentPlaneAlignmentListEXT;
Descrizioni dei membri
typeè l'XrStructureType di questa struttura.nextèNULLo un puntatore alla struttura successiva in una catena di strutture.planeAlignmentCountè unuint32_tche descrive il conteggio degli elementi nell'arrayplaneAlignments.planeAlignmentsè un array di XrSpatialPlaneAlignmentEXT .
Per eseguire query sul componente di allineamento del piano delle entità spaziali in un XrSpatialSnapshotEXT , includi XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT in XrSpatialComponentDataQueryConditionEXT :: componentTypes e aggiungi XrSpatialComponentPlaneAlignmentListEXT alla catena XrSpatialComponentDataQueryResultEXT :: next.
Il runtime deve restituire XR_ERROR_VALIDATION_FAILURE da xrQuerySpatialComponentDataEXT se XrSpatialComponentPlaneAlignmentListEXT si trova nella catena XrSpatialComponentDataQueryResultEXT :: next, ma XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT non è incluso in XrSpatialComponentDataQueryConditionEXT :: componentTypes .
Il runtime deve restituire XR_ERROR_SIZE_INSUFFICIENT da xrQuerySpatialComponentDataEXT se planeAlignmentCount è inferiore a XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .
Utilizzo valido (implicito)
- L'estensione
XR_EXT_spatial_plane_trackingdeve essere abilitata prima di utilizzare XrSpatialComponentPlaneAlignmentListEXT -
typedeve essereXR_TYPE_SPATIAL_COMPONENT_PLANE_ALIGNMENT_LIST_EXT -
nextdeve essereNULLo un puntatore valido alla struttura successiva in una catena di strutture -
planeAlignmentsdeve essere un puntatore a un array diplaneAlignmentCountvalori XrSpatialPlaneAlignmentEXT - Il parametro
planeAlignmentCountdeve essere maggiore di0
Configurazione
Se XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT è enumerato in XrSpatialCapabilityComponentTypesEXT :: componentTypes per una determinata funzionalità, un'applicazione può abilitarlo includendo l'enumerazione nell'elenco XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents della struttura derivata XrSpatialCapabilityConfigurationBaseHeaderEXT della funzionalità che supporta questo componente.
Questo componente non richiede alcuna configurazione speciale per essere incluso nella catena XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.
Componenti facoltativi
Un runtime che supporta XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT può supportare altri componenti spaziali oltre a quelli elencati nella sezione Componenti garantiti. Un'applicazione utilizza xrEnumerateSpatialCapabilityComponentTypesEXT per ottenere l'elenco completo dei componenti supportati da un runtime, quindi configura quelli di suo interesse durante la creazione del contesto spaziale.
Componente mesh 2D
Dati dei componenti
XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT utilizza la struttura XrSpatialMeshDataEXT per i suoi dati.
Struttura dell'elenco dei componenti per eseguire query sui dati
La struttura XrSpatialComponentMesh2DListEXT è definita come segue:
typedef struct XrSpatialComponentMesh2DListEXT {
XrStructureType type;
void* next;
uint32_t meshCount;
XrSpatialMeshDataEXT* meshes;
} XrSpatialComponentMesh2DListEXT;
Descrizioni dei membri
typeè l'XrStructureType di questa struttura.nextèNULLo un puntatore alla struttura successiva in una catena di strutture.meshCountè unuint32_tche descrive il conteggio degli elementi nell'arraymeshes.meshesè un array di XrSpatialMeshDataEXT .
Per eseguire query sul componente mesh 2D delle entità spaziali in un XrSpatialSnapshotEXT , includi XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT in XrSpatialComponentDataQueryConditionEXT :: componentTypes e aggiungi XrSpatialComponentMesh2DListEXT alla catena XrSpatialComponentDataQueryResultEXT :: next.
Il runtime deve restituire XR_ERROR_VALIDATION_FAILURE da xrQuerySpatialComponentDataEXT se XrSpatialComponentMesh2DListEXT si trova nella catena XrSpatialComponentDataQueryResultEXT :: next, ma XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT non è incluso in XrSpatialComponentDataQueryConditionEXT :: componentTypes .
Il runtime deve restituire XR_ERROR_SIZE_INSUFFICIENT da xrQuerySpatialComponentDataEXT se meshCount è inferiore a XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .
Per XrSpatialMeshDataEXT compilato dal runtime nell'meshes array, il XrSpatialBufferEXT :: bufferType per XrSpatialMeshDataEXT :: vertexBuffer deve essere XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT e il XrSpatialBufferEXT :: bufferType per XrSpatialMeshDataEXT :: indexBuffer deve essere XR_SPATIAL_BUFFER_TYPE_UINT16_EXT .
Utilizzo valido (implicito)
- L'estensione
XR_EXT_spatial_plane_trackingdeve essere abilitata prima di utilizzare XrSpatialComponentMesh2DListEXT -
typedeve essereXR_TYPE_SPATIAL_COMPONENT_MESH_2D_LIST_EXT -
nextdeve essereNULLo un puntatore valido alla struttura successiva in una catena di strutture -
meshesdeve essere un puntatore a un array dimeshCountstrutture XrSpatialMeshDataEXT - Il parametro
meshCountdeve essere maggiore di0
Configurazione
Se XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT è enumerato in XrSpatialCapabilityComponentTypesEXT :: componentTypes per una determinata funzionalità, un'applicazione può abilitarlo includendo l'enumerazione nell'elenco XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents della struttura derivata XrSpatialCapabilityConfigurationBaseHeaderEXT della funzionalità che supporta questo componente.
Questo componente non richiede alcuna configurazione speciale per essere incluso nella catena XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.
Componente poligono 2D
Dati dei componenti
La struttura XrSpatialPolygon2DDataEXT è definita come segue:
typedef struct XrSpatialPolygon2DDataEXT {
XrPosef origin;
XrSpatialBufferEXT vertexBuffer;
} XrSpatialPolygon2DDataEXT;
Descrizioni dei membri
originè un XrPosef che definisce l'origine del poligono. Tutti i vertici del poligono sono relativi a questa origine nel piano X-Y.vertexBufferè un XrSpatialBufferEXT che fornisce l'ID per un buffer di tipoXR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXTe rappresenta il buffer dei vertici dell'entità su cui si trova questo componente. I vertici devono essere restituiti in senso antiorario. Il poligono rappresentato da questi vertici non deve autointersecarsi e può essere concavo.
XrSpatialBufferEXT :: bufferType per vertexBuffer deve essere XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT .
Utilizzo valido (implicito)
- L'estensione
XR_EXT_spatial_plane_trackingdeve essere abilitata prima di utilizzare XrSpatialPolygon2DDataEXT -
vertexBufferdeve essere una struttura XrSpatialBufferEXT valida
Struttura dell'elenco dei componenti per eseguire query sui dati
La struttura XrSpatialComponentPolygon2DListEXT è definita come segue:
typedef struct XrSpatialComponentPolygon2DListEXT {
XrStructureType type;
void* next;
uint32_t polygonCount;
XrSpatialPolygon2DDataEXT* polygons;
} XrSpatialComponentPolygon2DListEXT;
Descrizioni dei membri
typeè l'XrStructureType di questa struttura.nextèNULLo un puntatore alla struttura successiva in una catena di strutture.polygonCountè unuint32_tche descrive il conteggio degli elementi nell'arraypolygons.polygonsè un array di XrSpatialPolygon2DDataEXT .
Per eseguire query sul componente poligono 2D delle entità spaziali in un XrSpatialSnapshotEXT , includi XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT in XrSpatialComponentDataQueryConditionEXT :: componentTypes e aggiungi XrSpatialComponentPolygon2DListEXT alla catena XrSpatialComponentDataQueryResultEXT :: next.
Il runtime deve restituire XR_ERROR_VALIDATION_FAILURE da xrQuerySpatialComponentDataEXT se XrSpatialComponentPolygon2DListEXT si trova nella catena XrSpatialComponentDataQueryResultEXT :: next, ma XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT non è incluso in XrSpatialComponentDataQueryConditionEXT :: componentTypes .
Il runtime deve restituire XR_ERROR_SIZE_INSUFFICIENT da xrQuerySpatialComponentDataEXT se polygonCount è inferiore a XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .
Utilizzo valido (implicito)
- L'estensione
XR_EXT_spatial_plane_trackingdeve essere abilitata prima di utilizzare XrSpatialComponentPolygon2DListEXT -
typedeve essereXR_TYPE_SPATIAL_COMPONENT_POLYGON_2D_LIST_EXT -
nextdeve essereNULLo un puntatore valido alla struttura successiva in una catena di strutture -
polygonsdeve essere un puntatore a un array dipolygonCountstrutture XrSpatialPolygon2DDataEXT - Il parametro
polygonCountdeve essere maggiore di0
Configurazione
Se XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT è enumerato in XrSpatialCapabilityComponentTypesEXT :: componentTypes per una determinata funzionalità, un'applicazione può abilitarlo includendo l'enumerazione nell'elenco XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents della struttura derivata XrSpatialCapabilityConfigurationBaseHeaderEXT della funzionalità che supporta questo componente.
Questo componente non richiede alcuna configurazione speciale per essere incluso nella catena XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.
Etichetta semantica del piano
Dati dei componenti
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;
L'enumerazione XrSpatialPlaneSemanticLabelEXT descrive un insieme di etichette semantiche per i piani.
Descrizione dell'enumerazione
XR_SPATIAL_PLANE_SEMANTIC_LABEL_UNCATEGORIZED_EXT
Il runtime non è riuscito a classificare questa entità.
XR_SPATIAL_PLANE_SEMANTIC_LABEL_FLOOR_EXT
L'entità è un pavimento.
XR_SPATIAL_PLANE_SEMANTIC_LABEL_WALL_EXT
L'entità è una parete.
XR_SPATIAL_PLANE_SEMANTIC_LABEL_CEILING_EXT
L'entità è un soffitto.
XR_SPATIAL_PLANE_SEMANTIC_LABEL_TABLE_EXT
L'entità è un tavolo.
Struttura dell'elenco dei componenti per eseguire query sui dati
La struttura XrSpatialComponentPlaneSemanticLabelListEXT è definita come segue:
typedef struct XrSpatialComponentPlaneSemanticLabelListEXT {
XrStructureType type;
void* next;
uint32_t semanticLabelCount;
XrSpatialPlaneSemanticLabelEXT* semanticLabels;
} XrSpatialComponentPlaneSemanticLabelListEXT;
Descrizioni dei membri
typeè l'XrStructureType di questa struttura.nextèNULLo un puntatore alla struttura successiva in una catena di strutture.semanticLabelCountè unuint32_tche descrive il conteggio degli elementi nell'arraysemanticLabels.semanticLabelsè un array di XrSpatialPlaneSemanticLabelEXT .
Per eseguire query sul componente dell'etichetta semantica del piano delle entità spaziali in un XrSpatialSnapshotEXT , includi XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT in XrSpatialComponentDataQueryConditionEXT :: componentTypes e aggiungi XrSpatialComponentPlaneSemanticLabelListEXT alla catena XrSpatialComponentDataQueryResultEXT :: next.
Il runtime deve restituire XR_ERROR_VALIDATION_FAILURE da xrQuerySpatialComponentDataEXT se XrSpatialComponentPlaneSemanticLabelListEXT si trova nella catena XrSpatialComponentDataQueryResultEXT :: next, ma XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT non è incluso in XrSpatialComponentDataQueryConditionEXT :: componentTypes .
Il runtime deve restituire XR_ERROR_SIZE_INSUFFICIENT da xrQuerySpatialComponentDataEXT se semanticLabelCount è inferiore a XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .
Utilizzo valido (implicito)
- L'estensione
XR_EXT_spatial_plane_trackingdeve essere abilitata prima di utilizzare XrSpatialComponentPlaneSemanticLabelListEXT -
typedeve essereXR_TYPE_SPATIAL_COMPONENT_PLANE_SEMANTIC_LABEL_LIST_EXT -
nextdeve essereNULLo un puntatore valido alla struttura successiva in una catena di strutture -
semanticLabelsdeve essere un puntatore a un array disemanticLabelCountvalori XrSpatialPlaneSemanticLabelEXT - Il parametro
semanticLabelCountdeve essere maggiore di0
Configurazione
Se XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT è enumerato in XrSpatialCapabilityComponentTypesEXT :: componentTypes per una determinata funzionalità, un'applicazione può abilitarlo includendo l'enumerazione nell'elenco XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents della struttura derivata XrSpatialCapabilityConfigurationBaseHeaderEXT della funzionalità che supporta questo componente.
Questo componente non richiede alcuna configurazione speciale per essere incluso nella catena XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.
Esempio di codice
Configurare la funzionalità di rilevamento del piano
Il seguente esempio di codice mostra come configurare la funzionalità di rilevamento del piano durante la creazione di un contesto spaziale.
// 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));
Individuare le entità spaziali ed eseguire query sui dati dei componenti
Il seguente esempio di codice mostra come individuare le entità spaziali per un contesto configurato con XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT ed eseguire query sui dati dei componenti.
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
// ...
}
Nuove strutture
- XrSpatialCapabilityConfigurationPlaneTrackingEXT
- XrSpatialPolygon2DDataEXT
Estensione di XrSpatialComponentDataQueryResultEXT :
Nuove enumerazioni
Nuove costanti di enumerazione
XR_EXT_SPATIAL_PLANE_TRACKING_EXTENSION_NAMEXR_EXT_spatial_plane_tracking_SPEC_VERSIONEstensione di XrSpatialCapabilityEXT :
XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT
Estensione di XrSpatialComponentTypeEXT :
XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXTXR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXTXR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXTXR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT
Estensione di XrStructureType :
XR_TYPE_SPATIAL_CAPABILITY_CONFIGURATION_PLANE_TRACKING_EXTXR_TYPE_SPATIAL_COMPONENT_MESH_2D_LIST_EXTXR_TYPE_SPATIAL_COMPONENT_PLANE_ALIGNMENT_LIST_EXTXR_TYPE_SPATIAL_COMPONENT_PLANE_SEMANTIC_LABEL_LIST_EXTXR_TYPE_SPATIAL_COMPONENT_POLYGON_2D_LIST_EXT
Problemi
Cronologia delle versioni
Revisione 1, 02/07/2024 (Nihav Jain, Google)
- Descrizione iniziale dell'estensione