XR_EXT_spatial_plane_tracking

سلسلة الاسم

XR_EXT_spatial_plane_tracking

نوع الإضافة

إضافة مثيل

رقم الإضافة المسجَّل

742

المراجعة

1

حالة التصديق

تم التصديق عليه

الاعتماديات على الإضافات والإصدارات

XR_EXT_spatial_entity

المساهمون

نيهات جين، Google
ناتالي فلوري، Meta
يويتشي تاغوتشي، Meta
رون بيسيمز، Meta
يين لي، Microsoft
جيمي ألامبارامبيل، ByteDance
تشيبينغ ليو، ByteDance
جون يان، ByteDance

نظرة عامة

تستند هذه الإضافة إلى XR_EXT_spatial_entity وتحدّد إمكانية تتبُّع المستوى المكاني لإطار الكيانات المكانية.

دعم وقت التشغيل

إذا كان وقت التشغيل يتيح تتبُّع الطائرات، يجب أن يشير إلى ذلك من خلال تعداد XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT في xrEnumerateSpatialCapabilitiesEXT .

الإعداد

يتم تعريف بنية XrSpatialCapabilityConfigurationPlaneTrackingEXT على النحو التالي:

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

أوصاف الأعضاء

  • type هو XrStructureType لهذه البنية.
  • next هي NULL أو مؤشر إلى البنية التالية في سلسلة البنية.
  • capability هو XrSpatialCapabilityEXT ويجب أن يكون XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT .
  • enabledComponentCount هو uint32_t يصف عدد العناصر في مصفوفة enabledComponents.
  • enabledComponents هو مؤشر إلى مصفوفة من XrSpatialComponentTypeEXT .

يمكن للتطبيقات تفعيل إمكانية XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT المكانية من خلال تضمين مؤشر إلى بنية XrSpatialCapabilityConfigurationPlaneTrackingEXT في XrSpatialContextCreateInfoEXT :: capabilityConfigs .

يجب أن تعرض قيمة وقت التشغيل XR_ERROR_VALIDATION_FAILURE إذا لم تكن قيمة capability هي XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT .

الاستخدام الصحيح (الضمني)

المكوّنات المضمونة

يجب أن يوفّر وقت التشغيل الذي يتوافق مع XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT المكوّنات المكانية التالية كمكوّنات مضمونة لجميع الكيانات التي يتم رصدها من خلال هذه الإمكانية، ويجب أن يسردها في xrEnumerateSpatialCapabilityComponentTypesEXT :

  • XR_SPATIAL_COMPONENT_TYPE_BOUNDED_2D_EXT
  • XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT

مكوّن ثنائي الأبعاد محدود

يوفّر المكوّن الثنائي الأبعاد المحدود المركز ومدى المستوى الذي يمثّله العنصر الذي يقع عليه. لمزيد من التفاصيل، يُرجى الاطّلاع على الرسومات الثنائية الأبعاد المحدودة.

مكوّن محاذاة المستوى

بيانات المكوّن

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;

يصف التعداد XrSpatialPlaneAlignmentEXT محاذاة المستوى المرتبط بالكيان المكاني مع أحد مكوّنات XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT.

تحمل قيم التعداد المعاني التالية:

وصف التعداد

XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_UPWARD_EXT

يكون العنصر أفقيًا ومتجهًا للأعلى (مثل الأرضية).

XR_SPATIAL_PLANE_ALIGNMENT_HORIZONTAL_DOWNWARD_EXT

يكون العنصر أفقيًا وموجّهًا للأسفل (مثل السقف).

XR_SPATIAL_PLANE_ALIGNMENT_VERTICAL_EXT

يكون العنصر عموديًا (مثل جدار).

XR_SPATIAL_PLANE_ALIGNMENT_ARBITRARY_EXT

للكيان اتجاه عشوائي غير عمودي وغير أفقي.

بنية قائمة المكوّنات لطلب البيانات

يتم تعريف بنية XrSpatialComponentPlaneAlignmentListEXT على النحو التالي:

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

أوصاف الأعضاء

  • type هو XrStructureType لهذه البنية.
  • next هي NULL أو مؤشر إلى البنية التالية في سلسلة البنية.
  • planeAlignmentCount هو uint32_t يصف عدد العناصر في مصفوفة planeAlignments.
  • planeAlignments هي مصفوفة من XrSpatialPlaneAlignmentEXT .

