[Bf-blender-cvs] [fb1822ddeb2] master: XR: Controller Data Improvements

Peter Kim noreply at git.blender.org
Thu Aug 5 14:11:22 CEST 2021


Commit: fb1822ddeb28037544e94862112aa7338a0c278b
Author: Peter Kim
Date:   Thu Aug 5 21:11:01 2021 +0900
Branches: master
https://developer.blender.org/rBfb1822ddeb28037544e94862112aa7338a0c278b

XR: Controller Data Improvements

Provides two key improvements to runtime controller data.

1. Separates controller poses into two components, "grip" and "aim",
which are both required to accurately represent the controllers
without manual offsets.

Following their OpenXR definitions, the grip pose represents the
user's hand when holding the controller, and the aim pose represents
the controller's aiming source.

2. Runtime controller data is now stored as a dynamic array instead
of a fixed array. This makes the API/functionality more adaptable to
different systems.

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/D12073

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

M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/xr/intern/wm_xr_action.c
M	source/blender/windowmanager/xr/intern/wm_xr_draw.c
M	source/blender/windowmanager/xr/intern/wm_xr_intern.h
M	source/blender/windowmanager/xr/intern/wm_xr_session.c

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

diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 8c1511fd152..7e26d921bd7 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -962,12 +962,18 @@ bool WM_xr_session_state_viewer_pose_rotation_get(const wmXrData *xr, float r_ro
 bool WM_xr_session_state_viewer_pose_matrix_info_get(const wmXrData *xr,
                                                      float r_viewmat[4][4],
                                                      float *r_focal_len);
-bool WM_xr_session_state_controller_pose_location_get(const wmXrData *xr,
+bool WM_xr_session_state_controller_grip_location_get(const wmXrData *xr,
                                                       unsigned int subaction_idx,
                                                       float r_location[3]);
-bool WM_xr_session_state_controller_pose_rotation_get(const wmXrData *xr,
+bool WM_xr_session_state_controller_grip_rotation_get(const wmXrData *xr,
                                                       unsigned int subaction_idx,
                                                       float r_rotation[4]);
+bool WM_xr_session_state_controller_aim_location_get(const wmXrData *xr,
+                                                     unsigned int subaction_idx,
+                                                     float r_location[3]);
+bool WM_xr_session_state_controller_aim_rotation_get(const wmXrData *xr,
+                                                     unsigned int subaction_idx,
+                                                     float r_rotation[4]);
 
 /* wm_xr_actions.c */
 /* XR action functions to be called pre-XR session start.
@@ -1002,9 +1008,10 @@ void WM_xr_action_binding_destroy(wmXrData *xr,
 /* If action_set_name is NULL, then all action sets will be treated as active. */
 bool WM_xr_active_action_set_set(wmXrData *xr, const char *action_set_name);
 
-bool WM_xr_controller_pose_action_set(wmXrData *xr,
-                                      const char *action_set_name,
-                                      const char *action_name);
+bool WM_xr_controller_pose_actions_set(wmXrData *xr,
+                                       const char *action_set_name,
+                                       const char *grip_action_name,
+                                       const char *aim_action_name);
 
 /* XR action functions to be called post-XR session start. */
 bool WM_xr_action_state_get(const wmXrData *xr,
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_action.c b/source/blender/windowmanager/xr/intern/wm_xr_action.c
index ee4cfcccaa7..8f2de4bbbad 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_action.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_action.c
@@ -112,11 +112,11 @@ static wmXrAction *action_create(const char *action_name,
   const bool is_button_action = (is_float_action || type == XR_BOOLEAN_INPUT);
   if (is_float_action) {
     action->float_thresholds = MEM_calloc_arrayN(
-      count, sizeof(*action->float_thresholds), "XrAction_FloatThresholds");
+        count, sizeof(*action->float_thresholds), "XrAction_FloatThresholds");
   }
   if (is_button_action) {
     action->axis_flags = MEM_calloc_arrayN(
-      count, sizeof(*action->axis_flags), "XrAction_AxisFlags");
+        count, sizeof(*action->axis_flags), "XrAction_AxisFlags");
   }
 
   action->ot = ot;
@@ -186,9 +186,9 @@ void WM_xr_action_set_destroy(wmXrData *xr, const char *action_set_name)
   wmXrSessionState *session_state = &xr->runtime->session_state;
 
   if (action_set == session_state->active_action_set) {
-    if (action_set->controller_pose_action) {
+    if (action_set->controller_grip_action || action_set->controller_aim_action) {
       wm_xr_session_controller_data_clear(session_state);
-      action_set->controller_pose_action = NULL;
+      action_set->controller_grip_action = action_set->controller_aim_action = NULL;
     }
     if (action_set->active_modal_action) {
       action_set->active_modal_action = NULL;
@@ -213,13 +213,8 @@ bool WM_xr_action_create(wmXrData *xr,
     return false;
   }
 
-  wmXrAction *action = action_create(action_name,
-                                     type,
-                                     count_subaction_paths,
-                                     subaction_paths,
-                                     ot,
-                                     op_properties,
-                                     op_flag);
+  wmXrAction *action = action_create(
+      action_name, type, count_subaction_paths, subaction_paths, ot, op_properties, op_flag);
 
   GHOST_XrActionInfo info = {
       .name = action_name,
@@ -269,13 +264,16 @@ void WM_xr_action_destroy(wmXrData *xr, const char *action_set_name, const char
     return;
   }
 
-  if (action_set->controller_pose_action &&
-      STREQ(action_set->controller_pose_action->name, action_name)) {
+  if ((action_set->controller_grip_action &&
+       STREQ(action_set->controller_grip_action->name, action_name)) ||
+      (action_set->controller_aim_action &&
+       STREQ(action_set->controller_aim_action->name, action_name))) {
     if (action_set == xr->runtime->session_state.active_action_set) {
       wm_xr_session_controller_data_clear(&xr->runtime->session_state);
     }
-    action_set->controller_pose_action = NULL;
+    action_set->controller_grip_action = action_set->controller_aim_action = NULL;
   }
+
   if (action_set->active_modal_action &&
       STREQ(action_set->active_modal_action->name, action_name)) {
     action_set->active_modal_action = NULL;
@@ -284,7 +282,6 @@ void WM_xr_action_destroy(wmXrData *xr, const char *action_set_name, const char
   GHOST_XrDestroyActions(xr->runtime->context, action_set_name, 1, &action_name);
 }
 
-
 bool WM_xr_action_binding_create(wmXrData *xr,
                                  const char *action_set_name,
                                  const char *action_name,
@@ -297,7 +294,7 @@ bool WM_xr_action_binding_create(wmXrData *xr,
                                  const struct wmXrPose *poses)
 {
   GHOST_XrActionBindingInfo *binding_infos = MEM_calloc_arrayN(
-    count_subaction_paths, sizeof(*binding_infos), __func__);
+      count_subaction_paths, sizeof(*binding_infos), __func__);
 
   for (unsigned int i = 0; i < count_subaction_paths; ++i) {
     GHOST_XrActionBindingInfo *binding_info = &binding_infos[i];
@@ -334,7 +331,7 @@ void WM_xr_action_binding_destroy(wmXrData *xr,
                                   const char *profile_path)
 {
   GHOST_XrDestroyActionBindings(
-    xr->runtime->context, action_set_name, 1, &action_name, &profile_path);
+      xr->runtime->context, action_set_name, 1, &action_name, &profile_path);
 }
 
 bool WM_xr_active_action_set_set(wmXrData *xr, const char *action_set_name)
@@ -360,31 +357,54 @@ bool WM_xr_active_action_set_set(wmXrData *xr, const char *action_set_name)
 
   xr->runtime->session_state.active_action_set = action_set;
 
-  if (action_set->controller_pose_action) {
-    wm_xr_session_controller_data_populate(action_set->controller_pose_action, xr);
+  if (action_set->controller_grip_action && action_set->controller_aim_action) {
+    wm_xr_session_controller_data_populate(
+        action_set->controller_grip_action, action_set->controller_aim_action, xr);
+  }
+  else {
+    wm_xr_session_controller_data_clear(&xr->runtime->session_state);
   }
 
   return true;
 }
 
-bool WM_xr_controller_pose_action_set(wmXrData *xr,
-                                      const char *action_set_name,
-                                      const char *action_name)
+bool WM_xr_controller_pose_actions_set(wmXrData *xr,
+                                       const char *action_set_name,
+                                       const char *grip_action_name,
+                                       const char *aim_action_name)
 {
   wmXrActionSet *action_set = action_set_find(xr, action_set_name);
   if (!action_set) {
     return false;
   }
 
-  wmXrAction *action = action_find(xr, action_set_name, action_name);
-  if (!action) {
+  wmXrAction *grip_action = action_find(xr, action_set_name, grip_action_name);
+  if (!grip_action) {
+    return false;
+  }
+
+  wmXrAction *aim_action = action_find(xr, action_set_name, aim_action_name);
+  if (!aim_action) {
     return false;
   }
 
-  action_set->controller_pose_action = action;
+  /* Ensure consistent subaction paths. */
+  const unsigned int count = grip_action->count_subaction_paths;
+  if (count != aim_action->count_subaction_paths) {
+    return false;
+  }
+
+  for (unsigned int i = 0; i < count; ++i) {
+    if (!STREQ(grip_action->subaction_paths[i], aim_action->subaction_paths[i])) {
+      return false;
+    }
+  }
+
+  action_set->controller_grip_action = grip_action;
+  action_set->controller_aim_action = aim_action;
 
   if (action_set == xr->runtime->session_state.active_action_set) {
-    wm_xr_session_controller_data_populate(action, xr);
+    wm_xr_session_controller_data_populate(grip_action, aim_action, xr);
   }
 
   return true;
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_draw.c b/source/blender/windowmanager/xr/intern/wm_xr_draw.c
index 4ac05e339b9..bbb73fc2007 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr_draw.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr_draw.c
@@ -38,18 +38,18 @@
 #include "wm_surface.h"
 #include "wm_xr_intern.h"
 
-void wm_xr_pose_to_viewmat(const GHOST_XrPose *pose, float r_viewmat[4][4])
+void wm_xr_pose_to_mat(const GHOST_XrPose *pose, float r_mat[4][4])
 {
-  float iquat[4];
-  invert_qt_qt_normalized(iquat, pose->orientation_quat);
-  quat_to_mat4(r_viewmat, iquat);
-  translate_m4(r_viewmat, -pose->position[0], -pose->position[1], -pose->position[2]);
+  quat_to_mat4(r_mat, pose->orientation_quat);
+  copy_v3_v3(r_mat[3], pose->position);
 }
 
-void wm_xr_controller_pose_to_mat(const GHOST_XrPose *pose, float r_mat[4][4])
+void wm_xr_pose_to_imat(const GHOST_XrPose *pose, float r_imat[4][4])
 {
-  quat_to_mat4(r_mat, pose->orientation_quat);
-  copy_v3_v3(r_mat[3], pose->position);
+  float iquat[4];
+  invert_qt_qt_normalized(iquat, pose->orientation_quat);
+  quat_to_mat4(r_imat

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list