[Bf-blender-cvs] [6b67760bd8f] xr-controller-support: XR: Refactor action maps, bindings

Peter Kim noreply at git.blender.org
Wed Jul 28 06:08:37 CEST 2021


Commit: 6b67760bd8fb20357ecc86782cf5449d35c38d27
Author: Peter Kim
Date:   Wed Jul 28 13:02:37 2021 +0900
Branches: xr-controller-support
https://developer.blender.org/rB6b67760bd8fb20357ecc86782cf5449d35c38d27

XR: Refactor action maps, bindings

This removes the previous limitation of one interaction profile
(device) per action map by moving the profiles to action bindings.
By doing so, there is no longer the need for users to manually select
an action map, as the XR runtime will automatically select the most
appropriate profile.

An additional DNA action map layer, "XrActionMapBinding", was also
added to store profiles and input-specific properties for actions,
allowing for flexible inputs across devices.

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

M	intern/ghost/GHOST_C-api.h
M	intern/ghost/GHOST_Types.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_XrAction.cpp
M	intern/ghost/intern/GHOST_XrAction.h
M	intern/ghost/intern/GHOST_XrSession.cpp
M	intern/ghost/intern/GHOST_XrSession.h
M	source/blender/makesdna/DNA_xr_types.h
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_xr.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm.c
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/xr/intern/wm_xr_action.c
M	source/blender/windowmanager/xr/intern/wm_xr_actionmap.c
M	source/blender/windowmanager/xr/intern/wm_xr_intern.h
M	source/blender/windowmanager/xr/intern/wm_xr_session.c

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

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 3e80d23de7f..bd145f34956 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -1066,22 +1066,6 @@ void GHOST_XrDestroyActions(GHOST_XrContextHandle xr_context,
                             uint32_t count,
                             const char *const *action_names);
 
-/**
- * Create spaces for pose-based OpenXR actions.
- */
-int GHOST_XrCreateActionSpaces(GHOST_XrContextHandle xr_context,
-                               const char *action_set_name,
-                               uint32_t count,
-                               const GHOST_XrActionSpaceInfo *infos);
-
-/**
- * Destroy previously created spaces for OpenXR actions.
- */
-void GHOST_XrDestroyActionSpaces(GHOST_XrContextHandle xr_context,
-                                 const char *action_set_name,
-                                 uint32_t count,
-                                 const GHOST_XrActionSpaceInfo *infos);
-
 /**
  * Create input/output path bindings for OpenXR actions.
  */
@@ -1096,7 +1080,8 @@ int GHOST_XrCreateActionBindings(GHOST_XrContextHandle xr_context,
 void GHOST_XrDestroyActionBindings(GHOST_XrContextHandle xr_context,
                                    const char *action_set_name,
                                    uint32_t count,
-                                   const GHOST_XrActionProfileInfo *infos);
+                                   const char *const *action_names,
+                                   const char *const *profile_paths);
 
 /**
  * Attach all created action sets to the current OpenXR session.
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 3bad4f6326c..34bf55dffca 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -719,29 +719,27 @@ typedef struct GHOST_XrActionInfo {
   const char **subaction_paths;
   /** States for each subaction path. */
   void *states;
+  /** Input thresholds/regions for each subaction path. */
+  float *float_thresholds;
+  int16_t *axis_flags;
 
   GHOST_XrCustomdataFreeFn customdata_free_fn;
   void *customdata; /* wmXrAction */
 } GHOST_XrActionInfo;
 
-typedef struct GHOST_XrActionSpaceInfo {
-  const char *action_name;
-  uint32_t count_subaction_paths;
-  const char **subaction_paths;
-  /** Poses for each subaction path. */
-  const GHOST_XrPose *poses;
-} GHOST_XrActionSpaceInfo;
-
 typedef struct GHOST_XrActionBindingInfo {
-  const char *action_name;
-  uint32_t count_interaction_paths;
-  /** Interaction path: User (sub-action) path + component path. */
-  const char **interaction_paths;
+  const char *component_path;
+  float float_threshold;
+  int16_t axis_flag;
+  GHOST_XrPose pose;
 } GHOST_XrActionBindingInfo;
 
 typedef struct GHOST_XrActionProfileInfo {
+  const char *action_name;
   const char *profile_path;
-  uint32_t count_bindings;
+  uint32_t count_subaction_paths;
+  const char **subaction_paths;
+  /* Bindings for each subaction path. */
   const GHOST_XrActionBindingInfo *bindings;
 } GHOST_XrActionProfileInfo;
 
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index cfa8e731592..22335994ae6 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -961,28 +961,6 @@ void GHOST_XrDestroyActions(GHOST_XrContextHandle xr_contexthandle,
   GHOST_XR_CAPI_CALL(xr_session->destroyActions(action_set_name, count, action_names), xr_context);
 }
 