للاستعلام عن مكوّن محاذاة المستوى الخاص بالكيانات المكانية في XrSpatialSnapshotEXT، أدرِج XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT في XrSpatialComponentDataQueryConditionEXT :: componentTypes وأضِف XrSpatialComponentPlaneAlignmentListEXT إلى سلسلة XrSpatialComponentDataQueryResultEXT :: next.

يجب أن يعرض وقت التشغيل XR_ERROR_VALIDATION_FAILURE من xrQuerySpatialComponentDataEXT إذا كان XrSpatialComponentPlaneAlignmentListEXT في سلسلة XrSpatialComponentDataQueryResultEXT :: next ولكن لم يتم تضمين XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT في XrSpatialComponentDataQueryConditionEXT :: componentTypes .

يجب أن تعرض بيئة التشغيل القيمة XR_ERROR_SIZE_INSUFFICIENT من xrQuerySpatialComponentDataEXT إذا كانت قيمة planeAlignmentCount أقل من XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .

الاستخدام الصحيح (الضمني)

الإعداد

إذا تم تعداد XR_SPATIAL_COMPONENT_TYPE_PLANE_ALIGNMENT_EXT في XrSpatialCapabilityComponentTypesEXT :: componentTypes لبعض الإمكانات، يمكن لأحد التطبيقات تفعيلها من خلال تضمين القيمة المُعدَّدة في قائمة XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents الخاصة ببنية XrSpatialCapabilityConfigurationBaseHeaderEXT المشتقة من الإمكانية التي تتوافق مع هذا المكوّن.

لا يتطلّب هذا المكوّن أي إعدادات خاصة ليتم تضمينه في سلسلة XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.

المكوِّنات الاختيارية

قد يتيح وقت التشغيل الذي يتوافق مع XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT استخدام مكوّنات مكانية أخرى بالإضافة إلى تلك المُدرَجة في قسم المكوّنات المضمونة. يستخدم التطبيق xrEnumerateSpatialCapabilityComponentTypesEXT للحصول على القائمة الكاملة بالمكوّنات التي يتيحها وقت التشغيل، ثم يضبط المكوّنات التي تهمه عند إنشاء السياق المكاني.

مكوّن Mesh 2D

بيانات المكوّن

تستخدم XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT بنية XrSpatialMeshDataEXT لبياناتها.

بنية قائمة المكوّنات لطلب البيانات

يتم تعريف بنية XrSpatialComponentMesh2DListEXT على النحو التالي:

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

أوصاف الأعضاء

  • type هو XrStructureType لهذه البنية.
  • next هي NULL أو مؤشر إلى البنية التالية في سلسلة البنية.
  • meshCount هو uint32_t يصف عدد العناصر في مصفوفة meshes.
  • meshes هي مصفوفة من XrSpatialMeshDataEXT .

للاستعلام عن مكوّن شبكة ثنائية الأبعاد للكيانات المكانية في XrSpatialSnapshotEXT، أدرِج XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT في XrSpatialComponentDataQueryConditionEXT :: componentTypes وأضِف XrSpatialComponentMesh2DListEXT إلى سلسلة XrSpatialComponentDataQueryResultEXT :: next.

يجب أن تعرض بيئة التشغيل XR_ERROR_VALIDATION_FAILURE من xrQuerySpatialComponentDataEXT إذا كان XrSpatialComponentMesh2DListEXT في سلسلة XrSpatialComponentDataQueryResultEXT :: next ولكن لم يتم تضمين XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT في XrSpatialComponentDataQueryConditionEXT :: componentTypes .

يجب أن تعرض بيئة التشغيل القيمة XR_ERROR_SIZE_INSUFFICIENT من xrQuerySpatialComponentDataEXT إذا كانت قيمة meshCount أقل من XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .

بالنسبة إلى XrSpatialMeshDataEXT التي يملأها وقت التشغيل في مصفوفة meshes، يجب أن تكون bufferType الخاصة بـ XrSpatialBufferEXT هي XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT بالنسبة إلى vertexBuffer الخاصة بـ XrSpatialMeshDataEXT، ويجب أن تكون bufferType الخاصة بـ XrSpatialBufferEXT هي XR_SPATIAL_BUFFER_TYPE_UINT16_EXT بالنسبة إلى indexBuffer الخاصة بـ XrSpatialMeshDataEXT .

