[Bf-blender-cvs] [034dd0d702a] xr-actions-D9124: XR: Move actions from keymaps to actionmaps

Peter Kim noreply at git.blender.org
Sun Mar 7 13:49:29 CET 2021


Commit: 034dd0d702a49bbe156e363f521d5b434407d20f
Author: Peter Kim
Date:   Sun Mar 7 21:40:38 2021 +0900
Branches: xr-actions-D9124
https://developer.blender.org/rB034dd0d702a49bbe156e363f521d5b434407d20f

XR: Move actions from keymaps to actionmaps

Previously, properties for XR actions were stored in keymaps but they
are now stored in a separate XR "actionmaps" system. Although the
actionmap system/API has many similarities to the keymaps, it is
significantly less complex since it does not involve any diff-ing of
default/addon/user configurations (at least at the moment).

Another big distinction between keymaps and actionmaps is that
actionmaps and properties are saved to blend files. This allows users
to set up a VR scene with actions and properties and share working
versions with others, without the need to import/export config files.
However, actionmap import/export is also supported via the addon.

There is still a fair amount of refactoring left to do but at least
this commit removes XR involvement from the keymaps while preserving
most of the existing XR action functionality (i.e. default actions
and user-configurable actions).

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

M	release/scripts/modules/bl_keymap_utils/io.py
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/editors/include/UI_interface.h
M	source/blender/editors/interface/CMakeLists.txt
M	source/blender/editors/interface/interface_templates.c
M	source/blender/makesdna/DNA_windowmanager_types.h
M	source/blender/makesdna/DNA_xr_types.h
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_ui_api.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/CMakeLists.txt
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/WM_keymap.h
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm.c
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/intern/wm_files.c
M	source/blender/windowmanager/intern/wm_keymap.c
M	source/blender/windowmanager/wm_event_types.h
A	source/blender/windowmanager/xr/intern/wm_xr_actionmap.c
M	source/blender/windowmanager/xr/intern/wm_xr_actions.c
M	source/blender/windowmanager/xr/intern/wm_xr_intern.h
M	source/creator/creator.c

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

diff --git a/release/scripts/modules/bl_keymap_utils/io.py b/release/scripts/modules/bl_keymap_utils/io.py
index cf28ac53051..7adcd799c0f 100644
--- a/release/scripts/modules/bl_keymap_utils/io.py
+++ b/release/scripts/modules/bl_keymap_utils/io.py
@@ -23,9 +23,7 @@
 
 __all__ = (
     "keyconfig_export_as_data",
-    "keyconfig_export_as_data_exec",
     "keyconfig_import_from_data",
-    "keyconfig_import_from_data_exec",
     "keyconfig_init_from_data",
     "keyconfig_merge",
     "keymap_init_from_data",
@@ -82,12 +80,6 @@ def kmi_args_as_data(kmi):
         ):
             s.append("\"repeat\": True")
 
-    if kmi.map_type == 'XR':
-        if kmi.xr_action_set:
-            s.append(f"\"xr_action_set\": '{kmi.xr_action_set}'")
-        if kmi.xr_action:
-            s.append(f"\"xr_action\": '{kmi.xr_action}'")
-
     return "{" + ", ".join(s) + "}"
 
 
@@ -143,7 +135,37 @@ def _kmi_attrs_or_none(level, kmi):
     return "".join(lines)
 
 
-def keyconfig_export_as_data_exec(export_keymaps, filepath):
+def keyconfig_export_as_data(wm, kc, filepath, *, all_keymaps=False):
+    # Alternate format
+
+    # Generate a list of keymaps to export:
+    #
+    # First add all user_modified keymaps (found in keyconfigs.user.keymaps list),
+    # then add all remaining keymaps from the currently active custom keyconfig.
+    #
+    # Sort the resulting list according to top context name,
+    # while this isn't essential, it makes comparing keymaps simpler.
+    #
+    # This will create a final list of keymaps that can be used as a "diff" against
+    # the default blender keyconfig, recreating the current setup from a fresh blender
+    # without needing to export keymaps which haven't been edited.
+
+    class FakeKeyConfig:
+        keymaps = []
+    edited_kc = FakeKeyConfig()
+    for km in wm.keyconfigs.user.keymaps:
+        if all_keymaps or km.is_user_modified:
+            edited_kc.keymaps.append(km)
+    # merge edited keymaps with non-default keyconfig, if it exists
+    if kc != wm.keyconfigs.default:
+        export_keymaps = keyconfig_merge(edited_kc, kc)
+    else:
+        export_keymaps = keyconfig_merge(edited_kc, edited_kc)
+
+    # Sort the keymap list by top context name before exporting,
+    # not essential, just convenient to order them predictably.
+    export_keymaps.sort(key=lambda k: k[0].name)
+
     with open(filepath, "w", encoding="utf-8") as fh:
         fw = fh.write
 
@@ -220,40 +242,6 @@ def keyconfig_export_as_data_exec(export_keymaps, filepath):
         fw("    )\n")
 
 
