[Bf-extensions-cvs] [b40fd578] xr-actions-D9124: VR: Add default action sets

Peter Kim noreply at git.blender.org
Mon Feb 8 15:54:52 CET 2021


Commit: b40fd578cd113af0c243c06ef9d12ab4e2b7ae24
Author: Peter Kim
Date:   Mon Feb 8 23:52:57 2021 +0900
Branches: xr-actions-D9124
https://developer.blender.org/rBAb40fd578cd113af0c243c06ef9d12ab4e2b7ae24

VR: Add default action sets

Default action sets are defined in defaults.py and will automatically
be loaded if the scene does not already contain action sets.
The accompanying operator properties for default VR actions are
defined in defaults.xrkey.py.

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

A	viewport_vr_preview/__init__.py
A	viewport_vr_preview/defaults.py
A	viewport_vr_preview/defaults.xrkey.py
R089	viewport_vr_preview.py	viewport_vr_preview/main.py

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

diff --git a/viewport_vr_preview/__init__.py b/viewport_vr_preview/__init__.py
new file mode 100644
index 00000000..d89018f3
--- /dev/null
+++ b/viewport_vr_preview/__init__.py
@@ -0,0 +1,213 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+bl_info = {
+    "name": "VR Scene Inspection",
+    "author": "Julian Eisel (Severin), Sebastian Koenig",
+    "version": (0, 9, 0),
+    "blender": (2, 90, 0),
+    "location": "3D View > Sidebar > VR",
+    "description": ("View the viewport with virtual reality glasses "
+                    "(head-mounted displays)"),
+    "support": "OFFICIAL",
+    "warning": "This is an early, limited preview of in development "
+               "VR support for Blender.",
+    "doc_url": "{BLENDER_MANUAL_URL}/addons/3d_view/vr_scene_inspection.html",
+    "category": "3D View",
+}
+
+if "bpy" in locals():
+    import importlib
+    importlib.reload(main)
+    importlib.reload(defaults)
+else:
+    from . import main, defaults
+
+import bpy
+from bpy.props import (
+    CollectionProperty,
+    IntProperty,
+    BoolProperty,
+)
+
+classes = (
+    main.VIEW3D_PT_vr_session,
+    main.VIEW3D_PT_vr_session_view,
+    main.VIEW3D_PT_vr_landmarks,
+    main.VIEW3D_PT_vr_actions,
+    main.VIEW3D_PT_vr_motion_capture,
+    main.VIEW3D_PT_vr_viewport_feedback,
+
+    main.VRLandmark,
+    main.VIEW3D_UL_vr_landmarks,
+    main.VIEW3D_MT_vr_landmark_menu,
+
+    main.VIEW3D_OT_vr_landmark_add,
+    main.VIEW3D_OT_vr_landmark_remove,
+    main.VIEW3D_OT_vr_landmark_activate,
+    main.VIEW3D_OT_vr_landmark_from_session,
+    main.VIEW3D_OT_add_camera_from_vr_landmark,
+    main.VIEW3D_OT_camera_to_vr_landmark,
+    main.VIEW3D_OT_vr_landmark_from_camera,
+    main.VIEW3D_OT_cursor_to_vr_landmark,
+    main.VIEW3D_OT_update_vr_landmark,
+
+    main.VRAction,
+    main.VRActionSet,
+    main.VIEW3D_UL_vr_action_sets,
+    main.VIEW3D_MT_vr_action_set_menu,
+    main.VIEW3D_UL_vr_actions,
+    main.VIEW3D_MT_vr_action_menu,
+
+    main.VIEW3D_OT_vr_action_set_add,
+    main.VIEW3D_OT_vr_action_set_remove,
+    main.VIEW3D_OT_vr_action_set_activate,
+    main.VIEW3D_OT_vr_action_sets_load_from_prefs,
+    main.VIEW3D_OT_vr_action_set_save_to_prefs,
+    main.VIEW3D_OT_vr_action_set_copy,
+    main.VIEW3D_OT_vr_action_sets_clear,
+    main.VIEW3D_OT_vr_action_add,
+    main.VIEW3D_OT_vr_action_remove,
+    main.VIEW3D_OT_vr_actions_clear,
+
+    main.VIEW3D_GT_vr_camera_cone,
+    main.VIEW3D_GT_vr_controller_axes,
+    main.VIEW3D_GGT_vr_viewer_pose,
+    main.VIEW3D_GGT_vr_controller_poses,
+    main.VIEW3D_GGT_vr_landmarks,
+
+    main.VRPreferences,
+    #main.PREFERENCES_PT_vr_actions,
+    main.PREFERENCES_UL_vr_action_sets,
+    main.PREFERENCES_MT_vr_action_set_menu,
+    main.PREFERENCES_UL_vr_actions,
+    main.PREFERENCES_MT_vr_action_menu,
+
+    main.PREFERENCES_OT_vr_action_set_add,
+    main.PREFERENCES_OT_vr_action_set_remove,
+    main.PREFERENCES_OT_vr_action_set_copy,
+    main.PREFERENCES_OT_vr_action_sets_clear,
+    main.PREFERENCES_OT_vr_action_add,
+    main.PREFERENCES_OT_vr_action_remove,
+    main.PREFERENCES_OT_vr_actions_clear,
+)
+
+
+def register():
+    if not bpy.app.build_options.xr_openxr:
+        bpy.utils.register_class(main.VIEW3D_PT_vr_info)
+        return
+
+    for cls in classes:
+        bpy.utils.register_class(cls)
+
+    bpy.types.Scene.vr_landmarks = CollectionProperty(
+        name="Landmark",
+        type=main.VRLandmark,
+    )
+    bpy.types.Scene.vr_landmarks_selected = IntProperty(
+        name="Selected Landmark"
+    )
+    bpy.types.Scene.vr_landmarks_active = IntProperty(
+        update=main.vr_landmark_active_update,
+    )
+    bpy.types.Scene.vr_action_sets = CollectionProperty(
+        name="Action Set",
+        type=main.VRActionSet,
+    )	
+    bpy.types.Scene.vr_action_sets_selected = IntProperty(
+        name="Selected Action Set",
+    )	
+    bpy.types.Scene.vr_action_sets_active = IntProperty(
+        default=0,
+        update=main.vr_action_set_active_update,
+    )
+    bpy.types.Scene.vr_headset_object = bpy.props.PointerProperty(
+        name="Headset Object",
+        type=bpy.types.Object,
+        update=main.vr_headset_object_update,
+    )
+    bpy.types.Scene.vr_controller0_object = bpy.props.PointerProperty(
+        name="Controller 0 Object",
+        type=bpy.types.Object,
+        update=main.vr_controller0_object_update,
+    )
+    bpy.types.Scene.vr_controller1_object = bpy.props.PointerProperty(
+        name="Controller 1 Object",
+        type=bpy.types.Object,
+        update=main.vr_controller1_object_update,
+    )
+    # View3DShading is the only per 3D-View struct with custom property
+    # support, so "abusing" that to get a per 3D-View option.
+    bpy.types.View3DShading.vr_show_virtual_camera = BoolProperty(
+        name="Show VR Camera"
+    )
+    bpy.types.View3DShading.vr_show_controllers = BoolProperty(
+        name="Show VR Controllers"
+    )
+    bpy.types.View3DShading.vr_show_landmarks = BoolProperty(
+        name="Show Landmarks"
+    )
+
+    bpy.app.handlers.load_post.append(main.vr_ensure_default_landmark)
+    bpy.app.handlers.load_post.append(main.vr_load_action_properties)
+    bpy.app.handlers.load_post.append(defaults.vr_load_default_action_sets)
+    bpy.app.handlers.save_post.append(main.vr_save_action_properties)
+    bpy.app.handlers.xr_session_start_pre.append(main.vr_create_actions)
+
+    # Register add-on key map.
+    kc = bpy.context.window_manager.keyconfigs.addon
+    if kc:
+        kc.keymaps.new(name="XR Session", space_type='EMPTY', region_type='XR')
+
+
+def unregister():
+    if not bpy.app.build_options.xr_openxr:
+        bpy.utils.unregister_class(main.VIEW3D_PT_vr_info)
+        return
+
+    # Unregister add-on key map.
+    kc = bpy.context.window_manager.keyconfigs.addon
+    if kc:
+        km = kc.keymaps.find("XR Session", space_type='EMPTY', region_type='XR')
+        if km:
+            kc.keymaps.remove(km)
+
+    for cls in classes:
+        bpy.utils.unregister_class(cls)
+
+    del bpy.types.Scene.vr_landmarks
+    del bpy.types.Scene.vr_landmarks_selected
+    del bpy.types.Scene.vr_landmarks_active
+    del bpy.types.Scene.vr_action_sets
+    del bpy.types.Scene.vr_action_sets_selected
+    del bpy.types.Scene.vr_action_sets_active
+    del bpy.types.Scene.vr_headset_object
+    del bpy.types.Scene.vr_controller0_object
+    del bpy.types.Scene.vr_controller1_object
+    del bpy.types.View3DShading.vr_show_virtual_camera
+    del bpy.types.View3DShading.vr_show_controllers
+    del bpy.types.View3DShading.vr_show_landmarks
+
+    bpy.app.handlers.load_post.remove(main.vr_ensure_default_landmark)
+    bpy.app.handlers.load_post.remove(main.vr_load_action_properties)
+    bpy.app.handlers.load_post.remove(defaults.vr_load_default_action_sets)
+    bpy.app.handlers.save_post.remove(main.vr_save_action_properties)
+    bpy.app.handlers.xr_session_start_pre.remove(main.vr_create_actions)
diff --git a/viewport_vr_preview/defaults.py b/viewport_vr_preview/defaults.py
new file mode 100644
index 00000000..4da93904
--- /dev/null
+++ b/viewport_vr_preview/defaults.py
@@ -0,0 +1,412 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+import bpy
+from bpy.app.handlers import persistent
+import os.path, importlib.util, math
+from enum import Enum
+from bl_keymap_utils.io import keyconfig_import_from_data_exec
+
+def vr_defaults_action_set_add(scene, name, profile):
+    bpy.ops.view3d.vr_action_set_add()
+    
+    action_set = scene.vr_action_sets[scene.vr_action_sets_selected]
+    if action_set:
+        action_set.name = name
+        action_set.profile = profile
+        
+    return action_set
+
+
+def vr_defaults_action_set_remove(scene, name):
+    action_set_selected_prev = scene.vr_action_sets_selected
+    
+    idx = 0
+    for action_set in scene.vr_action_sets:
+        if (action_set.name == name):
+            scene.vr_action_sets_selected = idx
+
+            bpy.ops.view3d.vr_action_set_remove()
+
+            scene.vr_action_sets_selected = action_set_selected_prev
+            return
+
+        idx += 1
+
+
+def vr_defaults_action_add(action_set,
+                           name,
+                           user_path0,
+                           component_path0,
+                           user_path1,
+                           component_path1,
+                           threshold,
+                           op,
+                           op_flag):
+    bpy.ops.view3d.vr_action_add()
+    
+    action = action_set.actions[action_set.actions_selected]
+    if action:        
+        action.name = name
+    

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list