[Bf-blender-cvs] [1d86e1ff467] xr-actions-D9124: XR: Support operator properties for actions

Peter Kim noreply at git.blender.org
Mon Oct 26 18:17:53 CET 2020


Commit: 1d86e1ff4676416f51b21b322e6b0fe53490df28
Author: Peter Kim
Date:   Tue Oct 27 01:54:03 2020 +0900
Branches: xr-actions-D9124
https://developer.blender.org/rB1d86e1ff4676416f51b21b322e6b0fe53490df28

XR: Support operator properties for actions

Pointers to op properties are stored in the XR session state as
IDProperty* and applied upon op execution. The actual properties
themselves are stored as key map items (new "XR" and "XR Session"
key maps were added to the blender default key maps).

The "XR" key map is intended to store op properties for action sets
that are saved in add-on (e.g. the VR Scene Inspection add-on) prefs.
The "XR Session" key map is intended to store op properties for scene
action sets, with these properties used for the XR session.

In this way, scene action sets can configure properties without
worrying about overwriting properties for action sets saved in prefs.

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

M	intern/ghost/GHOST_Types.h
M	release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py
M	release/scripts/modules/rna_keymap_ui.py
M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	source/blender/makesdna/DNA_screen_types.h
M	source/blender/makesdna/DNA_windowmanager_types.h
M	source/blender/makesrna/intern/rna_screen.c
M	source/blender/makesrna/intern/rna_wm.c
M	source/blender/makesrna/intern/rna_wm_api.c
M	source/blender/makesrna/intern/rna_xr.c
M	source/blender/windowmanager/WM_keymap.h
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/intern/wm_keymap.c
M	source/blender/windowmanager/wm_event_types.h
M	source/blender/windowmanager/xr/intern/wm_xr_actions.c
M	source/blender/windowmanager/xr/intern/wm_xr_intern.h
M	source/blender/windowmanager/xr/intern/wm_xr_session.c

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

diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index 5ffca42eefe..92b628e45c9 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -712,11 +712,12 @@ typedef struct GHOST_XrActionInfo {
   /** Previous states, stored to determine XR events. */
   void *states_prev;
 
-  /** Input threshold for float actions. */
+  /** Input threshold for float actions (only used by wm). */
   float threshold;
 
-  /** wmOperatorType and wmXrOpFlag, only used by wm. */
+  /** Operator to be called on XR events (only used by wm). */
   void *ot;
+  void *op_properties;
   char op_flag;
 } GHOST_XrActionInfo;
 
