[Bf-blender-cvs] [d1b2ed706cd] xr-dev: XR: Add mouse event simulation

Peter Kim noreply at git.blender.org
Mon Dec 12 13:34:12 CET 2022


Commit: d1b2ed706cd22defd109729e5809e20011fa5d7b
Author: Peter Kim
Date:   Mon Dec 12 21:26:01 2022 +0900
Branches: xr-dev
https://developer.blender.org/rBd1b2ed706cd22defd109729e5809e20011fa5d7b

XR: Add mouse event simulation

Updated version of https://developer.blender.org/D13153.

This enables practical use of more Blender operators in VR by
converting 3D controller positions to 2D mouse positions as well as
simulating the event type (LEFTMOUSE, MOUSEMOVE...) and value
(PRESS, CLICK...) based on VR controller inputs. In this way, the
view3d.select operator can be used in VR without any modifications to
the operator logic, enabling selection of armatures, empties, etc. in
VR.

If an XR action's simulate_mouse property is set, the 3D position of
the corresponding controller aim pose will be projected to a 2D mouse
position using the perspective of the user's preferred eye
(XrSessionSettings.projection_eye) and the result stored in
wmEvent.xy/mval. In this way, operators can make use of these mouse
values as usual, without needing to know that the event is an XR event.

Along with mouse coordinate simulation, the XR event type and value
can be simulated as a different wmEvent type/value during handling,
where this mapping is configurable via the XrActionMapItem.simulate
(XrSimulateMouseParams) property of an XR action map item. The
simulated type/value can be individually set for press, hold (modal
operators only), and release VR button interactions, depending on the
operator execution mode (XrActionMapItem.op_mode).

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

