XR_EXT_spatial_plane_tracking
Chaîne de nom
XR_EXT_spatial_plane_tracking
Type d'extension
Extension d'instance
Numéro d'extension enregistré
742
Révision
1
État de ratification
Ratifié
Dépendances d'extension et de version
XR_EXT_spatial_entity
Participants
Nihav Jain, Google
Natalie Fleury, Meta
Yuichi Taguchi, Meta
Ron Bessems, Meta
Yin Li, Microsoft
Jimmy Alamparambil, ByteDance
Zhipeng Liu, ByteDance
Jun Yan, ByteDance
Présentation
Cette extension s'appuie sur XR_EXT_spatial_entity et définit la fonctionnalité spatiale de suivi de plan pour le framework d'entité spatiale.
Compatibilité des environnements d'exécution
Si l'environnement d'exécution est compatible avec le suivi de plan, il doit l'indiquer en énumérant XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT dans xrEnumerateSpatialCapabilitiesEXT .
Configuration
La structure XrSpatialCapabilityConfigurationPlaneTrackingEXT est définie comme suit :
typedef struct XrSpatialCapabilityConfigurationPlaneTrackingEXT {
XrStructureType type;
const void* next;
XrSpatialCapabilityEXT capability;
uint32_t enabledComponentCount;
const XrSpatialComponentTypeEXT* enabledComponents;
} XrSpatialCapabilityConfigurationPlaneTrackingEXT;
Descriptions des membres
typecorrespond au XrStructureType de cette structure.nextestNULLou un pointeur vers la structure suivante dans une chaîne de structures.capabilityest un XrSpatialCapabilityEXT et doit êtreXR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT.enabledComponentCountest unuint32_tdécrivant le nombre d'éléments dans le tableauenabledComponents.enabledComponentsest un pointeur vers un tableau de XrSpatialComponentTypeEXT .
Les applications peuvent activer la fonctionnalité spatiale XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT en incluant un pointeur vers une structure XrSpatialCapabilityConfigurationPlaneTrackingEXT dans XrSpatialContextCreateInfoEXT :: capabilityConfigs .
L'environnement d'exécution doit renvoyer XR_ERROR_VALIDATION_FAILURE si capability n'est pas XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT .
Utilisation valide (implicite)
- L'extension
XR_EXT_spatial_plane_trackingdoit être activée avant d'utiliser XrSpatialCapabilityConfigurationPlaneTrackingEXT. -
typedoit êtreXR_TYPE_SPATIAL_CAPABILITY_CONFIGURATION_PLANE_TRACKING_EXT -
nextdoit êtreNULLou un pointeur valide vers la structure suivante dans une chaîne de structures -
capabilitydoit être une valeur XrSpatialCapabilityEXT valide. -
enabledComponentsdoit être un pointeur vers un tableau deenabledComponentCountvaleurs XrSpatialComponentTypeEXT valides. - Le paramètre
enabledComponentCountdoit être supérieur à0
Composants garantis
Un environnement d'exécution compatible avec XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT doit fournir les composants spatiaux suivants en tant que composants garantis de toutes les entités découvertes par cette fonctionnalité et doit les énumérer dans xrEnumerateSpatialCapabilityComponentTypesEXT :
XR_SPATIAL_COMPONENT_TYPE_BOUNDED_2D_EXTXR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT
Composant 2D limité
Le composant 2D limité fournit le centre et l'étendue du plan représenté par l'entité sur laquelle il se trouve. Pour en savoir plus, consultez la section 2D limité.
Composant d'alignement de plan
Données du composant
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'énumération XrSpatialPlaneAlignmentEXT décrit l'alignement du plan associé à l'entité spatiale avec un composant XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT.
Les valeurs d'énumération ont les significations suivantes :
Description de l'enum
XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_UPWARD_EXT
L'entité est horizontale et orientée vers le haut (par exemple, un sol).
XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_DOWNWARD_EXT
L'entité est horizontale et orientée vers le bas (par exemple, un plafond).
XR_SPATIAL_PLANE_ALIGNMENT_VERTICAL_EXT
L'entité est verticale (par exemple, un mur).
XR_SPATIAL_PLANE_ALIGNMENT_ARBITRARY_EXT
L'entité a une orientation arbitraire, non verticale et non horizontale.
Structure de la liste des composants pour interroger les données
La structure XrSpatialComponentPlaneAlignmentListEXT est définie comme suit :
typedef struct XrSpatialComponentPlaneAlignmentListEXT {
XrStructureType type;
void* next;
uint32_t planeAlignmentCount;
XrSpatialPlaneAlignmentEXT* planeAlignments;
} XrSpatialComponentPlaneAlignmentListEXT;
Descriptions des membres
typecorrespond au XrStructureType de cette structure.nextestNULLou un pointeur vers la structure suivante dans une chaîne de structures.planeAlignmentCountest unuint32_tdécrivant le nombre d'éléments dans le tableauplaneAlignments.planeAlignmentsest un tableau de XrSpatialPlaneAlignmentEXT .
Pour interroger le composant d'alignement de plan des entités spatiales dans un XrSpatialSnapshotEXT , incluez XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT dans XrSpatialComponentDataQueryConditionEXT :: componentTypes et ajoutez XrSpatialComponentPlaneAlignmentListEXT à la chaîne XrSpatialComponentDataQueryResultEXT :: next.
L'environnement d'exécution doit renvoyer XR_ERROR_VALIDATION_FAILURE à partir de xrQuerySpatialComponentDataEXT si XrSpatialComponentPlaneAlignmentListEXT se trouve dans la chaîne XrSpatialComponentDataQueryResultEXT :: next, mais que XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT n'est pas inclus dans XrSpatialComponentDataQueryConditionEXT :: componentTypes .
L'environnement d'exécution doit renvoyer XR_ERROR_SIZE_INSUFFICIENT à partir de xrQuerySpatialComponentDataEXT si planeAlignmentCount est inférieur à XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .
Utilisation valide (implicite)
- L'extension
XR_EXT_spatial_plane_trackingdoit être activée avant d'utiliser XrSpatialComponentPlaneAlignmentListEXT -
typedoit êtreXR_TYPE_SPATIAL_COMPONENT_PLANE_ALIGNMENT_LIST_EXT -
nextdoit êtreNULLou un pointeur valide vers la structure suivante dans une chaîne de structures -
planeAlignmentsdoit être un pointeur vers un tableau deplaneAlignmentCountvaleurs XrSpatialPlaneAlignmentEXT. - Le paramètre
planeAlignmentCountdoit être supérieur à0
Configuration
Si XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT est énuméré dans XrSpatialCapabilityComponentTypesEXT :: componentTypes pour une fonctionnalité, une application peut l'activer en incluant l'énumérant dans la liste XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents de la structure dérivée XrSpatialCapabilityConfigurationBaseHeaderEXT de la fonctionnalité compatible avec ce composant.
Ce composant ne nécessite aucune configuration spéciale pour être inclus dans la chaîne XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.
Composants facultatifs
Un environnement d'exécution compatible avec XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT peut être compatible avec d'autres composants spatiaux en plus de ceux listés dans la section Composants garantis. Une application utilise xrEnumerateSpatialCapabilityComponentTypesEXT pour obtenir la liste complète des composants compatibles avec un environnement d'exécution, puis configure ceux qui l'intéressent lors de la création du contexte spatial.
Composant de maillage 2D
Données du composant
XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT utilise la structure XrSpatialMeshDataEXT pour ses données.
Structure de la liste des composants pour interroger les données
La structure XrSpatialComponentMesh2DListEXT est définie comme suit :
typedef struct XrSpatialComponentMesh2DListEXT {
XrStructureType type;
void* next;
uint32_t meshCount;
XrSpatialMeshDataEXT* meshes;
} XrSpatialComponentMesh2DListEXT;
Descriptions des membres
typecorrespond au XrStructureType de cette structure.nextestNULLou un pointeur vers la structure suivante dans une chaîne de structures.meshCountest unuint32_tdécrivant le nombre d'éléments dans le tableaumeshes.meshesest un tableau de XrSpatialMeshDataEXT .
Pour interroger le composant de maillage 2D des entités spatiales dans un XrSpatialSnapshotEXT , incluez XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT dans XrSpatialComponentDataQueryConditionEXT :: componentTypes et ajoutez XrSpatialComponentMesh2DListEXT à la chaîne XrSpatialComponentDataQueryResultEXT :: next.
L'environnement d'exécution doit renvoyer XR_ERROR_VALIDATION_FAILURE à partir de xrQuerySpatialComponentDataEXT si XrSpatialComponentMesh2DListEXT se trouve dans la chaîne XrSpatialComponentDataQueryResultEXT :: next, mais que XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT n'est pas inclus dans XrSpatialComponentDataQueryConditionEXT :: componentTypes .
L'environnement d'exécution doit renvoyer XR_ERROR_SIZE_INSUFFICIENT à partir de xrQuerySpatialComponentDataEXT si meshCount est inférieur à XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .
Pour le XrSpatialMeshDataEXT rempli par l'environnement d'exécution dans le tableau meshes, le XrSpatialBufferEXT :: bufferType pour XrSpatialMeshDataEXT :: vertexBuffer doit être XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT et le XrSpatialBufferEXT :: bufferType pour XrSpatialMeshDataEXT :: indexBuffer doit être XR_SPATIAL_BUFFER_TYPE_UINT16_EXT .
Utilisation valide (implicite)
- L'extension
XR_EXT_spatial_plane_trackingdoit être activée avant d'utiliser XrSpatialComponentMesh2DListEXT -
typedoit êtreXR_TYPE_SPATIAL_COMPONENT_MESH_2D_LIST_EXT -
nextdoit êtreNULLou un pointeur valide vers la structure suivante dans une chaîne de structures -
meshesdoit être un pointeur vers un tableau demeshCountstructures XrSpatialMeshDataEXT. - Le paramètre
meshCountdoit être supérieur à0
Configuration
Si XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT est énuméré dans XrSpatialCapabilityComponentTypesEXT :: componentTypes pour une fonctionnalité, une application peut l'activer en incluant l'énumérant dans la liste XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents de la structure dérivée XrSpatialCapabilityConfigurationBaseHeaderEXT de la fonctionnalité compatible avec ce composant.
Ce composant ne nécessite aucune configuration spéciale pour être inclus dans la chaîne XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.
Composant de polygone 2D
Données du composant
La structure XrSpatialPolygon2DDataEXT est définie comme suit :
typedef struct XrSpatialPolygon2DDataEXT {
XrPosef origin;
XrSpatialBufferEXT vertexBuffer;
} XrSpatialPolygon2DDataEXT;
Descriptions des membres
originest un XrPosef définissant l'origine du polygone. Tous les sommets du polygone sont relatifs à cette origine dans le plan X-Y.vertexBufferest un XrSpatialBufferEXT qui fournit l'ID d'un tampon de typeXR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXTet représente le tampon de sommets de l'entité sur laquelle se trouve ce composant. Les sommets doivent être renvoyés dans le sens inverse des aiguilles d'une montre. Le polygone représenté par ces sommets ne doit pas s'auto-intersecter et peut être concave.
XrSpatialBufferEXT :: bufferType pour vertexBuffer doit être XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT .
Utilisation valide (implicite)
- L'extension
XR_EXT_spatial_plane_trackingdoit être activée avant d'utiliser XrSpatialPolygon2DDataEXT -
vertexBufferdoit être une structure XrSpatialBufferEXT valide.
Structure de la liste des composants pour interroger les données
La structure XrSpatialComponentPolygon2DListEXT est définie comme suit :
typedef struct XrSpatialComponentPolygon2DListEXT {
XrStructureType type;
void* next;
uint32_t polygonCount;
XrSpatialPolygon2DDataEXT* polygons;
} XrSpatialComponentPolygon2DListEXT;
Descriptions des membres
typecorrespond au XrStructureType de cette structure.nextestNULLou un pointeur vers la structure suivante dans une chaîne de structures.polygonCountest unuint32_tdécrivant le nombre d'éléments dans le tableaupolygons.polygonsest un tableau de XrSpatialPolygon2DDataEXT .
Pour interroger le composant de polygone 2D des entités spatiales dans un XrSpatialSnapshotEXT , incluez XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT dans XrSpatialComponentDataQueryConditionEXT :: componentTypes et ajoutez XrSpatialComponentPolygon2DListEXT à la chaîne XrSpatialComponentDataQueryResultEXT :: next.
L'environnement d'exécution doit renvoyer XR_ERROR_VALIDATION_FAILURE à partir de xrQuerySpatialComponentDataEXT si XrSpatialComponentPolygon2DListEXT se trouve dans la chaîne XrSpatialComponentDataQueryResultEXT :: next, mais que XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT n'est pas inclus dans XrSpatialComponentDataQueryConditionEXT :: componentTypes .
L'environnement d'exécution doit renvoyer XR_ERROR_SIZE_INSUFFICIENT à partir de xrQuerySpatialComponentDataEXT si polygonCount est inférieur à XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .
Utilisation valide (implicite)
- L'extension
XR_EXT_spatial_plane_trackingdoit être activée avant d'utiliser XrSpatialComponentPolygon2DListEXT -
typedoit êtreXR_TYPE_SPATIAL_COMPONENT_POLYGON_2D_LIST_EXT -
nextdoit êtreNULLou un pointeur valide vers la structure suivante dans une chaîne de structures -
polygonsdoit être un pointeur vers un tableau depolygonCountstructures XrSpatialPolygon2DDataEXT. - Le paramètre
polygonCountdoit être supérieur à0
Configuration
Si XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT est énuméré dans XrSpatialCapabilityComponentTypesEXT :: componentTypes pour une fonctionnalité, une application peut l'activer en incluant l'énumérant dans la liste XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents de la structure dérivée XrSpatialCapabilityConfigurationBaseHeaderEXT de la fonctionnalité compatible avec ce composant.
Ce composant ne nécessite aucune configuration spéciale pour être inclus dans la chaîne XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.
Libellé sémantique de plan
Données du composant
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'énumération XrSpatialPlaneSemanticLabelEXT décrit un ensemble de libellés sémantiques pour les plans.
Description de l'enum
XR_SPATIAL_PLANE_SEMANTIC_LABEL_UNCATEGORIZED_EXT
L'environnement d'exécution n'a pas pu classer cette entité.
XR_SPATIAL_PLANE_SEMANTIC_LABEL_FLOOR_EXT
L'entité est un sol.
XR_SPATIAL_PLANE_SEMANTIC_LABEL_WALL_EXT
L'entité est un mur.
XR_SPATIAL_PLANE_SEMANTIC_LABEL_CEILING_EXT
L'entité est un plafond.
XR_SPATIAL_PLANE_SEMANTIC_LABEL_TABLE_EXT
L'entité est une table.
Structure de la liste des composants pour interroger les données
La structure XrSpatialComponentPlaneSemanticLabelListEXT est définie comme suit :
typedef struct XrSpatialComponentPlaneSemanticLabelListEXT {
XrStructureType type;
void* next;
uint32_t semanticLabelCount;
XrSpatialPlaneSemanticLabelEXT* semanticLabels;
} XrSpatialComponentPlaneSemanticLabelListEXT;
Descriptions des membres
typecorrespond au XrStructureType de cette structure.nextestNULLou un pointeur vers la structure suivante dans une chaîne de structures.semanticLabelCountest unuint32_tdécrivant le nombre d'éléments dans le tableausemanticLabels.semanticLabelsest un tableau de XrSpatialPlaneSemanticLabelEXT .
Pour interroger le composant de libellé sémantique de plan des entités spatiales dans un XrSpatialSnapshotEXT , incluez XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT dans XrSpatialComponentDataQueryConditionEXT :: componentTypes et ajoutez XrSpatialComponentPlaneSemanticLabelListEXT à la chaîne XrSpatialComponentDataQueryResultEXT :: next.
L'environnement d'exécution doit renvoyer XR_ERROR_VALIDATION_FAILURE à partir de xrQuerySpatialComponentDataEXT si XrSpatialComponentPlaneSemanticLabelListEXT se trouve dans la chaîne suivante de XrSpatialComponentDataQueryResultEXT :: next, mais que XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT n'est pas inclus dans XrSpatialComponentDataQueryConditionEXT :: componentTypes .
L'environnement d'exécution doit renvoyer XR_ERROR_SIZE_INSUFFICIENT à partir de xrQuerySpatialComponentDataEXT si semanticLabelCount est inférieur à XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .
Utilisation valide (implicite)
- L'extension
XR_EXT_spatial_plane_trackingdoit être activée avant d'utiliser XrSpatialComponentPlaneSemanticLabelListEXT -
typedoit êtreXR_TYPE_SPATIAL_COMPONENT_PLANE_SEMANTIC_LABEL_LIST_EXT -
nextdoit êtreNULLou un pointeur valide vers la structure suivante dans une chaîne de structures -
semanticLabelsdoit être un pointeur vers un tableau desemanticLabelCountvaleurs XrSpatialPlaneSemanticLabelEXT. - Le paramètre
semanticLabelCountdoit être supérieur à0
Configuration
Si XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT est énuméré dans XrSpatialCapabilityComponentTypesEXT :: componentTypes pour une fonctionnalité, une application peut l'activer en incluant l'énumérant dans la liste XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents de la structure dérivée XrSpatialCapabilityConfigurationBaseHeaderEXT de la fonctionnalité compatible avec ce composant.
Ce composant ne nécessite aucune configuration spéciale pour être inclus dans la chaîne XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.
Exemple de code
Configurer la fonctionnalité de suivi de plan
L'exemple de code suivant montre comment configurer la fonctionnalité de suivi de plan lors de la création d'un contexte spatial.
// 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));
Découvrir des entités spatiales et interroger les données des composants
L'exemple de code suivant montre comment découvrir des entités spatiales pour un contexte configuré avec XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT et interroger les données de ses composants.
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
// ...
}
Nouvelles structures
- XrSpatialCapabilityConfigurationPlaneTrackingEXT
- XrSpatialPolygon2DDataEXT
Extension de XrSpatialComponentDataQueryResultEXT :
Nouveaux enums
Nouvelles constantes d'enum
XR_EXT_SPATIAL_PLANE_TRACKING_EXTENSION_NAMEXR_EXT_spatial_plane_tracking_SPEC_VERSIONExtension de XrSpatialCapabilityEXT :
XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT
Extension 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
Extension 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
Problèmes
Historique des versions
Révision 1, 02/07/2024 (Nihav Jain, Google)
- Description initiale de l'extension