[Bf-extensions-cvs] [7a45dbed] xr-controller-support: VR: Split code into more focused modules
Peter Kim
noreply at git.blender.org
Thu Sep 2 06:56:24 CEST 2021
Commit: 7a45dbeda20292a168dccdac102e52018c416c5c
Author: Peter Kim
Date: Thu Sep 2 13:34:45 2021 +0900
Branches: xr-controller-support
https://developer.blender.org/rBA7a45dbeda20292a168dccdac102e52018c416c5c
VR: Split code into more focused modules
Reflects changes from D11271.
===================================================================
M viewport_vr_preview/__init__.py
A viewport_vr_preview/action_map.py
R098 viewport_vr_preview/io.py viewport_vr_preview/action_map_io.py
M viewport_vr_preview/configs/default.py
M viewport_vr_preview/defaults.py
A viewport_vr_preview/gui.py
D viewport_vr_preview/main.py
A viewport_vr_preview/operators.py
A viewport_vr_preview/properties.py
===================================================================
diff --git a/viewport_vr_preview/__init__.py b/viewport_vr_preview/__init__.py
index a70dd847..216fec5e 100644
--- a/viewport_vr_preview/__init__.py
+++ b/viewport_vr_preview/__init__.py
@@ -36,156 +36,36 @@ bl_info = {
if "bpy" in locals():
import importlib
+ importlib.reload(action_map)
importlib.reload(defaults)
- importlib.reload(main)
+ importlib.reload(gui)
+ importlib.reload(operators)
+ importlib.reload(properties)
else:
- from . import defaults, main
+ from . import action_map, defaults, gui, operators, properties
import bpy
-classes = (
- main.VIEW3D_PT_vr_session,
- main.VIEW3D_PT_vr_session_view,
- main.VIEW3D_PT_vr_landmarks,
- main.VIEW3D_PT_vr_actions_actionmaps,
- main.VIEW3D_PT_vr_actions_actions,
- main.VIEW3D_PT_vr_actions_haptics,
- main.VIEW3D_PT_vr_actions_bindings,
- main.VIEW3D_PT_vr_actions_extensions,
- 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.VIEW3D_UL_vr_actionmaps,
- main.VIEW3D_MT_vr_actionmap_menu,
- main.VIEW3D_UL_vr_actions,
- main.VIEW3D_MT_vr_action_menu,
- main.VIEW3D_UL_vr_actionbindings,
- main.VIEW3D_MT_vr_actionbinding_menu,
-
- main.VIEW3D_OT_vr_actionmap_add,
- main.VIEW3D_OT_vr_actionmap_remove,
- main.VIEW3D_OT_vr_actionmap_activate,
- main.VIEW3D_OT_vr_actionmaps_defaults_load,
- main.VIEW3D_OT_vr_actionmaps_import,
- main.VIEW3D_OT_vr_actionmaps_export,
- main.VIEW3D_OT_vr_actionmap_copy,
- main.VIEW3D_OT_vr_actionmaps_clear,
- main.VIEW3D_OT_vr_action_add,
- main.VIEW3D_OT_vr_action_remove,
- main.VIEW3D_OT_vr_action_copy,
- main.VIEW3D_OT_vr_actions_clear,
- main.VIEW3D_OT_vr_actionbinding_add,
- main.VIEW3D_OT_vr_actionbinding_remove,
- main.VIEW3D_OT_vr_actionbinding_copy,
- main.VIEW3D_OT_vr_actionbindings_clear,
-
- main.VRMotionCaptureObject,
- main.VIEW3D_UL_vr_mocap_objects,
- main.VIEW3D_MT_vr_mocap_object_menu,
-
- main.VIEW3D_OT_vr_mocap_object_add,
- main.VIEW3D_OT_vr_mocap_object_remove,
- main.VIEW3D_OT_vr_mocap_object_help,
-
- main.VIEW3D_GT_vr_camera_cone,
- main.VIEW3D_GT_vr_controller_grip,
- main.VIEW3D_GT_vr_controller_aim,
- main.VIEW3D_GGT_vr_viewer_pose,
- main.VIEW3D_GGT_vr_controller_poses,
- main.VIEW3D_GGT_vr_landmarks,
-)
-
-
def register():
if not bpy.app.build_options.xr_openxr:
- bpy.utils.register_class(main.VIEW3D_PT_vr_info)
+ bpy.utils.register_class(gui.VIEW3D_PT_vr_info)
return
- for cls in classes:
- bpy.utils.register_class(cls)
-
- bpy.types.Scene.vr_landmarks = bpy.props.CollectionProperty(
- name="Landmark",
- type=main.VRLandmark,
- )
- bpy.types.Scene.vr_landmarks_selected = bpy.props.IntProperty(
- name="Selected Landmark"
- )
- bpy.types.Scene.vr_landmarks_active = bpy.props.IntProperty(
- update=main.vr_landmark_active_update,
- )
- bpy.types.Scene.vr_actions_enable_cosmos = bpy.props.BoolProperty(
- description="Enable bindings for the HTC Vive Cosmos controllers. Note that this may not be supported by all OpenXR runtimes",
- default=False,
- )
- bpy.types.Scene.vr_actions_enable_huawei = bpy.props.BoolProperty(
- description="Enable bindings for the Huawei controllers. Note that this may not be supported by all OpenXR runtimes",
- default=False,
- )
- bpy.types.Scene.vr_actions_enable_reverb_g2 = bpy.props.BoolProperty(
- description="Enable bindings for the HP Reverb G2 controllers. Note that this may not be supported by all OpenXR runtimes",
- default=False,
- )
- # This scene collection property is needed instead of directly accessing
- # XrSessionSettings.mocap_objects in the UI to avoid invalid pointers when
- # deleting objects.
- bpy.types.Scene.vr_mocap_objects = bpy.props.CollectionProperty(
- name="Motion Capture Object",
- type=main.VRMotionCaptureObject,
- )
- # 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 = bpy.props.BoolProperty(
- name="Show VR Camera"
- )
- bpy.types.View3DShading.vr_show_controllers = bpy.props.BoolProperty(
- name="Show VR Controllers"
- )
- bpy.types.View3DShading.vr_show_landmarks = bpy.props.BoolProperty(
- name="Show Landmarks"
- )
-
- bpy.app.handlers.load_post.append(main.vr_ensure_default_landmark)
- bpy.app.handlers.load_post.append(defaults.vr_init_default_actionconfig)
- bpy.app.handlers.load_post.append(main.vr_activate_user_actionconfig)
- bpy.app.handlers.xr_session_start_pre.append(main.vr_create_actions)
+ defaults.register() # Register before action_map to load defaults before activating user action config.
+ action_map.register()
+ gui.register()
+ operators.register()
+ properties.register()
def unregister():
if not bpy.app.build_options.xr_openxr:
- bpy.utils.unregister_class(main.VIEW3D_PT_vr_info)
+ bpy.utils.unregister_class(gui.VIEW3D_PT_vr_info)
return
- 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_actions_enable_cosmos
- del bpy.types.Scene.vr_actions_enable_huawei
- del bpy.types.Scene.vr_actions_enable_reverb_g2
- del bpy.types.Scene.vr_mocap_objects
- 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(defaults.vr_init_default_actionconfig)
- bpy.app.handlers.load_post.remove(main.vr_activate_user_actionconfig)
- bpy.app.handlers.xr_session_start_pre.remove(main.vr_create_actions)
+ defaults.unregister()
+ action_map.unregister()
+ gui.unregister()
+ operators.unregister()
+ properties.unregister()
diff --git a/viewport_vr_preview/action_map.py b/viewport_vr_preview/action_map.py
new file mode 100644
index 00000000..1bc35569
--- /dev/null
+++ b/viewport_vr_preview/action_map.py
@@ -0,0 +1,206 @@
+# ##### 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>
+
+if "bpy" in locals():
+ import importlib
+ importlib.reload(defaults)
+else:
+ from . import action_map_io, defaults
+
+import bpy
+from bpy.app.handlers import persistent
+from bpy_extras.io_utils import ExportHelper, ImportHelper
+import importlib.util
+import os.path
+
+
+def vr_actionconfig_active_get(context):
+ if not context.window_manager.xr_session_settings.actionconfigs:
+ return None
+ return context.window_manager.xr_session_settings.actionconfigs.active
+
+
+def vr_actionmap_selected_get(ac):
+ actionmaps = ac.actionmaps
+ return (
+ None if (len(actionmaps) <
+ 1) else actionmaps[ac.selected_actionmap]
+ )
+
+
+def vr_actionmap_active_get(ac):
+ actionmaps = ac.actionmaps
+ return (
+ None if (len(actionmaps) <
+ 1) else actionmaps[ac.active_actionmap]
+ )
+
+
+def vr_actionmap_item_selected_get(am):
+ actionmap_items = am.actionmap_items
+ return (
+ None if (len(actionmap_items) <
+ 1) else actionmap_items[am.selected_item]
+ )
+
+
+def vr_actionmap_binding_selected_get(ami):
+ actionmap_bindings = ami.bindings
+ return (
+ None if (len(actionmap_bindings) <
+ 1) else actionmap_bindings[ami.selected_binding]
+ )
+
+
+ at persistent
+def vr_activate_user_actionconfig(context: bpy.context):
+ # Set user config as active.
+ actionconfigs = bpy.context.window_manager.xr_session_settings.actionconfigs
+ if actionconfigs:
+ actionconfigs.active = actionconfigs.user
+
+
+ at persistent
+def vr_create_actions(context: bpy.context):
+ # Create all vr action sets and actions.
+ context = bpy.context
+ ac = vr_actionconfig_active_get(context)
+ if not ac:
+ return
+
+ session_state = context.window_manager.xr_session_state
+ if not session_state:
+ return
+
+ scene = context.scene
+
+ for am in ac.actionmaps:
+ if len(am.actionmap_items) < 1:
+ continue
+
+ ok = session_state.action_set_create(context, am)
+ if not ok:
+ return
+
+ controller_grip_name = ""
+ controller_aim_name = ""
+
+ for ami in am.actionmap_items:
+ if len(ami.bindings) < 1:
+ continue
+
+ ok = session_state.action_create(context, am, ami)
+ if not ok:
+ return
+
+ if ami.type == 'POSE':
+ if ami.pose_is_controller_grip:
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list