Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kim <pk15950@gmail.com>2021-10-12 07:09:01 +0300
committerPeter Kim <pk15950@gmail.com>2021-10-12 07:48:12 +0300
commitcdeb506008e9fc6d8d9a48ce90204ec10101cdd0 (patch)
tree0652dc8128c52173a587f464b96392c22f3e3679 /source/blender/makesrna/intern/rna_xr.c
parent4b31a21bcd19b5005cb46895186ca7ecf314c4db (diff)
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
Diffstat (limited to 'source/blender/makesrna/intern/rna_xr.c')
-rw-r--r--source/blender/makesrna/intern/rna_xr.c238
1 files changed, 238 insertions, 0 deletions
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 *brna)
rna_def_xr_actionmap(brna);
rna_def_xr_session_settings(brna);
rna_def_xr_session_state(brna);
+ rna_def_xr_eventdata(brna);
RNA_define_animate_sdna(true);
}