diff --git a/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py b/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py
index 52b9f1601d5..f1263cb9b54 100644
--- a/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py
+++ b/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py
@@ -63,6 +63,10 @@ _km_hierarchy = [
 
     ('User Interface', 'EMPTY', 'WINDOW', []),
 
+    ('XR', 'EMPTY', 'XR', [ # op properties for XR action sets saved in prefs 
+        ('XR Session', 'EMPTY', 'XR', []),  # op properties for scene XR action sets  
+    ]),
+
     ('3D View', 'VIEW_3D', 'WINDOW', [  # view 3d navigation and generic stuff (select, transform)
         ('Object Mode', 'EMPTY', 'WINDOW', [
             _km_expand_from_toolsystem('VIEW_3D', 'OBJECT'),
diff --git a/release/scripts/modules/rna_keymap_ui.py b/release/scripts/modules/rna_keymap_ui.py
index 6076bf00063..6ee064631b9 100644
--- a/release/scripts/modules/rna_keymap_ui.py
+++ b/release/scripts/modules/rna_keymap_ui.py
@@ -182,7 +182,7 @@ def draw_kmi(display_keymaps, kc, km, kmi, layout, level):
             # sub.prop_search(kmi, "idname", bpy.context.window_manager, "operators_all", text="")
             sub.prop(kmi, "idname", text="")
 
-        if map_type not in {'TEXTINPUT', 'TIMER'}:
+        if map_type not in {'TEXTINPUT', 'TIMER', 'XR'}:
             sub = split.column()
             subrow = sub.row(align=True)
 
@@ -204,6 +204,12 @@ def draw_kmi(display_keymaps, kc, km, kmi, layout, level):
             subrow.prop(kmi, "alt", toggle=True)
             subrow.prop(kmi, "oskey", text="Cmd", toggle=True)
             subrow.prop(kmi, "key_modifier", text="", event=True)
+        elif map_type == 'XR':
+            sub = split.column()
+            subrow = sub.row(align=True)
+            subrow.prop(kmi, "xr_action_set", text="Action Set")
+            subrow = sub.row()
+            subrow.prop(kmi, "xr_action", text="Action")
 
         # Operator properties
         box.template_keymap_item_properties(kmi)
diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 37457892033..6643ac8f354 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -721,6 +721,28 @@ def km_user_interface(_params):
     return keymap
 
 
+def km_xr(_params):
+    items = []
+    keymap = (
+        "XR",
+        {"space_type": 'EMPTY', "region_type": 'XR'},
+        {"items": items},
+    )
+
+    return keymap
+
+
+def km_xr_session(_params):
+    items = []
+    keymap = (
+        "XR Session",
+        {"space_type": 'EMPTY', "region_type": 'XR'},
+        {"items": items},
+    )
+
+    return keymap
+
+
 # ------------------------------------------------------------------------------
 # Editors
 
@@ -6840,9 +6862,11 @@ def generate_keymaps(params=None):
         km_view2d(params),
         km_view2d_buttons_list(params),
         km_user_interface(params),
-        km_property_editor(params),
+        km_xr(params),
+        km_xr_session(params),
 
         # Editors.
+        km_property_editor(params),
         km_outliner(params),
         km_uv_editor(params),
         km_view3d_generic(params),
diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h
index c650b441895..28b0a1b96c7 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -637,7 +637,7 @@ typedef enum eRegionType {
   RGN_TYPE_FOOTER = 11,
   RGN_TYPE_TOOL_HEADER = 12,
   /* Region representing an XR headset's display (internally, corresponds to an XR surface). */
-  RGN_TYPE_XR_DISPLAY = 13,
+  RGN_TYPE_XR = 13,
 
 #define RGN_TYPE_LEN (RGN_TYPE_TOOL_HEADER + 1)
 } eRegionType;
diff --git a/source/blender/makesdna/DNA_windowmanager_types.h b/source/blender/makesdna/DNA_windowmanager_types.h
index 3f7e3e61d56..6c12a7e6443 100644
--- a/source/blender/makesdna/DNA_windowmanager_types.h
+++ b/source/blender/makesdna/DNA_windowmanager_types.h
@@ -355,6 +355,10 @@ typedef struct wmKeyMapItem {
   short shift, ctrl, alt, oskey;
   /** Rawkey modifier. */
   short keymodifier;
+  /** XR action set name. */
+  char xr_action_set[64];
+  /** XR action name. */
+  char xr_action[64];
 
   /* flag: inactive, expanded */
   short flag;
@@ -394,6 +398,7 @@ enum {
   KMI_TYPE_TEXTINPUT = 3,
   KMI_TYPE_TIMER = 4,
   KMI_TYPE_NDOF = 5,
+  KMI_TYPE_XR = 6,
 };
 
 /* stored in WM, the actively used keymaps */
diff --git a/source/blender/makesrna/intern/rna_screen.c b/source/blender/makesrna/intern/rna_screen.c
index 7e066ef3a72..cf04bc3da4c 100644
--- a/source/blender/makesrna/intern/rna_screen.c
+++ b/source/blender/makesrna/intern/rna_screen.c
@@ -46,7 +46,7 @@ const EnumPropertyItem rna_enum_region_type_items[] = {
     {RGN_TYPE_EXECUTE, "EXECUTE", 0, "Execute Buttons", ""},
     {RGN_TYPE_FOOTER, "FOOTER", 0, "Footer", ""},
     {RGN_TYPE_TOOL_HEADER, "TOOL_HEADER", 0, "Tool Header", ""},
-    {RGN_TYPE_XR_DISPLAY, "XR_DISPLAY", 0, "XR Display", ""},
+    {RGN_TYPE_XR, "XR", 0, "XR", ""},
     {0, NULL, 0, NULL, NULL},
 };
 
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index 310593efb64..598e1751bb1 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -169,6 +169,11 @@ static const EnumPropertyItem event_ndof_type_items[] = {
     {NDOF_BUTTON_C, "NDOF_BUTTON_C", 0, "Button C", ""},
     {0, NULL, 0, NULL, NULL},
 };
+
+static const EnumPropertyItem event_xr_type_items[] = {
+    {EVT_XR_ACTION, "XR_ACTION", 0, "XR Action", ""},
+    {0, NULL, 0, NULL, NULL},
+};
 #endif /* RNA_RUNTIME */
 
 /* not returned: CAPSLOCKKEY, UNKNOWNKEY */
@@ -392,7 +397,7 @@ const EnumPropertyItem rna_enum_event_type_items[] = {
      "ActionZone Fullscreen",
      "AZone FullScr"},
     /* xr */
-    {EVT_XR_ACTION, "XR_ACTION", 0, "XR action", ""},
+    {EVT_XR_ACTION, "XR_ACTION", 0, "XR Action", ""},
     {0, NULL, 0, NULL, NULL},
 };
 
@@ -1050,6 +1055,10 @@ static void rna_wmKeyMapItem_map_type_set(PointerRNA *ptr, int value)
         kmi->type = NDOF_MOTION;
         kmi->val = KM_NOTHING;
         break;
+      case KMI_TYPE_XR:
+        kmi->type = EVT_XR_ACTION;
+        kmi->val = KM_NOTHING;
+        break;
     }
   }
 }
@@ -1074,6 +1083,48 @@ static void rna_wmKeyMapItem_keymodifier_set(PointerRNA *ptr, int value)
   }
 }
 