-int GHOST_XrCreateActionSpaces(GHOST_XrContextHandle xr_contexthandle,
-                               const char *action_set_name,
-                               uint32_t count,
-                               const GHOST_XrActionSpaceInfo *infos)
-{
-  GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
-  GHOST_XrSession *xr_session = xr_context->getSession();
-  GHOST_XR_CAPI_CALL_RET(xr_session->createActionSpaces(action_set_name, count, infos),
-                         xr_context);
-  return 0;
-}
-
-void GHOST_XrDestroyActionSpaces(GHOST_XrContextHandle xr_contexthandle,
-                                 const char *action_set_name,
-                                 uint32_t count,
-                                 const GHOST_XrActionSpaceInfo *infos)
-{
-  GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
-  GHOST_XrSession *xr_session = xr_context->getSession();
-  GHOST_XR_CAPI_CALL(xr_session->destroyActionSpaces(action_set_name, count, infos), xr_context);
-}
-
 int GHOST_XrCreateActionBindings(GHOST_XrContextHandle xr_contexthandle,
                                  const char *action_set_name,
                                  uint32_t count,
@@ -998,11 +976,14 @@ int GHOST_XrCreateActionBindings(GHOST_XrContextHandle xr_contexthandle,
 void GHOST_XrDestroyActionBindings(GHOST_XrContextHandle xr_contexthandle,
                                    const char *action_set_name,
                                    uint32_t count,
-                                   const GHOST_XrActionProfileInfo *infos)
+                                   const char *const *action_names,
+                                   const char *const *profile_paths)
 {
   GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
   GHOST_XrSession *xr_session = xr_context->getSession();
-  GHOST_XR_CAPI_CALL(xr_session->destroyActionBindings(action_set_name, count, infos), xr_context);
+  GHOST_XR_CAPI_CALL(
+      xr_session->destroyActionBindings(action_set_name, count, action_names, profile_paths),
+      xr_context);
 }
 
 int GHOST_XrAttachActionSets(GHOST_XrContextHandle xr_contexthandle)
diff --git a/intern/ghost/intern/GHOST_XrAction.cpp b/intern/ghost/intern/GHOST_XrAction.cpp
index 997fc75a8a8..e7941744755 100644
--- a/intern/ghost/intern/GHOST_XrAction.cpp
+++ b/intern/ghost/intern/GHOST_XrAction.cpp
@@ -35,21 +35,20 @@
 GHOST_XrActionSpace::GHOST_XrActionSpace(XrInstance instance,
                                          XrSession session,
                                          XrAction action,
-                                         const GHOST_XrActionSpaceInfo &info,
-                                         uint32_t subaction_idx)
+                                         const char *action_name,
+                                         const char *profile_path,
+                                         XrPath subaction_path,
+                                         const char *subaction_path_str,
+                                         const GHOST_XrPose &pose)
 {
-  const char *subaction_path = info.subaction_paths[subaction_idx];
-  CHECK_XR(xrStringToPath(instance, subaction_path, &m_subaction_path),
-           (std::string("Failed to get user path \"") + subaction_path + "\".").data());
-
   XrActionSpaceCreateInfo action_space_info{XR_TYPE_ACTION_SPACE_CREATE_INFO};
   action_space_info.action = action;
-  action_space_info.subactionPath = m_subaction_path;
-  copy_ghost_pose_to_openxr_pose(info.poses[subaction_idx], action_space_info.poseInActionSpace);
+  action_space_info.subactionPath = subaction_path;
+  copy_ghost_pose_to_openxr_pose(pose, action_space_info.poseInActionSpace);
 
   CHECK_XR(xrCreateActionSpace(session, &action_space_info, &m_space),
-           (std::string("Failed to create space \"") + subaction_path + "\" for action \"" +
-            info.action_name + "\".")
+           (std::string("Failed to create space \"") + subaction_path_str + "\" for action \"" +
+            action_name + "\" and profile \"" + profile_path + "\".")
                .data());
 }
 
@@ -65,11 +64,6 @@ XrSpace GHOST_XrActionSpace::getSpace() const
   return m_space;
 }
 
-const XrPath &GHOST_XrActionSpace::getSubactionPath() const
-{
-  return m_subaction_path;
-}
-
 /** \} */
 
 /* -------------------------------------------------------------------- */
@@ -78,13 +72,19 @@ const XrPath &GHOST_XrActionSpace::getSubactionPath() const
  * \{ */
 
 GHOST_XrActionProfile::GHOST_XrActionProfile(XrInstance instance,
+                                             XrSession session,
                                              XrAction action,
-                                             const char *profile_path,
-                                             const GHOST_XrActionBindingInfo &info)
+                                             GHOST_XrActionType type,
+                                             const GHOST_XrActionProfileInfo &info)
 {
-  CHECK_XR(
-      xrStringToPath(instance, profile_path, &m_profile),
-      (std::string("Failed to get interaction profile path \"") + profile_path + "\".").data());
+  CHECK_XR(xrStringToPath(instance, info.profile_path, &m_profile),
+           (std::string("Failed to get interaction profile path \"") + info.profile_path + "\".")
+               .data());
+
+  const bool is_float_action = (type == GHOST_kXrActionTypeFloatInput ||
+                                type == GHOST_kXrActionTypeVector2fInput);
+  const bool is_button_action = (is_float_action || type == GHOST_kXrActionTypeBooleanInput);
+  const bool is_pose_action = (type == GHOST_kXrActionTypePoseInput);
 
   /* Create bindings. */
   XrInteractionProfileSuggestedBinding bindings_info{
@@ -92,31 +92,81 @@ GHOST_XrActionProfile::GHOST_XrActionProfile(XrInstance instance,
   bindings_info.interactionProfile = m_profile;
   bindings_info.countSuggestedBindings = 1;
 
-  for (uint32_t interaction_idx = 0; interaction_idx < info.count_interaction_paths;
-       ++interaction_idx) {
-    const char *interaction_path = info.interaction_paths[interaction_idx];
+  for (uint32_t subaction_idx = 0; subaction_idx < info.count_subaction_paths; ++subaction_idx) {
+    const char *subaction_path_str = info.subaction_paths[subaction_idx];
+    const GHOST_XrActionBindingInfo &binding_info = info.bindings[subaction_idx];
+
+    const std::string interaction_path = std::string(subaction_path_str) +
+                                         binding_info.component_path;
     if (m_bindings.find(interaction_path) != m_bindings.end()) {
       continue;
     }
 
     XrActionSuggestedBinding sbinding;
     sbinding.action = action;
-    CHECK_XR(xrStringToPath(instance, int

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list