[Bf-blender-cvs] [eeb948f428f] xr-controller-support: XR: Add axis region, bimanual action flags

Peter Kim noreply at git.blender.org
Fri Jun 11 14:07:34 CEST 2021


Commit: eeb948f428f2c0dc67dfdbea803d2bce00c31a0e
Author: Peter Kim
Date:   Fri Jun 11 20:48:41 2021 +0900
Branches: xr-controller-support
https://developer.blender.org/rBeeb948f428f2c0dc67dfdbea803d2bce00c31a0e

XR: Add axis region, bimanual action flags

The axis flags allow binding actions to certain regions of an input
axis (positive or negative). In this way, two different actions can
be bound to the input path "/input/thumbstick/x" without overlapping.

The bimanual flag signifies that the action depends on inputs from
both of its subaction paths, and both states, if available, will then
be passed to the operator. This will be used in the future for
two-handed navigation and transform.

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

M	source/blender/makesdna/DNA_xr_types.h
M	source/blender/makesrna/intern/rna_wm.c
M	source/blender/makesrna/intern/rna_xr.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_event_query.c
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/wm_event_system.h
M	source/blender/windowmanager/xr/intern/wm_xr_action.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/makesdna/DNA_xr_types.h b/source/blender/makesdna/DNA_xr_types.h
index 9eced3ab034..c48760926c4 100644
--- a/source/blender/makesdna/DNA_xr_types.h
+++ b/source/blender/makesdna/DNA_xr_types.h
@@ -36,7 +36,7 @@ typedef struct XrSessionSettings {
 
   float base_scale;
   char _pad[3];
-  char base_pose_type; /* eXRSessionBasePoseType */
+  char base_pose_type; /* eXrSessionBasePoseType */
   /** Object to take the location and rotation as base position from. */
   Object *base_pose_object;
   float base_pose_location[3];
@@ -75,31 +75,16 @@ typedef struct XrSessionSettings {
   char _pad3[5];
 } XrSessionSettings;
 
-/** XR action type. Enum values match those in GHOST_XrActionType enum for consistency. */
-typedef enum eXrActionType {
-  XR_BOOLEAN_INPUT = 1,
-  XR_FLOAT_INPUT = 2,
-  XR_VECTOR2F_INPUT = 3,
-  XR_POSE_INPUT = 4,
-  XR_VIBRATION_OUTPUT = 100,
-} eXrActionType;
-
-typedef enum eXrOpFlag {
-  XR_OP_PRESS = 0,
-  XR_OP_RELEASE = 1,
-  XR_OP_MODAL = 2,
-} eXrOpFlag;
-
 typedef enum eXrSessionFlag {
   XR_SESSION_USE_POSITION_TRACKING = (1 << 0),
   XR_SESSION_USE_ABSOLUTE_TRACKING = (1 << 1),
 } eXrSessionFlag;
 
-typedef enum eXRSessionBasePoseType {
+typedef enum eXrSessionBasePoseType {
   XR_BASE_POSE_SCENE_CAMERA = 0,
   XR_BASE_POSE_OBJECT = 1,
   XR_BASE_POSE_CUSTOM = 2,
-} eXRSessionBasePoseType;
+} eXrSessionBasePoseType;
 
 typedef enum eXrSessionControllerDrawStyle {
   XR_CONTROLLER_DRAW_AXES = 0,
@@ -116,6 +101,30 @@ typedef enum eXrSessionObjectFlag {
   XR_OBJECT_AUTOKEY = (1 << 1),
 } eXrSessionObjectFlag;
 
+/** XR action type. Enum values match those in GHOST_XrActionType enum for consistency. */
+typedef enum eXrActionType {
+  XR_BOOLEAN_INPUT = 1,
+  XR_FLOAT_INPUT = 2,
+  XR_VECTOR2F_INPUT = 3,
+  XR_POSE_INPUT = 4,
+  XR_VIBRATION_OUTPUT = 100,
+} eXrActionType;
+
+typedef enum eXrActionFlag {
+  /** Determines how the operator will be executed (mutually exclusive). */
+  XR_ACTION_PRESS = (1 << 0),
+  XR_ACTION_RELEASE = (1 << 1),
+  XR_ACTION_MODAL = (1 << 2),
+  /** For axis-based inputs (thumbstick/trackpad/etc). Determines the region for operator execution
+     (mutually exclusive per axis). */
+  XR_ACTION_AXIS0_POS = (1 << 3),
+  XR_ACTION_AXIS0_NEG = (1 << 4),
+  XR_ACTION_AXIS1_POS = (1 << 5),
+  XR_ACTION_AXIS1_NEG = (1 << 6),
+  /** Action depends on two subaction paths (i.e. two-handed/bimanual action). */
+  XR_ACTION_BIMANUAL = (1 << 7),
+} eXrActionFlag;
+
 /* -------------------------------------------------------------------- */
 
 typedef struct XrActionMapItem {
@@ -145,11 +154,12 @@ typedef struct XrActionMapItem {
   IDProperty *op_properties;
   /** RNA pointer to access properties. */
   struct PointerRNA *op_properties_ptr;
-  char op_flag; /* eXrOpFlag */
+
+  short action_flag; /* eXrActionFlag */
 
   /** Pose action properties. */
   char pose_is_controller;
-  char _pad2[2];
+  char _pad2[1];
   float pose_location[3];
   float pose_rotation[3];
 
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index a073e710196..c3c43a77244 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -712,7 +712,7 @@ static void rna_Event_xr_actionmap_get(PointerRNA *ptr, char *value)
 {
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
-    WM_event_xr_data(event, &value, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+    WM_event_xr_data(event, &value, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
   }
   else {
     value[0] = '\0';
@@ -735,7 +735,7 @@ static void rna_Event_xr_action_get(PointerRNA *ptr, char *value)
 {
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
-    WM_event_xr_data(event, NULL, &value, NULL, NULL, NULL, NULL, NULL, NULL);
+    WM_event_xr_data(event, NULL, &value, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
   }
   else {
     value[0] = '\0';
@@ -759,7 +759,8 @@ static int rna_Event_xr_type_get(PointerRNA *ptr)
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
     int type;
-    WM_event_xr_data(event, NULL, NULL, (char *)&type, NULL, NULL, NULL, NULL, NULL);
+    WM_event_xr_data(
+        event, NULL, NULL, (char *)&type, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
     return type;
   }
   else {
@@ -771,7 +772,18 @@ static void rna_Event_xr_state_get(PointerRNA *ptr, float *value)
 {
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
-    WM_event_xr_data(event, NULL, NULL, NULL, value, NULL, NULL, NULL, NULL);
+    WM_event_xr_data(event, NULL, NULL, NULL, value, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+  }
+  else {
+    memset(value, 0, sizeof(float[2]));
+  }
+}
+
+static void rna_Event_xr_state_other_get(PointerRNA *ptr, float *value)
+{
+  const wmEvent *event = ptr->data;
+  if (WM_event_is_xr(event)) {
+    WM_event_xr_data(event, NULL, NULL, NULL, NULL, value, NULL, NULL, NULL, NULL, NULL, NULL);
   }
   else {
     memset(value, 0, sizeof(float[2]));
@@ -782,7 +794,7 @@ static void rna_Event_xr_controller_location_get(PointerRNA *ptr, float *value)
 {
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
-    WM_event_xr_data(event, NULL, NULL, NULL, NULL, value, NULL, NULL, NULL);
+    WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL, value, NULL, NULL, NULL, NULL, NULL);
   }
   else {
     memset(value, 0, sizeof(float[3]));
@@ -793,7 +805,30 @@ static void rna_Event_xr_controller_rotation_get(PointerRNA *ptr, float *value)
 {
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
-    WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL, value, NULL, NULL);
+    WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL, NULL, value, NULL, NULL, NULL, NULL);
+  }
+  else {
+    value[0] = 1.0f;
+    value[1] = value[2] = value[3] = 0.0f;
+  }
+}
+
+static void rna_Event_xr_controller_location_other_get(PointerRNA *ptr, float *value)
+{
+  const wmEvent *event = ptr->data;
+  if (WM_event_is_xr(event)) {
+    WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, value, NULL, NULL, NULL);
+  }
+  else {
+    memset(value, 0, sizeof(float[3]));
+  }
+}
+
+static void rna_Event_xr_controller_rotation_other_get(PointerRNA *ptr, float *value)
+{
+  const wmEvent *event = ptr->data;
+  if (WM_event_is_xr(event)) {
+    WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, value, NULL, NULL);
   }
   else {
     value[0] = 1.0f;
@@ -805,7 +840,8 @@ static void rna_Event_xr_view_matrix_get(PointerRNA *ptr, float values[16])
 {
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
-    WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL, NULL, (float(*)[4])values, NULL);
+    WM_event_xr_data(
+        event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, (float(*)[4])values, NULL);
   }
   else {
     memset(values, 0, sizeof(float[16]));
@@ -817,7 +853,8 @@ static float rna_Event_xr_focal_length_get(PointerRNA *ptr)
   const wmEvent *event = ptr->data;
   if (WM_event_is_xr(event)) {
     float focal_len;
-    WM_event_xr_data(event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &focal_len);
+    WM_event_xr_data(
+        event, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &focal_len);
     return focal_len;
   }
   else {
@@ -2414,6 +2451,13 @@ static void rna_def_event(BlenderRNA *brna)
   RNA_def_property_float_funcs(prop, "rna_Event_xr_state_get", NULL, NULL);
   RNA_def_property_ui_text(prop, "XR State", "XR action values corresponding to type");
 
+  prop = RNA_def_property(srna, "xr_state_other", PROP_FLOAT, PROP_NONE);
+  RNA_def_property_array(prop, 2);
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+  RNA_def_property_float_funcs(prop, "rna_Event_xr_state_other_get", NULL, NULL);
+  RNA_def_property_ui_text(
+      prop, "XR State Other", "State of the other user path for bimanual actions");
+
   prop = RNA_def_property(srna, "xr_controller_location", PROP_FLOAT, PROP_TRANSLATION);
   RNA_def_property_array(prop, 3);
   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
@@ -2432,6 +2476,22 @@ static void rna_def_event(BlenderRNA *brna)
       "XR Controller Rotation",
       "Rotation of the action's corresponding controller pose in world space");
 
+  prop = RNA_def_property(srna, "xr_controller_location_other", PROP_FLOAT, PROP_TRANSLATION);
+  RNA_def_property_array(prop, 3);
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+  RNA_def_property_float_funcs(prop, "rna_Event_xr_controller_location_other_get", NULL, NULL);
+  RNA_def_property_ui_text(prop,
+                           "XR Controller Location Other",
+                           "Controller location of the other user path for bimanual actions");
+
+  prop = RNA_def_property(srna, "xr_controller_rotation_other", PROP_FLOAT, PROP_QUATERNION);
+  RNA_def_property_array(prop, 4);
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+  RNA_def_property_float_funcs(prop, "rna_Event_xr_controller_rotation_other_get", NULL, NULL);
+  RNA_def_property_ui_text(prop,
+                           "XR Controller Rotation Other",
+                           "Controller rotation of the other user path for bimanual actions");
+
   prop = RNA_def_property(srna, "xr_view_matrix", PROP_FLOAT, PROP_MATRIX);
   RNA_def_property_array(prop, 16);
   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c
index a48a073f03d..1a6f4c68388 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -145,6 +145,115 @@ static PointerRNA rna_XrActionMapItem_op_properties_get(PointerRNA *ptr)
   return PointerRNA_NULL;
 }
 
+static int rna_XrActionMapItem_op_flag_get(PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  XrActionMapItem *ami = ptr->data;
+  if ((ami->action_flag & XR_ACTION_RELEASE) != 0) {
+    return XR_ACTION_RELEASE;
+  }
+  if ((ami->action_flag & XR_ACTION_MODAL) != 0) {
+    return XR_ACTION_MODAL;
+  }
+#  else
+  UNUSED_VARS(ptr);
+#  endif
+  return XR_ACTION_PRESS;
+}
+
+static void rna_XrActionMapItem_op_flag_set(PointerRNA *ptr, int value)
+{
+#  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list