XR_EXT_spatial_plane_tracking
Cadena de nombre
XR_EXT_spatial_plane_tracking
Tipo de extensión
Extensión de instancia
Número de extensión registrada
742
Revisión
1
Estado de ratificación
Ratificado
Dependencias de extensión y versión
XR_EXT_spatial_entity
Colaboradores
Nihav Jain, Google
Natalie Fleury, Meta
Yuichi Taguchi, Meta
Ron Bessems, Meta
Yin Li, Microsoft
Jimmy Alamparambil, ByteDance
Zhipeng Liu, ByteDance
Jun Yan, ByteDance
Descripción general
Esta extensión se basa en XR_EXT_spatial_entity y define la capacidad espacial de seguimiento de planos para el framework de entidades espaciales.
Asistencia del entorno de ejecución
Si el entorno de ejecución admite el seguimiento de planos, debe indicarlo enumerando XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT en xrEnumerateSpatialCapabilitiesEXT .
Configuración
La estructura XrSpatialCapabilityConfigurationPlaneTrackingEXT se define de la siguiente manera:
typedef struct XrSpatialCapabilityConfigurationPlaneTrackingEXT {
XrStructureType type;
const void* next;
XrSpatialCapabilityEXT capability;
uint32_t enabledComponentCount;
const XrSpatialComponentTypeEXT* enabledComponents;
} XrSpatialCapabilityConfigurationPlaneTrackingEXT;
Descripciones de miembros
typees el XrStructureType de esta estructura.nextesNULLo un puntero a la siguiente estructura en una cadena de estructuras.capabilityes un XrSpatialCapabilityEXT y debe serXR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT.enabledComponentCountes unuint32_tque describe el recuento de elementos en el arrayenabledComponents.enabledComponentses un puntero a un array de XrSpatialComponentTypeEXT .
Las aplicaciones pueden habilitar la capacidad espacial XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT incluyendo un puntero a una estructura XrSpatialCapabilityConfigurationPlaneTrackingEXT en XrSpatialContextCreateInfoEXT :: capabilityConfigs .
El entorno de ejecución debe mostrar XR_ERROR_VALIDATION_FAILURE si capability no es XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT .
Uso válido (implícito)
- La extensión
XR_EXT_spatial_plane_trackingdebe habilitarse antes de usar XrSpatialCapabilityConfigurationPlaneTrackingEXT. -
typedebe serXR_TYPE_SPATIAL_CAPABILITY_CONFIGURATION_PLANE_TRACKING_EXT -
nextdebe serNULLo un puntero válido a la siguiente estructura en una cadena de estructuras -
capabilitydebe ser un valor XrSpatialCapabilityEXT válido -
enabledComponentsdebe ser un puntero a un array deenabledComponentCountvalores XrSpatialComponentTypeEXT válidos - El parámetro
enabledComponentCountdebe ser mayor que0
Componentes garantizados
Un entorno de ejecución que admite XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT debe proporcionar los siguientes componentes espaciales como componentes garantizados de todas las entidades descubiertas por esta capacidad y debe enumerarlos en xrEnumerateSpatialCapabilityComponentTypesEXT :
XR_SPATIAL_COMPONENT_TYPE_BOUNDED_2D_EXTXR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT
Componente 2D delimitado
El componente 2D delimitado proporciona el centro y las extensiones del plano representado por la entidad en la que se encuentra. Consulta 2D delimitado para obtener más detalles.
Componente de alineación de planos
Datos del componente
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;
La enumeración XrSpatialPlaneAlignmentEXT describe la alineación del plano asociado con la entidad espacial con un componente XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT.
Los valores de enumeración tienen los siguientes significados:
Descripción de enum
XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_UPWARD_EXT
La entidad es horizontal y mira hacia arriba (p.ej., el piso).
XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_DOWNWARD_EXT
La entidad es horizontal y mira hacia abajo (p.ej., el techo).
XR_SPATIAL_PLANE_ALIGNMENT_VERTICAL_EXT
La entidad es vertical (p.ej., una pared).
XR_SPATIAL_PLANE_ALIGNMENT_ARBITRARY_EXT
La entidad tiene una orientación arbitraria, no vertical y no horizontal.
Estructura de la lista de componentes para consultar datos
La estructura XrSpatialComponentPlaneAlignmentListEXT se define de la siguiente manera:
typedef struct XrSpatialComponentPlaneAlignmentListEXT {
XrStructureType type;
void* next;
uint32_t planeAlignmentCount;
XrSpatialPlaneAlignmentEXT* planeAlignments;
} XrSpatialComponentPlaneAlignmentListEXT;
Descripciones de miembros
typees el XrStructureType de esta estructura.nextesNULLo un puntero a la siguiente estructura en una cadena de estructuras.planeAlignmentCountes unuint32_tque describe el recuento de elementos en el arrayplaneAlignments.planeAlignmentses un array de XrSpatialPlaneAlignmentEXT .
Para consultar el componente de alineación de planos de las entidades espaciales en un XrSpatialSnapshotEXT , incluye XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT en XrSpatialComponentDataQueryConditionEXT :: componentTypes y agrega XrSpatialComponentPlaneAlignmentListEXT a la cadena XrSpatialComponentDataQueryResultEXT :: next.
El entorno de ejecución debe mostrar XR_ERROR_VALIDATION_FAILURE desde xrQuerySpatialComponentDataEXT si XrSpatialComponentPlaneAlignmentListEXT está en la cadena XrSpatialComponentDataQueryResultEXT :: next, pero XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT no está incluido en XrSpatialComponentDataQueryConditionEXT :: componentTypes .
El entorno de ejecución debe mostrar XR_ERROR_SIZE_INSUFFICIENT desde xrQuerySpatialComponentDataEXT si planeAlignmentCount es menor que XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .
Uso válido (implícito)
- La extensión
XR_EXT_spatial_plane_trackingdebe habilitarse antes de usar XrSpatialComponentPlaneAlignmentListEXT. -
typedebe serXR_TYPE_SPATIAL_COMPONENT_PLANE_ALIGNMENT_LIST_EXT -
nextdebe serNULLo un puntero válido a la siguiente estructura en una cadena de estructuras -
planeAlignmentsdebe ser un puntero a un array de valoresplaneAlignmentCountXrSpatialPlaneAlignmentEXT. - El parámetro
planeAlignmentCountdebe ser mayor que0
Configuración
Si XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT se enumera en XrSpatialCapabilityComponentTypesEXT :: componentTypes para alguna capacidad, una aplicación puede habilitarla incluyendo el enumerador en la lista XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents de la estructura derivada XrSpatialCapabilityConfigurationBaseHeaderEXT de la capacidad que admite este componente.
Este componente no requiere ninguna configuración especial para incluirse en la cadena XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.
Componentes opcionales
Un entorno de ejecución que admite XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT puede admitir otros componentes espaciales además de los que se enumeran en la sección Componentes garantizados. Una aplicación usa xrEnumerateSpatialCapabilityComponentTypesEXT para obtener la lista completa de componentes que admite un entorno de ejecución y, luego, configura los que le interesan cuando crea el contexto espacial.
Componente de malla 2D
Datos del componente
XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT usa la estructura XrSpatialMeshDataEXT para sus datos.
Estructura de la lista de componentes para consultar datos
La estructura XrSpatialComponentMesh2DListEXT se define de la siguiente manera:
typedef struct XrSpatialComponentMesh2DListEXT {
XrStructureType type;
void* next;
uint32_t meshCount;
XrSpatialMeshDataEXT* meshes;
} XrSpatialComponentMesh2DListEXT;
Descripciones de miembros
typees el XrStructureType de esta estructura.nextesNULLo un puntero a la siguiente estructura en una cadena de estructuras.meshCountes unuint32_tque describe el recuento de elementos en el arraymeshes.mesheses un array de XrSpatialMeshDataEXT .
Para consultar el componente de malla 2D de las entidades espaciales en un XrSpatialSnapshotEXT , incluye XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT en XrSpatialComponentDataQueryConditionEXT :: componentTypes y agrega XrSpatialComponentMesh2DListEXT a la cadena XrSpatialComponentDataQueryResultEXT :: next.
El entorno de ejecución debe mostrar XR_ERROR_VALIDATION_FAILURE desde xrQuerySpatialComponentDataEXT si XrSpatialComponentMesh2DListEXT está en la cadena XrSpatialComponentDataQueryResultEXT :: next, pero XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT no está incluido en XrSpatialComponentDataQueryConditionEXT :: componentTypes .
El entorno de ejecución debe mostrar XR_ERROR_SIZE_INSUFFICIENT desde xrQuerySpatialComponentDataEXT si meshCount es menor que XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .
Para el XrSpatialMeshDataEXT propagado por el entorno de ejecución en el array meshes, el XrSpatialBufferEXT :: bufferType para XrSpatialMeshDataEXT :: vertexBuffer debe ser XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT y el XrSpatialBufferEXT :: bufferType para XrSpatialMeshDataEXT :: indexBuffer debe ser XR_SPATIAL_BUFFER_TYPE_UINT16_EXT .
Uso válido (implícito)
- La extensión
XR_EXT_spatial_plane_trackingdebe habilitarse antes de usar XrSpatialComponentMesh2DListEXT. -
typedebe serXR_TYPE_SPATIAL_COMPONENT_MESH_2D_LIST_EXT -
nextdebe serNULLo un puntero válido a la siguiente estructura en una cadena de estructuras -
meshesdebe ser un puntero a un array de estructurasmeshCountXrSpatialMeshDataEXT. - El parámetro
meshCountdebe ser mayor que0
Configuración
Si XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT se enumera en XrSpatialCapabilityComponentTypesEXT :: componentTypes para alguna capacidad, una aplicación puede habilitarla incluyendo el enumerador en la lista XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents de la estructura derivada XrSpatialCapabilityConfigurationBaseHeaderEXT de la capacidad que admite este componente.
Este componente no requiere ninguna configuración especial para incluirse en la cadena XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.
Componente de polígono 2D
Datos del componente
La estructura XrSpatialPolygon2DDataEXT se define de la siguiente manera:
typedef struct XrSpatialPolygon2DDataEXT {
XrPosef origin;
XrSpatialBufferEXT vertexBuffer;
} XrSpatialPolygon2DDataEXT;
Descripciones de miembros
origines un XrPosef que define el origen del polígono. Todos los vértices del polígono son relativos a este origen en el plano X-Y.vertexBufferes un XrSpatialBufferEXT que proporciona el ID de un búfer de tipoXR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXTy representa el búfer de vértices de la entidad en la que se encuentra este componente. Los vértices deben mostrarse en sentido antihorario. El polígono representado por estos vértices no debe intersecarse a sí mismo y puede ser cóncavo.
XrSpatialBufferEXT :: bufferType para vertexBuffer debe ser XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT .
Uso válido (implícito)
- La extensión
XR_EXT_spatial_plane_trackingdebe habilitarse antes de usar XrSpatialPolygon2DDataEXT. -
vertexBufferdebe ser una estructura XrSpatialBufferEXT válida.
Estructura de la lista de componentes para consultar datos
La estructura XrSpatialComponentPolygon2DListEXT se define de la siguiente manera:
typedef struct XrSpatialComponentPolygon2DListEXT {
XrStructureType type;
void* next;
uint32_t polygonCount;
XrSpatialPolygon2DDataEXT* polygons;
} XrSpatialComponentPolygon2DListEXT;
Descripciones de miembros
typees el XrStructureType de esta estructura.nextesNULLo un puntero a la siguiente estructura en una cadena de estructuras.polygonCountes unuint32_tque describe el recuento de elementos en el arraypolygons.polygonses un array de XrSpatialPolygon2DDataEXT .
Para consultar el componente de polígono 2D de las entidades espaciales en un XrSpatialSnapshotEXT , incluye XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT en XrSpatialComponentDataQueryConditionEXT :: componentTypes y agrega XrSpatialComponentPolygon2DListEXT a la cadena XrSpatialComponentDataQueryResultEXT :: next.
El entorno de ejecución debe mostrar XR_ERROR_VALIDATION_FAILURE desde xrQuerySpatialComponentDataEXT si XrSpatialComponentPolygon2DListEXT está en la cadena XrSpatialComponentDataQueryResultEXT :: next, pero XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT no está incluido en XrSpatialComponentDataQueryConditionEXT :: componentTypes .
El entorno de ejecución debe mostrar XR_ERROR_SIZE_INSUFFICIENT desde xrQuerySpatialComponentDataEXT si polygonCount es menor que XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .
Uso válido (implícito)
- La extensión
XR_EXT_spatial_plane_trackingdebe habilitarse antes de usar XrSpatialComponentPolygon2DListEXT. -
typedebe serXR_TYPE_SPATIAL_COMPONENT_POLYGON_2D_LIST_EXT -
nextdebe serNULLo un puntero válido a la siguiente estructura en una cadena de estructuras -
polygonsdebe ser un puntero a un array de estructuraspolygonCountXrSpatialPolygon2DDataEXT. - El parámetro
polygonCountdebe ser mayor que0
Configuración
Si XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT se enumera en XrSpatialCapabilityComponentTypesEXT :: componentTypes para alguna capacidad, una aplicación puede habilitarla incluyendo el enumerador en la lista XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents de la estructura derivada XrSpatialCapabilityConfigurationBaseHeaderEXT de la capacidad que admite este componente.
Este componente no requiere ninguna configuración especial para incluirse en la cadena XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.
Etiqueta semántica de plano
Datos del componente
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;
La enumeración XrSpatialPlaneSemanticLabelEXT describe un conjunto de etiquetas semánticas para planos.
Descripción de enum
XR_SPATIAL_PLANE_SEMANTIC_LABEL_UNCATEGORIZED_EXT
El entorno de ejecución no pudo clasificar esta entidad.
XR_SPATIAL_PLANE_SEMANTIC_LABEL_FLOOR_EXT
La entidad es un piso.
XR_SPATIAL_PLANE_SEMANTIC_LABEL_WALL_EXT
La entidad es una pared.
XR_SPATIAL_PLANE_SEMANTIC_LABEL_CEILING_EXT
La entidad es un techo.
XR_SPATIAL_PLANE_SEMANTIC_LABEL_TABLE_EXT
La entidad es una tabla.
Estructura de la lista de componentes para consultar datos
La estructura XrSpatialComponentPlaneSemanticLabelListEXT se define de la siguiente manera:
typedef struct XrSpatialComponentPlaneSemanticLabelListEXT {
XrStructureType type;
void* next;
uint32_t semanticLabelCount;
XrSpatialPlaneSemanticLabelEXT* semanticLabels;
} XrSpatialComponentPlaneSemanticLabelListEXT;
Descripciones de miembros
typees el XrStructureType de esta estructura.nextesNULLo un puntero a la siguiente estructura en una cadena de estructuras.semanticLabelCountes unuint32_tque describe el recuento de elementos en el arraysemanticLabels.semanticLabelses un array de XrSpatialPlaneSemanticLabelEXT .
Para consultar el componente de etiqueta semántica de plano de las entidades espaciales en un XrSpatialSnapshotEXT , incluye XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT en XrSpatialComponentDataQueryConditionEXT :: componentTypes y agrega XrSpatialComponentPlaneSemanticLabelListEXT a la cadena XrSpatialComponentDataQueryResultEXT :: next.
El entorno de ejecución debe mostrar XR_ERROR_VALIDATION_FAILURE desde xrQuerySpatialComponentDataEXT si XrSpatialComponentPlaneSemanticLabelListEXT está en la siguiente cadena de XrSpatialComponentDataQueryResultEXT :: next, pero XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT no está incluido en XrSpatialComponentDataQueryConditionEXT :: componentTypes .
El entorno de ejecución debe mostrar XR_ERROR_SIZE_INSUFFICIENT desde xrQuerySpatialComponentDataEXT si semanticLabelCount es menor que XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .
Uso válido (implícito)
- La extensión
XR_EXT_spatial_plane_trackingdebe habilitarse antes de usar XrSpatialComponentPlaneSemanticLabelListEXT. -
typedebe serXR_TYPE_SPATIAL_COMPONENT_PLANE_SEMANTIC_LABEL_LIST_EXT -
nextdebe serNULLo un puntero válido a la siguiente estructura en una cadena de estructuras -
semanticLabelsdebe ser un puntero a un array de valoressemanticLabelCountXrSpatialPlaneSemanticLabelEXT. - El parámetro
semanticLabelCountdebe ser mayor que0
Configuración
Si XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT se enumera en XrSpatialCapabilityComponentTypesEXT :: componentTypes para alguna capacidad, una aplicación puede habilitarla incluyendo el enumerador en la lista XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents de la estructura derivada XrSpatialCapabilityConfigurationBaseHeaderEXT de la capacidad que admite este componente.
Este componente no requiere ninguna configuración especial para incluirse en la cadena XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.
Código de ejemplo
Configura la capacidad de seguimiento de planos
En el siguiente código de ejemplo, se muestra cómo configurar la capacidad de seguimiento de planos cuando se crea un contexto espacial.
// 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));
Descubre entidades espaciales y consulta datos de componentes
En el siguiente código de ejemplo, se muestra cómo descubrir entidades espaciales para un contexto configurado con XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT y consultar sus datos de componentes.
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
// ...
}
Nuevas estructuras
- XrSpatialCapabilityConfigurationPlaneTrackingEXT
- XrSpatialPolygon2DDataEXT
Extensión de XrSpatialComponentDataQueryResultEXT :
Nuevos enums
Nuevas constantes de enum
XR_EXT_SPATIAL_PLANE_TRACKING_EXTENSION_NAMEXR_EXT_spatial_plane_tracking_SPEC_VERSIONExtensión de XrSpatialCapabilityEXT :
XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT
Extensión de 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
Extensión de 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
Problemas
Historial de versiones
Revisión 1, 2/7/2024 (Nihav Jain, Google)
- Descripción inicial de la extensión