[Bf-blender-cvs] [cdeb506008e] master: XR Controller Support Step 3: XR Events

Peter Kim noreply at git.blender.org
Tue Oct 12 06:50:18 CEST 2021


Commit: cdeb506008e9fc6d8d9a48ce90204ec10101cdd0
Author: Peter Kim
Date:   Tue Oct 12 13:09:01 2021 +0900
Branches: master
https://developer.blender.org/rBcdeb506008e9fc6d8d9a48ce90204ec10101cdd0

XR Controller Support Step 3: XR Events

Integrates XR input actions with the WM event system. With this commit,
all VR action functionality (operator execution, pose querying, haptic
application), with the exception of custom drawing, is enabled.

By itself, this does not bring about any changes for regular users,
however it is necessary for the upcoming VR add-on update that will
expose default controller actions to users.

For add-on developers, this updates the Python API with access to XR
event data (input states, controller poses, etc.), which can be
obtained via the "xr" property added to the bpy.types.Event struct.
For XR events, this property will be non-null and the event will have
the type XR_ACTION.

Further details:
XR-type window events are queued to the regular window queues after
updating and interpreting VR action states. An appropriate window is
found by either using the window the VR session was started in or a
fallback option.

When handling XR events, mouse-specific processing is skipped and
instead a dedicated XR offscreen area and region (see 08511b1c3de0) is
used to execute XR event operators in the proper context.

Reviewed By: Severin

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

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

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/intern/wm_event_query.c
M	source/blender/windowmanager/xr/intern/wm_xr_session.c

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

diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index c2d1ac67675..b45cfb04bc1 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -362,6 +362,8 @@ const EnumPropertyItem rna_enum_event_type_items[] = {
      0,
      "ActionZone Fullscreen",
      "AZone FullScr"},
+    /* xr */
+    {EVT_XR_ACTION, "XR_ACTION", 0, "XR Action", ""},
     {0, NULL, 0, NULL, NULL},
 };
 
@@ -700,6 +702,18 @@ static void rna_Event_tilt_get(PointerRNA *ptr, float *values)
   WM_event_tablet_data(event, NULL, values);
 }
 
