XR_EXT_spatial_plane_tracking

Name String

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

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

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

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

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

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، يجب أن تكون قيمة XrSpatialBufferEXT :: bufferType لـ XrSpatialMeshDataEXT :: vertexBuffer هي XR_SPATIAL_BUFFER_TYPE_VECTOR2F_EXT ويجب أن تكون قيمة XrSpatialBufferEXT :: bufferType لـ XrSpatialMeshDataEXT :: indexBuffer هي XR_SPATIAL_BUFFER_TYPE_UINT16_EXT .

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

الإعداد

إذا تم تعداد 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، بتاريخ ‎2024-07-02 (نيهف جين، Google)

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