-def keyconfig_export_as_data(wm, kc, filepath, *, all_keymaps=False):
-    # Alternate format
-
-    # Generate a list of keymaps to export:
-    #
-    # First add all user_modified keymaps (found in keyconfigs.user.keymaps list),
-    # then add all remaining keymaps from the currently active custom keyconfig.
-    #
-    # Sort the resulting list according to top context name,
-    # while this isn't essential, it makes comparing keymaps simpler.
-    #
-    # This will create a final list of keymaps that can be used as a "diff" against
-    # the default blender keyconfig, recreating the current setup from a fresh blender
-    # without needing to export keymaps which haven't been edited.
-
-    class FakeKeyConfig:
-        keymaps = []
-    edited_kc = FakeKeyConfig()
-    for km in wm.keyconfigs.user.keymaps:
-        if all_keymaps or km.is_user_modified:
-            edited_kc.keymaps.append(km)
-    # merge edited keymaps with non-default keyconfig, if it exists
-    if kc != wm.keyconfigs.default:
-        export_keymaps = keyconfig_merge(edited_kc, kc)
-    else:
-        export_keymaps = keyconfig_merge(edited_kc, edited_kc)
-
-    # Sort the keymap list by top context name before exporting,
-    # not essential, just convenient to order them predictably.
-    export_keymaps.sort(key=lambda k: k[0].name)
-
-    keyconfig_export_as_data_exec(export_keymaps, filepath) 
-
-
 # -----------------------------------------------------------------------------
 # Import Functions
 
@@ -303,14 +291,6 @@ def keyconfig_init_from_data(kc, keyconfig_data):
         keymap_init_from_data(km, km_items, is_modal=km_args.get("modal", False))
 
 
-def keyconfig_import_from_data_exec(kc, keyconfig_data, keyconfig_version=(0, 0, 0)):
-    if keyconfig_version is not None:
-        from .versioning import keyconfig_update
-        keyconfig_data = keyconfig_update(keyconfig_data, keyconfig_version)
-    keyconfig_init_from_data(kc, keyconfig_data)
-    return kc
-
-
 def keyconfig_import_from_data(name, keyconfig_data, *, keyconfig_version=(0, 0, 0)):
     # Load data in the format defined above.
     #
@@ -319,7 +299,11 @@ def keyconfig_import_from_data(name, keyconfig_data, *, keyconfig_version=(0, 0,
     import bpy
     wm = bpy.context.window_manager
     kc = wm.keyconfigs.new(name)
-    keyconfig_import_from_data_exec(kc, keyconfig_data, keyconfig_version)
+    if keyconfig_version is not None:
+        from .versioning import keyconfig_update
+        keyconfig_data = keyconfig_update(keyconfig_data, keyconfig_version)
+    keyconfig_init_from_data(kc, keyconfig_data)
+    return kc
 
 
 # -----------------------------------------------------------------------------
diff --git a/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py b/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py
index b6ef83f0fe4..0784a91d174 100644
--- a/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py
+++ b/release/scripts/modules/bl_keymap_utils/keymap_hierarchy.py
@@ -63,10 +63,6 @@ _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 6ee064631b9..6076bf00063 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', 'XR'}:
+        if map_type not in {'TEXTINPUT', 'TIMER'}:
             sub = split.column()
             subrow = sub.row(align=True)
 
@@ -204,12 +204,6 @@ 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 0ed04b859de..874a8baa958 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -729,28 +729,6 @@ 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
 
@@ -7035,8 +7013,6 @@ def generate_keymaps(params=None):
         km_view2d(params),
         km_view2d_buttons_list(params),
         km_user_interface(params),
-        km_xr(params),
-        km_xr_session(params),
 
         # Editors.
         km_property_editor(params),
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 5620d39ab16..536d1871813 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2123,6 +2123,7 @@ void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C);
 void uiTemplateReportsBanner(uiLayout *layout, struct bContext *C);
 void uiTemplateInputStatus(uiLayout *layout, struct bContext *C);
 void uiTemplateKeymapItemProperties(uiLayout *layout, struct PointerRNA *ptr);
+void uiTemplateXrActionmapItemProperties(uiLayout *layout, struct PointerRNA *ptr);
 
 bool uiTemplateEventFromKeymapItem(struct uiLayout *layout,
                                    const char *text,
diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt
index 82bcd5d7eb4..bdea5bbde4f 100644
--- a/source/blender/editors/interface/CMakeLists.txt
+++ b/source/blender/editors/interface/CMakeLists.txt
@@ -106,5 +106,8 @@ if(WIN32)
   endif()
 endif()
 
+if(WITH_XR_OPENXR)
+  add_definitions(-DWITH_XR_OPENXR)
+endif()
 
 blender_add_lib(bf_editor_interface "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index c5e67e0334e..d37b4605981 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -7016,6 +7016,42 @@ void uiTemplateKeymapItemProperties(uiLayout *layout, PointerRNA *ptr)
 
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name XR Actionmap Template
+ * \{ */
+
+static void xr_actionmap_item_modified(bContext *UNUS

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list