+static PointerRNA rna_Event_xr_get(PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  wmEvent *event = ptr->data;
+  wmXrActionData *actiondata = WM_event_is_xr(event) ? event->customdata : NULL;
+  return rna_pointer_inherit_refine(ptr, &RNA_XrEventData, actiondata);
+#  else
+  UNUSED_VARS(ptr);
+  return PointerRNA_NULL;
+#  endif
+}
+
 static PointerRNA rna_PopupMenu_layout_get(PointerRNA *ptr)
 {
   struct uiPopupMenu *pup = ptr->data;
@@ -2228,6 +2242,13 @@ static void rna_def_event(BlenderRNA *brna)
   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
   RNA_def_property_ui_text(prop, "Absolute Motion", "The last motion event was an absolute input");
 
+  /* xr */
+  prop = RNA_def_property(srna, "xr", PROP_POINTER, PROP_NONE);
+  RNA_def_property_struct_type(prop, "XrEventData");
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+  RNA_def_property_pointer_funcs(prop, "rna_Event_xr_get", NULL, NULL, NULL);
+  RNA_def_property_ui_text(prop, "XR", "XR event data");
+
   /* modifiers */
   prop = RNA_def_property(srna, "shift", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "shift", 1);
diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c
index f24d28d1209..a433a93e403 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -947,6 +947,155 @@ static void rna_XrSessionState_selected_actionmap_set(PointerRNA *ptr, int value
 
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name XR Event Data
+ * \{ */
+
+static void rna_XrEventData_action_set_get(PointerRNA *ptr, char *r_value)
+{
+#  ifdef WITH_XR_OPENXR
+  const wmXrActionData *data = ptr->data;
+  strcpy(r_value, data->action_set);
+#  else
+  UNUSED_VARS(ptr);
+  r_value[0] = '\0';
+#  endif
+}
+
+static int rna_XrEventData_action_set_length(PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  const wmXrActionData *data = ptr->data;
+  return strlen(data->action_set);
+#  else
+  UNUSED_VARS(ptr);
+  return 0;
+#  endif
+}
+
+static void rna_XrEventData_action_get(PointerRNA *ptr, char *r_value)
+{
+#  ifdef WITH_XR_OPENXR
+  const wmXrActionData *data = ptr->data;
+  strcpy(r_value, data->action);
+#  else
+  UNUSED_VARS(ptr);
+  r_value[0] = '\0';
+#  endif
+}
+
+static int rna_XrEventData_action_length(PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  const wmXrActionData *data = ptr->data;
+  return strlen(data->action);
+#  else
+  UNUSED_VARS(ptr);
+  return 0;
+#  endif
+}
+
+static int rna_XrEventData_type_get(PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  const wmXrActionData *data = ptr->data;
+  return data->type;
+#  else
+  UNUSED_VARS(ptr);
+  return 0;
+#  endif
+}
+
+static void rna_XrEventData_state_get(PointerRNA *ptr, float r_values[2])
+{
+#  ifdef WITH_XR_OPENXR
+  const wmXrActionData *data = ptr->data;
+  copy_v2_v2(r_values, data->state);
+#  else
+  UNUSED_VARS(ptr);
+  zero_v2(r_values);
+#  endif
+}
+
+static void rna_XrEventData_state_other_get(PointerRNA *ptr, float r_values[2])
+{
+#  ifdef WITH_XR_OPENXR
+  const wmXrActionData *data = ptr->data;
+  copy_v2_v2(r_values, data->state_other);
+#  else
+  UNUSED_VARS(ptr);
+  zero_v2(r_values);
+#  endif
+}
+
+static float rna_XrEventData_float_threshold_get(PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  const wmXrActionData *data = ptr->data;
+  return data->float_threshold;
+#  else
+  UNUSED_VARS(ptr);
+  return 0.0f;
+#  endif
+}
+
+static void rna_XrEventData_controller_location_get(PointerRNA *ptr, float r_values[3])
+{
+#  ifdef WITH_XR_OPENXR
+  const wmXrActionData *data = ptr->data;
+  copy_v3_v3(r_values, data->controller_loc);
+#  else
+  UNUSED_VARS(ptr);
+  zero_v3(r_values);
+#  endif
+}
+
+static void rna_XrEventData_controller_rotation_get(PointerRNA *ptr, float r_values[4])
+{
+#  ifdef WITH_XR_OPENXR
+  const wmXrActionData *data = ptr->data;
+  copy_qt_qt(r_values, data->controller_rot);
+#  else
+  UNUSED_VARS(ptr);
+  unit_qt(r_values);
+#  endif
+}
+
+static void rna_XrEventData_controller_location_other_get(PointerRNA *ptr, float r_values[3])
+{
+#  ifdef WITH_XR_OPENXR
+  const wmXrActionData *data = ptr->data;
+  copy_v3_v3(r_values, data->controller_loc_other);
+#  else
+  UNUSED_VARS(ptr);
+  zero_v3(r_values);
+#  endif
+}
+
+static void rna_XrEventData_controller_rotation_other_get(PointerRNA *ptr, float r_values[4])
+{
+#  ifdef WITH_XR_OPENXR
+  const wmXrActionData *data = ptr->data;
+  copy_qt_qt(r_values, data->controller_rot_other);
+#  else
+  UNUSED_VARS(ptr);
+  unit_qt(r_values);
+#  endif
+}
+
+static bool rna_XrEventData_bimanual_get(PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  const wmXrActionData *data = ptr->data;
+  return data->bimanual;
+#  else
+  UNUSED_VARS(ptr);
+  return false;
+#  endif
+}
+
+/** \} */
+
 #else /* RNA_RUNTIME */
 
 /* -------------------------------------------------------------------- */
@@ -1824,6 +1973,94 @@ static void rna_def_xr_session_state(BlenderRNA *brna)
 
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name XR Event Data
+ * \{ */
+
+static void rna_def_xr_eventdata(BlenderRNA *brna)
+{
+  StructRNA *srna;
+  PropertyRNA *prop;
+
+  srna = RNA_def_struct(brna, "XrEventData", NULL);
+  RNA_def_struct_ui_text(srna, "XrEventData", "XR Data for Window Manager Event");
+
+  prop = RNA_def_property(srna, "action_set", PROP_STRING, PROP_NONE);
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+  RNA_def_property_string_funcs(
+      prop, "rna_XrEventData_action_set_get", "rna_XrEventData_action_set_length", NULL);
+  RNA_def_property_ui_text(prop, "Action Set", "XR action set name");
+
+  prop = RNA_def_property(srna, "action", PROP_STRING, PROP_NONE);
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+  RNA_def_property_string_funcs(
+      prop, "rna_XrEventData_action_get", "rna_XrEventData_action_length", NULL);
+  RNA_def_property_ui_text(prop, "Action", "XR action name");
+
+  prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+  RNA_def_property_enum_items(prop, rna_enum_xr_action_types);
+  RNA_def_property_enum_funcs(prop, "rna_XrEventData_type_get", NULL, NULL);
+  RNA_def_property_ui_text(prop, "Type", "XR action type");
+
+  prop = RNA_def_property(srna, "state", 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_XrEventData_state_get", NULL, NULL);
+  RNA_def_property_ui_text(prop, "State", "XR action values corresponding to type");
+
+  prop = RNA_def_property(srna, "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_XrEventData_state_other_get", NULL, NULL);
+  RNA_def_property_ui_text(
+      prop, "State Other", "State of the other user path for bimanual actions");
+
+  prop = RNA_def_property(srna, "float_threshold", PROP_FLOAT, PROP_NONE);
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+  RNA_def_property_float_funcs(prop, "rna_XrEventData_float_threshold_get", NULL, NULL);
+  RNA_def_property_ui_text(prop, "Float Threshold", "Input threshold for float/2D vector actions");
+
+  prop = RNA_def_property(srna, "controller_location", 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_XrEventData_controller_location_get", NULL, NULL);
+  RNA_def_property_ui_text(prop,
+                           "Controller Location",
+                           "Location of the action's corresponding controller aim in world space");
+
+  prop = RNA_def_property(srna, "controller_rotation", 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_XrEventData_controller_rotation_get", NULL, NULL);
+  RNA_def_property_ui_text(prop,
+                           "Controller Rotation",
+                           "Rotation of the action's corresponding controller aim in world space");
+
+  prop = RNA_def_property(srna, "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_XrEventData_controller_location_other_get", NULL, NULL);
+  RNA_def_property_ui_text(prop,
+                           "Controller Location Other",
+                           "Controller aim location of the other user path for bimanual actions");
+
+  prop = RNA_def_property(srna, "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_XrEventData_controller_rotation_other_get", NULL, NULL);
+  RNA_def_property_ui_text(prop,
+                           "Controller Rotation Other",
+                           "Controller aim rotation of the other user path for bimanual actions");
+
+  prop = RNA_def_property(srna, "bimanual", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+  RNA_def_property_boolean_funcs(prop, "rna_XrEventData_bimanual_get", NULL);
+  RNA_def_property_ui_text(prop, "Bimanual", "Whether bimanual interaction is occurring");
+}
+
+/** \} */
+
 void RNA_def_xr(BlenderRNA *brna)
 {
   RNA_define_animate_sdna(false);
@@ -1831,6 +2068,7 @@ void RNA_def_xr(BlenderRNA 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list