M	source/blender/editors/include/ED_view3d.h
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/gizmo/intern/wm_gizmo_map.c
M	source/blender/windowmanager/intern/wm_event_system.cc
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_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/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 040a2b13adb..6af7400d458 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -1346,7 +1346,7 @@ void ED_view3d_local_collections_reset(struct bContext *C, bool reset_all);
 #ifdef WITH_XR_OPENXR
 void ED_view3d_xr_mirror_update(const struct ScrArea *area, const struct View3D *v3d, bool enable);
 void ED_view3d_xr_shading_update(struct wmWindowManager *wm,
-                                 const View3D *v3d,
+                                 const struct View3D *v3d,
                                  const struct Scene *scene);
 bool ED_view3d_is_region_xr_mirror_active(const struct wmWindowManager *wm,
                                           const struct View3D *v3d,
diff --git a/source/blender/makesdna/DNA_xr_types.h b/source/blender/makesdna/DNA_xr_types.h
index fa590c69728..502d711ae5a 100644
--- a/source/blender/makesdna/DNA_xr_types.h
+++ b/source/blender/makesdna/DNA_xr_types.h
@@ -30,7 +30,9 @@ typedef struct XrSessionSettings {
   char draw_flags;
   /** Draw style for controller visualization. */
   char controller_draw_style;
-  char _pad2[2];
+  /** The eye (view) used for 3D->2D projection when simulating mouse. */
+  char projection_eye;
+  char _pad2;
 
   /** Clipping distance. */
   float clip_start, clip_end;
@@ -71,6 +73,11 @@ typedef enum eXrSessionControllerDrawStyle {
   XR_CONTROLLER_DRAW_LIGHT_RAY = 3,
 } eXrSessionControllerDrawStyle;
 
+typedef enum eXrSessionEye {
+  XR_EYE_LEFT = 0,
+  XR_EYE_RIGHT = 1,
+} eXrSessionEye;
+
 /** XR action type. Enum values match those in GHOST_XrActionType enum for consistency. */
 typedef enum eXrActionType {
   XR_BOOLEAN_INPUT = 1,
@@ -90,6 +97,8 @@ typedef enum eXrOpFlag {
 typedef enum eXrActionFlag {
   /** Action depends on two sub-action paths (i.e. two-handed/bi-manual action). */
   XR_ACTION_BIMANUAL = (1 << 0),
+  /** Whether to use controller inputs to simulate mouse inputs. */
+  XR_ACTION_SIMULATE_MOUSE = (1 << 1),
 } eXrActionFlag;
 
 typedef enum eXrHapticFlag {
@@ -174,6 +183,16 @@ typedef struct XrUserPath {
   char path[64]; /* XR_MAX_USER_PATH_LENGTH */
 } XrUserPath;
 
+typedef struct XrSimulateMouseParams {
+  short press_type; /* wmEvent.type */
+  short press_val;  /* wmEvent.val */
+  short hold_type;
+  short hold_val;
+  short release_type;
+  short release_val;
+  short _pad[2];
+} XrSimulateMouseParams;
+
 typedef struct XrActionMapItem {
   struct XrActionMapItem *next, *prev;
 
@@ -193,6 +212,9 @@ typedef struct XrActionMapItem {
   /** RNA pointer to access properties. */
   struct PointerRNA *op_properties_ptr;
 
+  /** Mouse simulation. */
+  XrSimulateMouseParams simulate;
+
   short op_flag;     /* eXrOpFlag */
   short action_flag; /* eXrActionFlag */
   short haptic_flag; /* eXrHapticFlag */
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index 83e3e4eb335..fca7c410040 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -2832,6 +2832,53 @@ static void rna_def_keyconfig(BlenderRNA *brna)
   RNA_api_keymapitem(srna);
 }
 
+#  ifdef WITH_XR_OPENXR
+/* Defined here instead of rna_xr.c to access event type/value enums. */
+static void rna_def_xr_simulate_mouse_params(BlenderRNA *brna)
+{
+  StructRNA *srna;
+  PropertyRNA *prop;
+
+  srna = RNA_def_struct(brna, "XrSimulateMouseParams", NULL);
+  RNA_def_struct_ui_text(srna,
+                         "XR Mouse Simulation Parameters",
+                         "Parameters for simulating mouse with VR controllers");
+
+  prop = RNA_def_property(srna, "press_type", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "press_type");
+  RNA_def_property_enum_items(prop, rna_enum_event_type_items);
+  RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
+  RNA_def_property_ui_text(prop, "Press Type", "Event type to simulate on VR action press");
+
+  prop = RNA_def_property(srna, "press_value", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "press_val");
+  RNA_def_property_enum_items(prop, rna_enum_event_value_items);
+  RNA_def_property_ui_text(prop, "Press Value", "Event value to simulate on VR action press");
+
+  prop = RNA_def_property(srna, "hold_type", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "hold_type");
+  RNA_def_property_enum_items(prop, rna_enum_event_type_items);
+  RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
+  RNA_def_property_ui_text(prop, "Hold Type", "Event type to simulate on VR action hold");
+
+  prop = RNA_def_property(srna, "hold_value", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "hold_val");
+  RNA_def_property_enum_items(prop, rna_enum_event_value_items);
+  RNA_def_property_ui_text(prop, "Hold Value", "Event value to simulate on VR action hold");
+
+  prop = RNA_def_property(srna, "release_type", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "release_type");
+  RNA_def_property_enum_items(prop, rna_enum_event_type_items);
+  RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
+  RNA_def_property_ui_text(prop, "Release Type", "Event type to simulate on VR action release");
+
+  prop = RNA_def_property(srna, "release_value", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "release_val");
+  RNA_def_property_enum_items(prop, rna_enum_event_value_items);
+  RNA_def_property_ui_text(prop, "Release Value", "Event value to simulate on VR action release");
+}
+#  endif
+
 void RNA_def_wm(BlenderRNA *brna)
 {
   rna_def_operator(brna);
@@ -2849,6 +2896,9 @@ void RNA_def_wm(BlenderRNA *brna)
   rna_def_windowmanager(brna);
   rna_def_keyconfig_prefs(brna);
   rna_def_keyconfig(brna);
+#  ifdef WITH_XR_OPENXR
+  rna_def_xr_simulate_mouse_params(brna);
+#  endif
 }
 
 #endif /* RNA_RUNTIME */
diff --git a/source/blender/makesrna/intern/rna_xr.c b/source/blender/makesrna/intern/rna_xr.c
index 6731243648a..a5ce059fba4 100644
--- a/source/blender/makesrna/intern/rna_xr.c
+++ b/source/blender/makesrna/intern/rna_xr.c
@@ -426,6 +426,41 @@ static void rna_XrActionMapItem_bimanual_set(PointerRNA *ptr, bool value)
 #  endif
 }
 
+static bool rna_XrActionMapItem_simulate_mouse_get(PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  XrActionMapItem *ami = ptr->data;
+  if ((ami->action_flag & XR_ACTION_SIMULATE_MOUSE) != 0) {
+    return true;
+  }
+#  else
+  UNUSED_VARS(ptr);
+#  endif
+  return false;
+}
+
+static void rna_XrActionMapItem_simulate_mouse_set(PointerRNA *ptr, bool value)
+{
+#  ifdef WITH_XR_OPENXR
+  XrActionMapItem *ami = ptr->data;
+  SET_FLAG_FROM_TEST(ami->action_flag, value, XR_ACTION_SIMULATE_MOUSE);
+#  else
+  UNUSED_VARS(ptr, value);
+#  endif
+}
+
+static PointerRNA rna_XrActionMapItem_simulate_get(PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  XrActionMapItem *ami = ptr->data;
+  XrSimulateMouseParams *simulate = &ami->simulate;
+  return rna_pointer_inherit_refine(ptr, &RNA_XrSimulateMouseParams, simulate);
+#  else
+  UNUSED_VARS(ptr);
+  return PointerRNA_NULL;
+#  endif
+}
+
 static bool rna_XrActionMapItem_haptic_match_user_paths_get(PointerRNA *ptr)
 {
 #  ifdef WITH_XR_OPENXR
@@ -1003,6 +1038,7 @@ static bool rna_XrSessionState_action_create(bContext *C,
                              &ami->user_paths,
                              ot,
                              op_properties,
+                             is_button_action ? &ami->simulate : NULL,
                              is_button_action ? ami->haptic_name : NULL,
                              is_button_action ? &haptic_duration_msec : NULL,
                              is_button_action ? &ami->haptic_frequency : NULL,
@@ -1545,6 +1581,17 @@ static bool rna_XrEventData_bimanual_get(PointerRNA *ptr)
 #  endif
 }
 
+static bool rna_XrEventData_simulate_mouse_get(PointerRNA *ptr)
+{
+#  ifdef WITH_XR_OPENXR
+  const wmXrActionData *data = ptr->data;
+  return data->simulate_mouse;
+#  else
+  UNUSED_VARS(ptr);
+  return false;
+#  endif
+}
+
 /** \} */
 
 #else /* RNA_RUNTIME */
@@ -1951,6 +1998,18 @@ static void rna_def_xr_actionmap(BlenderRNA *brna)
   RNA_def_property_ui_text(
       prop, "Bimanual", "The action depends on the states/poses of both user paths");
 
+  prop = RNA_def_property(srna, "simulate_mouse", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_funcs(
+      prop, "rna_XrActionMapItem_simulate_mouse_get", "rna_XrActionMapItem_simulate_mouse_set");
+  RNA_def_property_ui_text(
+      prop, "Simulate Mouse", "Use VR controller inputs to simulate mouse inputs");
+
+  prop = RNA_def_property(srna, "simulate", PROP_POINTER, PROP_NONE);
+  RNA_def_property_struct_type(prop, "XrSimulateMouseParams");
+  RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+  RNA_def_property_pointer_funcs(prop, "rna_XrActionMapItem_simulate_get", NULL, NULL, NULL);
+  RNA_def_property_ui_text(prop, "Simulate", "Mouse simulation parameters");
+
   prop = RNA_def_property(srna, "pose_is_controller_grip", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_funcs(prop,
                                  "rna_XrActionMapItem_pose_is_controller_grip_get",
@@ -2234,6 +2293,20 @@ static void rna_def_xr_session_settings(BlenderRNA *brna)
       {0, NULL, 0, NULL, NULL},
   };
 
+  static const EnumPropertyItem projection_eyes[] = {
+      {XR_EYE_LEFT,
+       "EYE_LEFT",
+       0,
+       "Left Eye",
+       "Use the left eye's perspective for projection when simulating mouse"},
+      {XR_EYE_RIGHT,
+       "EYE_RIGHT",
+       0,
+       "Right Eye",
+       "Use the right eye's perspective for projection when simulating mouse"},
+      {0, NULL, 0, NULL, NULL},
+  };
+
   srna = RNA_def_struct(brna, "XrSessionSettings", NULL);
   RNA_def_struct_ui_text(srna, "XR Session Settings", "");
 
@@ -2320,6 +2393,14 @@ static void rna_def_xr_session_settings(BlenderRNA *brna)
       prop, "Controller Draw Style", "Style to use when drawing VR controllers");
   RNA_def_property_update(prop, NC_WM | ND_XR_DATA_CHANGED, NULL);
 
+  prop = RNA_def_property(srna, "projection_eye", PROP_ENUM, PROP_NONE

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list