+static void rna_wmKeyMapItem_xr_action_set_get(PointerRNA *ptr, char *value)
+{
+  wmKeyMapItem *kmi = ptr->data;
+  strcpy(value, kmi->xr_action_set);
+}
+
+static int rna_wmKeyMapItem_xr_action_set_length(PointerRNA *ptr)
+{
+  wmKeyMapItem *kmi = ptr->data;
+  return strlen(kmi->xr_action_set);
+}
+
+static void rna_wmKeyMapItem_xr_action_set_set(PointerRNA *ptr, const char *value)
+{
+  wmKeyMapItem *kmi = ptr->data;
+
+  if (!STREQ(value, kmi->xr_action_set)) {
+    strcpy(kmi->xr_action_set, value);
+  }
+}
+
+static void rna_wmKeyMapItem_xr_action_get(PointerRNA *ptr, char *value)
+{
+  wmKeyMapItem *kmi = ptr->data;
+  strcpy(value, kmi->xr_action);
+}
+
+static int rna_wmKeyMapItem_xr_action_length(PointerRNA *ptr)
+{
+  wmKeyMapItem *kmi = ptr->data;
+  return strlen(kmi->xr_action);
+}
+
+static void rna_wmKeyMapItem_xr_action_set(PointerRNA *ptr, const char *value)
+{
+  wmKeyMapItem *kmi = ptr->data;
+
+  if (!STREQ(value, kmi->xr_action)) {
+    strcpy(kmi->xr_action, value);
+  }
+}
+
 static const EnumPropertyItem *rna_KeyMapItem_type_itemf(bContext *UNUSED(C),
                                                          PointerRNA *ptr,
                                                          PropertyRNA *UNUSED(prop),
@@ -1096,6 +1147,9 @@ static const EnumPropertyItem *rna_KeyMapItem_type_itemf(bContext *UNUSED(C),
   if (map_type == KMI_TYPE_TEXTINPUT) {
     return event_textinput_type_items;
   }
+  if (map_type == KMI_TYPE_XR) {
+    return event_xr_type_items;
+  }
   else {
     return rna_enum_event_type_items;
   }
@@ -2770,6 +2824,7 @@ static void rna_def_keyconfig(BlenderRNA *brna)
       {KMI_TYPE_NDOF, "NDOF", 0, "NDOF", ""},
       {KMI_TYPE_TEXTINPUT, "TEXTINPUT", 0, "Text Input", ""},
       {KMI_TYPE_TIMER, "TIMER", 0, "Timer", ""},
+      {KMI_TYPE_XR, "XR", 0, "XR", ""},
       {0, NULL, 0, NULL, NULL},
   };
 
@@ -2963,6 +3018,26 @@ static void rna_def_keyconfig(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Key Modifier", "Regular key pressed as a modifier");
   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
 
+  prop = RNA_def_property(srna, "xr_action_set", PROP_STRING, PROP_NONE);
+  RNA_def_property_string_sdna(prop, NULL, "xr_action_set");
+  RNA_def_property_ui_text(prop, "XR Action Set", "XR action set name");
+  RNA_def_property_string_funcs(prop,
+    "rna_wmKeyMapItem_xr_action_set_get",
+    "rna_wmKeyMapItem_xr_action_set_length",
+    "rna_wmKeyMapItem_xr_action_set_set");
+  RNA_def_struct_name_property(srna, prop);
+  RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
+
+  prop = RNA_def_property(srna, "xr_action", PROP_STRING, PROP_NONE);
+  RNA_def_property_string_sdna(prop, NULL, "xr_action");
+  RNA_def_property_ui_text(prop, "XR Action", "XR action name");
+  RNA_def_property_string_funcs(prop,
+    "rna_wmKeyMapItem_xr_action_get",
+    "rna_wmKeyMapItem_xr_action_length",
+    "rna_wmKeyMapItem_xr_action_set");
+  RNA_def_struct_name_property(srna, prop);
+  RNA_def_property_update(prop, 0, "rna_KeyMapItem_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list