الاستخدام الصحيح (الضمني)

الإعداد

إذا تم تعداد XR_SPATIAL_COMPONENT_TYPE_MESH_2D_EXT في XrSpatialCapabilityComponentTypesEXT :: componentTypes لبعض الإمكانات، يمكن لأحد التطبيقات تفعيلها من خلال تضمين القيمة المُعدَّدة في قائمة XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents الخاصة ببنية XrSpatialCapabilityConfigurationBaseHeaderEXT المشتقة من الإمكانية التي تتوافق مع هذا المكوّن.

لا يتطلّب هذا المكوّن أي إعدادات خاصة ليتم تضمينه في سلسلة XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.

مكوِّن المضلّع الثنائي الأبعاد

بيانات المكوّن

يتم تعريف بنية XrSpatialPolygon2DDataEXT على النحو التالي:

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

أوصاف الأعضاء

  • origin هو XrPosef يحدّد مصدر المضلّع. تكون جميع رؤوس المضلّع مرتبطة بهذا الأصل في المستوى X-Y.
  • vertexBuffer هو XrSpatialBufferEXT يوفّر معرّفًا لمخزن مؤقت من النوع XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT ويمثّل مخزن مؤقت للرؤوس خاصًا بالكيان الذي يتضمّن هذا المكوّن. يجب عرض الرؤوس بترتيب عكس اتجاه عقارب الساعة. يجب ألّا يتقاطع المضلّع الممثّل بهذه الرؤوس ذاتيًا، ويجوز أن يكون مقعّرًا.

XrSpatialBufferEXT :: bufferType بالنسبة إلى vertexBuffer يجب أن تكون XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT .

الاستخدام الصحيح (الضمني)

بنية قائمة المكوّنات لطلب البيانات

يتم تعريف بنية XrSpatialComponentPolygon2DListEXT على النحو التالي:

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

أوصاف الأعضاء

  • type هو XrStructureType لهذه البنية.
  • next هي NULL أو مؤشر إلى البنية التالية في سلسلة البنية.
  • polygonCount هو uint32_t يصف عدد العناصر في مصفوفة polygons.
  • polygons هي مجموعة من XrSpatialPolygon2DDataEXT .

للاستعلام عن مضلّع ثنائي الأبعاد خاص بالكيانات المكانية في XrSpatialSnapshotEXT، أدرِج XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT في XrSpatialComponentDataQueryConditionEXT :: componentTypes وأضِف XrSpatialComponentPolygon2DListEXT إلى سلسلة XrSpatialComponentDataQueryResultEXT :: next.

يجب أن تعرض وقت التشغيل XR_ERROR_VALIDATION_FAILURE من xrQuerySpatialComponentDataEXT إذا كان XrSpatialComponentPolygon2DListEXT في سلسلة XrSpatialComponentDataQueryResultEXT :: next ولكن لم يتم تضمين XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT في XrSpatialComponentDataQueryConditionEXT :: componentTypes .

يجب أن تعرض بيئة التشغيل القيمة XR_ERROR_SIZE_INSUFFICIENT من xrQuerySpatialComponentDataEXT إذا كانت قيمة polygonCount أقل من XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .

الاستخدام الصحيح (الضمني)

الإعداد

إذا تم تعداد XR_SPATIAL_COMPONENT_TYPE_POLYGON_2D_EXT في XrSpatialCapabilityComponentTypesEXT :: componentTypes لبعض الإمكانات، يمكن لأحد التطبيقات تفعيلها من خلال تضمين القيمة المُعدَّدة في قائمة XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents الخاصة ببنية XrSpatialCapabilityConfigurationBaseHeaderEXT المشتقة من الإمكانية التي تتوافق مع هذا المكوّن.

لا يتطلّب هذا المكوّن أي إعدادات خاصة ليتم تضمينه في سلسلة XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.

التصنيف الدلالي للطائرة

بيانات المكوّن

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;

يصف التعداد XrSpatialPlaneSemanticLabelEXT مجموعة من التصنيفات الدلالية للمستويات.

وصف التعداد

