[Bf-blender-cvs] [abd81d76d2d] xr-dev: XR: Enable (selectively) Vive Tracker extension

Peter Kim noreply at git.blender.org
Wed Feb 23 08:48:53 CET 2022


Commit: abd81d76d2d35428bc0c73e60d9164abda902975
Author: Peter Kim
Date:   Wed Feb 23 16:46:17 2022 +0900
Branches: xr-dev
https://developer.blender.org/rBabd81d76d2d35428bc0c73e60d9164abda902975

XR: Enable (selectively) Vive Tracker extension

Allows action bindings for the HTC Vive Trackers, so that their poses
can be queried and used for motion capture objects. For details on the
available tracker roles/user path identifiers, see: https://www.khronos.org/registry/OpenXR/specs/1.0/html/xrspec.html#XR_HTCX_vive_tracker_interaction

Currently the extension is only supported by the SteamVR runtime (1.21)
and there a few issues (which could be on the Blender or SteamVR side),
such as incorrect controller poses when the extension is enabled.

For this reason, the tracker extension is added as a session option to
enable only when one wants to exclusively use trackers instead of
controllers.

===================================================================

M	intern/ghost/GHOST_Types.h
M	intern/ghost/intern/GHOST_XrContext.cpp
M	intern/ghost/intern/GHOST_XrContext.h
M	source/blender/makesdna/DNA_xr_types.h
M	source/blender/makesrna/intern/rna_xr.c
M	source/blender/windowmanager/xr/intern/wm_xr.c

===================================================================

diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index c654367072f..fb532b4c1fa 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -647,6 +647,10 @@ enum {
    * (use DirectX fallback instead). */
   GHOST_kXrContextGpuNVIDIA = (1 << 2),
 #  endif
+  /* Needed to selectively enable the #XR_HTCX_vive_tracker_interaction extension, as it causes
+     incorrect controller poses with SteamVR (1.21). Although not ideal, either trackers or
+     controllers (but not both) can be used during a given session. */
+  GHOST_kXrContextEnableViveTrackerExtension = (1 << 3),
 };
 
 typedef struct {
diff --git a/intern/ghost/intern/GHOST_XrContext.cpp b/intern/ghost/intern/GHOST_XrContext.cpp
index 716b60799f9..4a7f833a25b 100644
--- a/intern/ghost/intern/GHOST_XrContext.cpp
+++ b/intern/ghost/intern/GHOST_XrContext.cpp
@@ -82,7 +82,7 @@ void GHOST_XrContext::initialize(const GHOST_XrContextCreateInfo *create_info)
       determineGraphicsBindingTypesToEnable(create_info);
 
   assert(m_oxr->instance == XR_NULL_HANDLE);
-  createOpenXRInstance(graphics_binding_types);
+  createOpenXRInstance(graphics_binding_types, create_info);
   storeInstanceProperties();
 
   /* Multiple bindings may be enabled. Now that we know the runtime in use, settle for one. */
@@ -95,7 +95,8 @@ void GHOST_XrContext::initialize(const GHOST_XrContextCreateInfo *create_info)
 }
 
 void GHOST_XrContext::createOpenXRInstance(
-    const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types)
+    const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types,
+    const GHOST_XrContextCreateInfo *ctx_create_info)
 {
   XrInstanceCreateInfo create_info = {XR_TYPE_INSTANCE_CREATE_INFO};
 
@@ -104,7 +105,7 @@ void GHOST_XrContext::createOpenXRInstance(
   create_info.applicationInfo.apiVersion = XR_CURRENT_API_VERSION;
 
   getAPILayersToEnable(m_enabled_layers);
-  getExtensionsToEnable(graphics_binding_types, m_enabled_extensions);
+  getExtensionsToEnable(graphics_binding_types, ctx_create_info, m_enabled_extensions);
   create_info.enabledApiLayerCount = m_enabled_layers.size();
   create_info.enabledApiLayerNames = m_enabled_layers.data();
   create_info.enabledExtensionCount = m_enabled_extensions.size();
@@ -400,6 +401,7 @@ static const char *openxr_ext_name_from_wm_gpu_binding(GHOST_TXrGraphicsBinding
  */
 void GHOST_XrContext::getExtensionsToEnable(
     const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types,
+    const GHOST_XrContextCreateInfo *create_info,
     std::vector<const char *> &r_ext_names)
 {
   std::vector<std::string_view> try_ext;
@@ -412,7 +414,14 @@ void GHOST_XrContext::getExtensionsToEnable(
   /* Interaction profile extensions. */
   try_ext.push_back(XR_EXT_HP_MIXED_REALITY_CONTROLLER_EXTENSION_NAME);
   try_ext.push_back(XR_HTC_VIVE_COSMOS_CONTROLLER_INTERACTION_EXTENSION_NAME);
+#ifdef XR_HTC_VIVE_FOCUS3_CONTROLLER_INTERACTION_EXTENSION_NAME
   try_ext.push_back(XR_HTC_VIVE_FOCUS3_CONTROLLER_INTERACTION_EXTENSION_NAME);
+#endif
+  if ((create_info->context_flag & GHOST_kXrContextEnableViveTrackerExtension) != 0) {
+#ifdef XR_HTCX_VIVE_TRACKER_INTERACTION_EXTENSION_NAME
+    try_ext.push_back(XR_HTCX_VIVE_TRACKER_INTERACTION_EXTENSION_NAME);
+#endif
+  }
   try_ext.push_back(XR_HUAWEI_CONTROLLER_INTERACTION_EXTENSION_NAME);
 
   /* Controller model extension. */
diff --git a/intern/ghost/intern/GHOST_XrContext.h b/intern/ghost/intern/GHOST_XrContext.h
index 6eac4284e43..435454397cf 100644
--- a/intern/ghost/intern/GHOST_XrContext.h
+++ b/intern/ghost/intern/GHOST_XrContext.h
@@ -108,7 +108,8 @@ class GHOST_XrContext : public GHOST_IXrContext {
   bool m_debug = false;
   bool m_debug_time = false;
 
-  void createOpenXRInstance(const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types);
+  void createOpenXRInstance(const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types,
+                            const GHOST_XrContextCreateInfo *create_info);
   void storeInstanceProperties();
   void initDebugMessenger();
 
@@ -122,6 +123,7 @@ class GHOST_XrContext : public GHOST_IXrContext {
   void initExtensionsEx(std::vector<XrExtensionProperties> &extensions, const char *layer_name);
   void getAPILayersToEnable(std::vector<const char *> &r_ext_names);
   void getExtensionsToEnable(const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types,
+                             const GHOST_XrContextCreateInfo *create_info,
                              std::vector<const char *> &r_ext_names);
   std::vector<GHOST_TXrGraphicsBinding> determineGraphicsBindingTypesToEnable(
       const GHOST_XrContextCreateInfo *create_info);
diff --git a/source/blender/makesdna/DNA_xr_types.h b/source/blender/makesdna/DNA_xr_types.h
index 457bf44f3b8..6097dfcfe7e 100644
--- a/source/blender/makesdna/DNA_xr_types.h
+++ b/source/blender/makesdna/DNA_xr_types.h
@@ -50,6 +50,8 @@ typedef struct XrSessionSettings {
 typedef enum eXrSessionFlag {
   XR_SESSION_USE_POSITION_TRACKING = (1 << 0),
   XR_SESSION_USE_ABSOLUTE_TRACKING = (1 << 1),
+  XR_SESSION_ENABLE_VIVE_TRACKER_EXTENSION =
+      (1 << 2), /* See #GHOST_kXrContextEnableViveTrackerExtension. */
 } eXrSessionFlag;
 
 typedef enum eXRSessionBasePoseType {
diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c
index a606e57ba58..c405e01f4dc 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -822,6 +822,27 @@ static void rna_XrSessionSettings_use_absolute_tracking_set(PointerRNA *ptr, boo
 #  endif
 }
 
+static bool rna_XrSessionSettings_enable_vive_tracker_extension_get(PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  const wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
+  return (xr->session_settings.flag & XR_SESSION_ENABLE_VIVE_TRACKER_EXTENSION) != 0;
+#  else
+  UNUSED_VARS(ptr);
+  return false;
+#  endif
+}
+
+static void rna_XrSessionSettings_enable_vive_tracker_extension_set(PointerRNA *ptr, bool value)
+{
+#  ifdef WITH_XR_OPENXR
+  wmXrData *xr = rna_XrSession_wm_xr_data_get(ptr);
+  SET_FLAG_FROM_TEST(xr->session_settings.flag, value, XR_SESSION_ENABLE_VIVE_TRACKER_EXTENSION);
+#  else
+  UNUSED_VARS(ptr, value);
+#  endif
+}
+
 static void rna_XrSessionSettings_actionmaps_begin(CollectionPropertyIterator *iter,
                                                    PointerRNA *ptr)
 {
@@ -2182,6 +2203,16 @@ static void rna_def_xr_session_settings(BlenderRNA *brna)
       "Allow the VR tracking origin to be defined independently of the headset location");
   RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
 
+  prop = RNA_def_property(srna, "enable_vive_tracker_extension", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_funcs(prop,
+                                 "rna_XrSessionSettings_enable_vive_tracker_extension_get",
+                                 "rna_XrSessionSettings_enable_vive_tracker_extension_set");
+  RNA_def_property_ui_text(prop,
+                           "Enable Vive Tracker Extension",
+                           "Enable bindings for the HTC Vive Trackers. Note that this may not be "
+                           "supported by all OpenXR runtimes");
+  RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
+
   prop = RNA_def_property(srna, "actionmaps", PROP_COLLECTION, PROP_NONE);
   RNA_def_property_collection_funcs(prop,
                                     "rna_XrSessionSettings_actionmaps_begin",
diff --git a/source/blender/windowmanager/xr/intern/wm_xr.c b/source/blender/windowmanager/xr/intern/wm_xr.c
index 5b7a86f65f4..c4427898d3a 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr.c
@@ -90,6 +90,9 @@ bool wm_xr_init(wmWindowManager *wm)
       create_info.context_flag |= GHOST_kXrContextGpuNVIDIA;
     }
 #endif
+    if ((wm->xr.session_settings.flag & XR_SESSION_ENABLE_VIVE_TRACKER_EXTENSION) != 0) {
+      create_info.context_flag |= GHOST_kXrContextEnableViveTrackerExtension;
+    }
 
     if (!(context = GHOST_XrContextCreate(&create_info))) {
       return false;



More information about the Bf-blender-cvs mailing list