[Bf-blender-cvs] [d3d4be1db3a] master: XR: Action Binding Improvements

Peter Kim noreply at git.blender.org
Thu Aug 5 06:14:42 CEST 2021


Commit: d3d4be1db3a09084eb2ff329bb7a530a87481480
Author: Peter Kim
Date:   Thu Aug 5 13:14:26 2021 +0900
Branches: master
https://developer.blender.org/rBd3d4be1db3a09084eb2ff329bb7a530a87481480

XR: Action Binding Improvements

Provides several important improvements to the runtime action
bindings operation and internal API.

Moves input-specific action data (input thresholds, input regions,
pose offsets/spaces) from actions to more granular action bindings.
This allows a single action to be mapped to a variety of inputs,
without having to share a single input threshold, region, or space.

Also removes the need for action space creation API, as spaces for
pose actions will be automatically created with the bindings.

The correct action data for the current inputs is set by calling
xrGetCurrentInteractionProfile() to get the current profile and then
retrieving the corresponding mapped data.

Does not bring about any changes for users since only internal
runtime functionality is currently affected.

Reviewed By: Julian Eisel

Differential Revision: http://developer.blender.org/D12077

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

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/windowmanager/CMakeLists.txt
M	source/blender/windowmanager/WM_api.h
R079	source/blender/windowmanager/xr/intern/wm_xr_actions.c	source/blender/windowmanager/xr/intern/wm_xr_action.c
M	source/blender/windowmanager/xr/intern/wm_xr_intern.h

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

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 46e3888a367..fea5a545807 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 94a3fd86b73..fb19b9535ad 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 cb409595e50..0bc9be26eb1 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 9c4f7fbc7d8..676a3367ee1 100644
--- a/intern/ghost/intern/GHOST_XrAction.cpp
+++ b/intern/ghost/intern/GHOST_XrAction.cpp
@@ -33,24 +33,22 @@
  *
  * \{ */
 
-GHOST_XrActionSpace::GHOST_XrActionSpace(XrInstance instance,
-                                         XrSession session,
+GHOST_XrActionSpace::GHOST_XrActionSpace(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());
 }
 
@@ -66,11 +64,6 @@ XrSpace GHOST_XrActionSpace::getSpace() const
   return m_space;
 }
 
-const XrPath &GHOST_XrActionSpace::getSubactionPath() const
-{
-  return m_subaction_path;
-}
-
 /** \} */
 
 /* -------------------------------------------------------------------- */
@@ -79,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{
@@ -93,31 +92,80 @@ 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 sbindi

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list