XR_SPATIAL_PLANE_SEMANTIC_LABEL_UNCATEGORIZED_EXT

تعذّر على وقت التشغيل تصنيف هذا العنصر.

XR_SPATIAL_PLANE_SEMANTIC_LABEL_FLOOR_EXT

تمثّل هذه السمة طابقًا.

XR_SPATIAL_PLANE_SEMANTIC_LABEL_WALL_EXT

تمثّل هذه السمة جدارًا.

XR_SPATIAL_PLANE_SEMANTIC_LABEL_CEILING_EXT

الكيان هو سقف.

XR_SPATIAL_PLANE_SEMANTIC_LABEL_TABLE_EXT

الكيان هو جدول.

بنية قائمة المكوّنات للاستعلام عن البيانات

يتم تعريف بنية XrSpatialComponentPlaneSemanticLabelListEXT على النحو التالي:

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

أوصاف الأعضاء

  • type هو XrStructureType لهذه البنية.
  • next هي NULL أو مؤشر إلى البنية التالية في سلسلة البنية.
  • semanticLabelCount هو uint32_t يصف عدد العناصر في مصفوفة semanticLabels.
  • semanticLabels هي مصفوفة من XrSpatialPlaneSemanticLabelEXT .

للاستعلام عن مكوّن التصنيف الدلالي الخاص بالطائرة للكيانات المكانية في XrSpatialSnapshotEXT، أدرِج XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT في XrSpatialComponentDataQueryConditionEXT :: componentTypes وأضِف XrSpatialComponentPlaneSemanticLabelListEXT إلى سلسلة XrSpatialComponentDataQueryResultEXT :: next.

يجب أن تعرض بيئة التشغيل القيمة XR_ERROR_VALIDATION_FAILURE من xrQuerySpatialComponentDataEXT إذا كان XrSpatialComponentPlaneSemanticLabelListEXT في السلسلة التالية من XrSpatialComponentDataQueryResultEXT :: next ولكن لم يتم تضمين XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT في XrSpatialComponentDataQueryConditionEXT :: componentTypes .

يجب أن تعرض بيئة التشغيل القيمة XR_ERROR_SIZE_INSUFFICIENT من xrQuerySpatialComponentDataEXT إذا كانت قيمة semanticLabelCount أقل من XrSpatialComponentDataQueryResultEXT :: entityIdCountOutput .

الاستخدام الصحيح (الضمني)

الإعداد

إذا تم تعداد XR_SPATIAL_COMPONENT_TYPE_PLANE_SEMANTIC_LABEL_EXT في XrSpatialCapabilityComponentTypesEXT :: componentTypes لبعض الإمكانات، يمكن لأحد التطبيقات تفعيلها من خلال تضمين القيمة المُعدَّدة في قائمة XrSpatialCapabilityConfigurationBaseHeaderEXT :: enabledComponents الخاصة ببنية XrSpatialCapabilityConfigurationBaseHeaderEXT المشتقة من الإمكانية التي تتوافق مع هذا المكوّن.

لا يتطلّب هذا المكوّن أي إعدادات خاصة ليتم تضمينه في سلسلة XrSpatialCapabilityConfigurationBaseHeaderEXT :: next.

مثال على الشفرة

ضبط إمكانية تتبُّع الطائرات

يوضّح نموذج الرمز البرمجي التالي كيفية ضبط إمكانية تتبُّع الطائرة عند إنشاء سياق مكاني.

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

استكشاف الكيانات المكانية والاستعلام عن بيانات المكوّنات

يوضّح نموذج الرمز التالي كيفية العثور على عناصر مكانية لسياق تم إعداده باستخدام XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT وطلب بيانات المكوّنات الخاصة به.

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

بنى جديدة

عمليات التعداد الجديدة

ثوابت التعداد الجديدة

  • XR_EXT_SPATIAL_PLANE_TRACKING_EXTENSION_NAME
  • XR_EXT_spatial_plane_tracking_SPEC_VERSION
  • تمديد XrSpatialCapabilityEXT :

    • XR_SPATIAL_CAPABILITY_PLANE_TRACKING_EXT
  • تمديد 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
  • تمديد 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

المشاكل

سجلّ الإصدارات

  • المراجعة 1، ‎02-07-2024 (Nihav Jain، Google)

    • الوصف الأوّلي للإضافة