[Bf-blender-cvs] [e844e9e8f3b] master: XR Controller Support Step 2: Action Maps

Peter Kim noreply at git.blender.org
Thu Aug 5 16:41:12 CEST 2021


Commit: e844e9e8f3bb6814e24749316003814156e2e2ce
Author: Peter Kim
Date:   Thu Aug 5 23:40:17 2021 +0900
Branches: master
https://developer.blender.org/rBe844e9e8f3bb6814e24749316003814156e2e2ce

XR Controller Support Step 2: Action Maps

Addresses the remaining portions of T77137 (Python API for Controller
Interaction), which was partially completed by D10942.

Adds an XR "action maps" system for loading XR action data from a
Python script. Action maps are accessible via the Python API, and are used
to pass default actions to the VR session during the
xr_session_start_pre() callback.

Since action maps are stored only as runtime data, they will be
cleaned up with the rest of the VR runtime data on file read or exit.

Reviewed By: Julian Eisel, Hans Goudey

Differential Revision: https://developer.blender.org/D10943

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

M	intern/ghost/GHOST_C-api.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_xr.c
M	source/blender/windowmanager/CMakeLists.txt
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/xr/intern/wm_xr.c
M	source/blender/windowmanager/xr/intern/wm_xr_action.c
A	source/blender/windowmanager/xr/intern/wm_xr_actionmap.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 fea5a545807..83c67f83908 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -1102,6 +1102,7 @@ int GHOST_XrSyncActions(GHOST_XrContextHandle xr_context, const char *action_set
 int GHOST_XrApplyHapticAction(GHOST_XrContextHandle xr_context,
                               const char *action_set_name,
                               const char *action_name,
+                              const char **subaction_path,
                               const int64_t *duration,
                               const float *frequency,
                               const float *amplitude);
@@ -1111,7 +1112,8 @@ int GHOST_XrApplyHapticAction(GHOST_XrContextHandle xr_context,
  */
 void GHOST_XrStopHapticAction(GHOST_XrContextHandle xr_context,
                               const char *action_set_name,
-                              const char *action_name);
+                              const char *action_name,
+                              const char **subaction_path);
 
 /**
  * Get action set custom data (owned by Blender, not GHOST).
@@ -1126,6 +1128,18 @@ void *GHOST_XrGetActionCustomdata(GHOST_XrContextHandle xr_context,
                                   const char *action_set_name,
                                   const char *action_name);
 
+/**
+ * Get the number of actions in an action set.
+ */
+unsigned int GHOST_XrGetActionCount(GHOST_XrContextHandle xr_context, const char *action_set_name);
+
+/**
+ * Get custom data for all actions in an action set.
+ */
+void GHOST_XrGetActionCustomdataArray(GHOST_XrContextHandle xr_context,
+                                      const char *action_set_name,
+                                      void **r_customdata_array);
+
 #endif /* WITH_XR_OPENXR */
 
 #ifdef __cplusplus
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 0bc9be26eb1..b1af5c131ab 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -1005,25 +1005,29 @@ int GHOST_XrSyncActions(GHOST_XrContextHandle xr_contexthandle, const char *acti
 int GHOST_XrApplyHapticAction(GHOST_XrContextHandle xr_contexthandle,
                               const char *action_set_name,
                               const char *action_name,
+                              const char **subaction_path,
                               const int64_t *duration,
                               const float *frequency,
                               const float *amplitude)
 {
   GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
   GHOST_XrSession *xr_session = xr_context->getSession();
-  GHOST_XR_CAPI_CALL_RET(xr_session->applyHapticAction(
-                             action_set_name, action_name, *duration, *frequency, *amplitude),
-                         xr_context);
+  GHOST_XR_CAPI_CALL_RET(
+      xr_session->applyHapticAction(
+          action_set_name, action_name, subaction_path, *duration, *frequency, *amplitude),
+      xr_context);
   return 0;
 }
 
 void GHOST_XrStopHapticAction(GHOST_XrContextHandle xr_contexthandle,
                               const char *action_set_name,
-                              const char *action_name)
+                              const char *action_name,
+                              const char **subaction_path)
 {
   GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
   GHOST_XrSession *xr_session = xr_context->getSession();
-  GHOST_XR_CAPI_CALL(xr_session->stopHapticAction(action_set_name, action_name), xr_context);
+  GHOST_XR_CAPI_CALL(xr_session->stopHapticAction(action_set_name, action_name, subaction_path),
+                     xr_context);
 }
 
 void *GHOST_XrGetActionSetCustomdata(GHOST_XrContextHandle xr_contexthandle,
@@ -1046,4 +1050,23 @@ void *GHOST_XrGetActionCustomdata(GHOST_XrContextHandle xr_contexthandle,
   return 0;
 }
 
+unsigned int GHOST_XrGetActionCount(GHOST_XrContextHandle xr_contexthandle,
+                                    const char *action_set_name)
+{
+  GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
+  GHOST_XrSession *xr_session = xr_context->getSession();
+  GHOST_XR_CAPI_CALL_RET(xr_session->getActionCount(action_set_name), xr_context);
+  return 0;
+}
+
+void GHOST_XrGetActionCustomdataArray(GHOST_XrContextHandle xr_contexthandle,
+                                      const char *action_set_name,
+                                      void **r_customdata_array)
+{
+  GHOST_IXrContext *xr_context = (GHOST_IXrContext *)xr_contexthandle;
+  GHOST_XrSession *xr_session = xr_context->getSession();
+  GHOST_XR_CAPI_CALL(xr_session->getActionCustomdataArray(action_set_name, r_customdata_array),
+                     xr_context);
+}
+
 #endif /* WITH_XR_OPENXR */
diff --git a/intern/ghost/intern/GHOST_XrAction.cpp b/intern/ghost/intern/GHOST_XrAction.cpp
index 676a3367ee1..07eb42c14e6 100644
--- a/intern/ghost/intern/GHOST_XrAction.cpp
+++ b/intern/ghost/intern/GHOST_XrAction.cpp
@@ -208,8 +208,10 @@ GHOST_XrAction::GHOST_XrAction(XrInstance instance,
   m_subaction_paths.resize(info.count_subaction_paths);
 
   for (uint32_t i = 0; i < info.count_subaction_paths; ++i) {
-    CHECK_XR(xrStringToPath(instance, info.subaction_paths[i], &m_subaction_paths[i]),
-             (std::string("Failed to get user path \"") + info.subaction_paths[i] + "\".").data());
+    const char *subaction_path_str = info.subaction_paths[i];
+    CHECK_XR(xrStringToPath(instance, subaction_path_str, &m_subaction_paths[i]),
+             (std::string("Failed to get user path \"") + subaction_path_str + "\".").data());
+    m_subaction_indices.insert({subaction_path_str, i});
   }
 
   XrActionCreateInfo action_info{XR_TYPE_ACTION_CREATE_INFO};
@@ -373,6 +375,7 @@ void GHOST_XrAction::updateState(XrSession session,
 
 void GHOST_XrAction::applyHapticFeedback(XrSession session,
                                          const char *action_name,
+                                         const char **subaction_path_str,
                                          const int64_t &duration,
                                          const float &frequency,
                                          const float &amplitude)
@@ -386,24 +389,46 @@ void GHOST_XrAction::applyHapticFeedback(XrSession session,
   XrHapticActionInfo haptic_info{XR_TYPE_HAPTIC_ACTION_INFO};
   haptic_info.action = m_action;
 
-  for (std::vector<XrPath>::iterator it = m_subaction_paths.begin(); it != m_subaction_paths.end();
-       ++it) {
-    haptic_info.subactionPath = *it;
-    CHECK_XR(xrApplyHapticFeedback(session, &haptic_info, (const XrHapticBaseHeader *)&vibration),
-             (std::string("Failed to apply haptic action \"") + action_name + "\".").data());
+  if (subaction_path_str != nullptr) {
+    SubactionIndexMap::iterator it = m_subaction_indices.find(*subaction_path_str);
+    if (it != m_subaction_indices.end()) {
+      haptic_info.subactionPath = m_subaction_paths[it->second];
+      CHECK_XR(
+          xrApplyHapticFeedback(session, &haptic_info, (const XrHapticBaseHeader *)&vibration),
+          (std::string("Failed to apply haptic action \"") + action_name + "\".").data());
+    }
+  }
+  else {
+    for (const XrPath &subaction_path : m_subaction_paths) {
+      haptic_info.subactionPath = subaction_path;
+      CHECK_XR(
+          xrApplyHapticFeedback(session, &haptic_info, (const XrHapticBaseHeader *)&vibration),
+          (std::string("Failed to apply haptic action \"") + action_name + "\".").data());
+    }
   }
 }
 
-void GHOST_XrAction::stopHapticFeedback(XrSession session, const char *action_name)
+void GHOST_XrAction::stopHapticFeedback(XrSession session,
+                                        const char *action_name,
+                                        const char **subaction_path_str)
 {
   XrHapticActionInfo haptic_info{XR_TYPE_HAPTIC_ACTION_INFO};
   haptic_info.action = m_action;
 
-  for (std::vector<XrPath>::iterator it = m_subaction_paths.begin(); it != m_subaction_paths.end();
-       ++it) {
-    haptic_info.subactionPath = *it;
-    CHECK_XR(xrStopHapticFeedback(session, &haptic_info),
-             (std::string("Failed to stop haptic action \"") + action_name + "\".").data());
+  if (subaction_path_str != nullptr) {
+    SubactionIndexMap::iterator it = m_subaction_indices.find(*subaction_path_str);
+    if (it != m_subaction_indices.end()) {
+      haptic_info.subactionPath = m_subaction_paths[it->second];
+      CHECK_XR(xrStopHapticFeedback(session, &haptic_info),
+               (std::string("Failed to stop haptic action \"") + action_name + "\".").data());
+    }
+  }
+  else {
+    for (const XrPath &subaction_path : m_subaction_paths) {
+      haptic_info.subactionPath = subaction_path;
+      CHECK_XR(xrStopHapticFeedback(session, &haptic_info),
+               (std::string("Failed to stop haptic action \"") + action_name + "\".").data());
+    }
   }
 }
 
@@ -511,6 +536,19 @@ void *GHOST_XrActionSet::getCustomdata()
   return m_custom_data_->custom_data_;
 }
 
+uint32_t GHOST_XrActionSet::getActionCount() const
+{
+  return (uint32_t)m_actions.size();
+}
+
+void GHOST_XrActionSet::getActionCustomdataArray(void **r_customdata_array)
+{
+  uint32_t i = 0;
+  for (auto &[name, action] : m_actions) {
+    r_customdata_array[i++] = action.getCustomdata();
+  }
+}
+
 void GHOST_XrActionSet::getBindings(
     std::map<XrPath, std::vector<XrActionSuggestedBinding>> &r_bindings) const
 {
diff --git a/intern/ghost/intern/GHOST_XrAction.h b/intern/ghost/intern/GHOST_XrAction.h
index e2a89e87278..73a1cd9cd6a 100644
--- a/intern/ghost/intern/GHOST_XrAction.h
+++ b/intern/ghost/intern/GHOST_XrAction.h
@@ -103,17 +103,21 @@ class GHOST_XrAction {
                    const XrTime &predicted_display_time);
   void applyHapticFeedback(XrSession session,
                            const char *action_name,
+                           const char **subaction_path,
                            const int64_t &duration,
                            const float &frequency,
                            const float &amplitude);
-  void stopHapticFeedback(XrSession session, 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list