[Bf-extensions-cvs] [6d464d15] xr-actions-D9124: VR Scene Inspection: Add add-on preferences

Peter Kim noreply at git.blender.org
Sat Oct 24 18:37:43 CEST 2020


Commit: 6d464d159ff562169c3de161b9ce40fc56875d46
Author: Peter Kim
Date:   Sun Oct 25 01:36:42 2020 +0900
Branches: xr-actions-D9124
https://developer.blender.org/rBA6d464d159ff562169c3de161b9ce40fc56875d46

VR Scene Inspection: Add add-on preferences

VR action sets can now be configured in the add-on preferences. These
action sets can be added and saved to a scene, enabling easy transfer
of actions across blend files.

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

M	viewport_vr_preview.py

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

diff --git a/viewport_vr_preview.py b/viewport_vr_preview.py
index 8b7698de..4a44a947 100644
--- a/viewport_vr_preview.py
+++ b/viewport_vr_preview.py
@@ -153,7 +153,7 @@ def xr_landmark_active_update(self, context):
         wm.xr_session_state.reset_to_base_pose(context)
 
 
-class VIEW3D_MT_landmark_menu(Menu):
+class VIEW3D_MT_vr_landmark_menu(Menu):
     bl_label = "Landmark Controls"
 
     def draw(self, _context):
@@ -270,7 +270,7 @@ class VIEW3D_PT_vr_landmarks(Panel):
         col.operator("view3d.vr_landmark_remove", icon='REMOVE', text="")
         col.operator("view3d.vr_landmark_from_session", icon='PLUS', text="")
 
-        col.menu("VIEW3D_MT_landmark_menu", icon='DOWNARROW_HLT', text="")
+        col.menu("VIEW3D_MT_vr_landmark_menu", icon='DOWNARROW_HLT', text="")
 
         if landmark_selected:
             layout.prop(landmark_selected, "type")
@@ -289,12 +289,11 @@ def create_vr_actions(context: bpy.context):
     # Create all vr action sets and actions.
     context = bpy.context
     wm = context.window_manager
-    scene = context.scene
-    action_set = scene.vr_action_set[0]
-    actions = scene.vr_actions
+    action_set = VRActionSet.get_active_action_set(context)
 
-    if wm.xr_session_state and len(actions) > 0:
+    if wm.xr_session_state and action_set and len(action_set.actions) > 0:
         wm.xr_session_state.create_action_set(context, action_set.name)
+        actions = action_set.actions 
 
         type = 'BUTTON'
         op_flag = 'PRESS'
@@ -335,33 +334,6 @@ def create_vr_actions(context: bpy.context):
         wm.xr_session_state.set_active_action_set(context, action_set.name)
 
 
- at persistent
-def ensure_default_vr_action_set(context: bpy.context):
-    # Ensure there's a default action set.
-    action_set = bpy.context.scene.vr_action_set
-    if not action_set:
-        action_set.add()
-
-
-class VIEW3D_MT_action_menu(Menu):
-    bl_label = "Action Controls"
-
-    def draw(self, _context):
-        layout = self.layout
-
-        layout.operator("view3d.vr_action_set_clear")
-
-
-class VRActionSet(PropertyGroup):
-    name: bpy.props.StringProperty(
-        name="VR action set.\nMust not contain upper case letters or special characters other than '-', '_', or '.'",
-        default="action_set",
-    )
-    profile: bpy.props.StringProperty(
-        name="OpenXR interaction profile path",
-    )
-
-
 class VRAction(PropertyGroup):
     name: bpy.props.StringProperty(
         name="VR action.\nMust not contain upper case letters or special characters other than '-', '_', or '.'",
@@ -412,12 +384,6 @@ class VRAction(PropertyGroup):
         ],
         default='PRESS',
     )
-    state0: bpy.props.FloatProperty(
-        name="Current value",
-    )
-    state1: bpy.props.FloatProperty(
-        name="Current value",
-    )
     pose_is_controller: bpy.props.BoolProperty(
         name="Pose will be used for the VR controllers",
     )	
@@ -429,22 +395,6 @@ class VRAction(PropertyGroup):
         name="Pose rotation offset",
         subtype='EULER',
     )
-    pose_state_location0: bpy.props.FloatVectorProperty(
-        name="Current pose location",
-        subtype='TRANSLATION',
-    )
-    pose_state_rotation0: bpy.props.FloatVectorProperty(
-        name="Current pose rotation",
-        subtype='EULER',
-    )
-    pose_state_location1: bpy.props.FloatVectorProperty(
-        name="Current pose location",
-        subtype='TRANSLATION',
-    )
-    pose_state_rotation1: bpy.props.FloatVectorProperty(
-        name="Current pose rotation",
-        subtype='EULER',
-    )
     haptic_duration: bpy.props.FloatProperty(
         name="Haptic duration in seconds",
     )
@@ -455,15 +405,119 @@ class VRAction(PropertyGroup):
         name="Haptic amplitude",
     )
 
+    def copy_from(self, o):
+        self.name = o.name
+        self.type = o.type
+        self.user_path0 = o.user_path0
+        self.component_path0 = o.component_path0
+        self.user_path1 = o.user_path1
+        self.component_path1 = o.component_path1
+        self.threshold = o.threshold
+        self.op = o.op
+        self.op_flag = o.op_flag
+        self.pose_is_controller = o.pose_is_controller
+        self.pose_location = o.pose_location
+        self.pose_rotation = o.pose_rotation
+        self.haptic_duration = o.haptic_duration
+        self.haptic_frequency = o.haptic_frequency
+        self.haptic_amplitude = o.haptic_amplitude
+
+
+class VRActionSet(PropertyGroup):
+    name: bpy.props.StringProperty(
+        name="VR action set.\nMust not contain upper case letters or special characters other than '-', '_', or '.'",
+        default="action_set",
+    )
+    profile: bpy.props.StringProperty(
+        name="OpenXR interaction profile path",
+    )
+    actions: CollectionProperty(
+        name="Actions",
+        type=VRAction,
+    )
+    actions_selected: IntProperty(
+        name="Selected Action",		
+    )
+
     @staticmethod
-    def get_selected_action(context):
+    def get_active_action_set(context):
         scene = context.scene
-        actions = scene.vr_actions
+        action_sets = scene.vr_action_sets
+
+        return (
+            None if (len(action_sets) <
+                     1) else action_sets[scene.vr_action_sets_active]
+        )
+
+    @staticmethod
+    def get_selected_action_set(context):
+        scene = context.scene
+        action_sets = scene.vr_action_sets
+
+        return (
+            None if (len(action_sets) <
+                     1) else action_sets[scene.vr_action_sets_selected]
+        )
+
+    @staticmethod
+    def prefs_get_selected_action_set(context):
+        prefs = context.preferences.addons[__name__].preferences
+        action_sets = prefs.action_sets
+
+        return (
+            None if (len(action_sets) <
+                     1) else action_sets[prefs.action_sets_selected]
+        )
+
+    def get_selected_action(self):
+        actions = self.actions
 
         return (
             None if (len(actions) <
-                     1) else actions[scene.vr_actions_selected]
+                     1) else actions[self.actions_selected]
+        )
+
+    def copy_from(self, o):
+        self.name = o.name
+        self.profile = o.profile
+
+        self.actions.clear()
+        idx = 0
+        for action in o.actions:
+            self.actions.add()
+            self.actions[idx].copy_from(action)
+            idx += 1
+
+        self.actions_selected = o.actions_selected
+
+
+class VIEW3D_UL_vr_action_sets(UIList):
+    def draw_item(self, context, layout, _data, item, icon, _active_data,
+                  _active_propname, index):
+        action_set = item
+        action_set_active_idx = context.scene.vr_action_sets_active
+
+        layout.emboss = 'NONE'
+
+        layout.prop(action_set, "name", text="")
+
+        icon = (
+            'RADIOBUT_ON' if (index == action_set_active_idx) else 'RADIOBUT_OFF'
         )
+        props = layout.operator(
+            "view3d.vr_action_set_activate", text="", icon=icon)
+        props.index = index
+
+
+class VIEW3D_MT_vr_action_set_menu(Menu):
+    bl_label = "Action Set Controls"
+
+    def draw(self, _context):
+        layout = self.layout
+
+        layout.operator("view3d.vr_action_sets_load_from_prefs")
+        layout.operator("view3d.vr_action_set_save_to_prefs")
+        layout.operator("view3d.vr_action_sets_clear")
 
 
 class VIEW3D_UL_vr_actions(UIList):
@@ -476,6 +530,15 @@ class VIEW3D_UL_vr_actions(UIList):
         layout.prop(action, "name", text="")
 
 
+class VIEW3D_MT_vr_action_menu(Menu):
+    bl_label = "Action Controls"
+
+    def draw(self, _context):
+        layout = self.layout
+
+        layout.operator("view3d.vr_actions_clear")
+
+
 class VIEW3D_PT_vr_actions(Panel):
     bl_space_type = 'VIEW_3D'
     bl_region_type = 'UI'
@@ -486,69 +549,69 @@ class VIEW3D_PT_vr_actions(Panel):
     def draw(self, context):
         layout = self.layout
         scene = context.scene
-        action_set = scene.vr_action_set[0]
-        action_selected = VRAction.get_selected_action(context)
+        action_set_selected = VRActionSet.get_selected_action_set(context)
 
         layout.use_property_split = True
         layout.use_property_decorate = False  # No animation.
 
-        layout.prop(action_set, "name", text="Action Set")
-        layout.prop(action_set, "profile", text="Profile")
+        row0 = layout.row()
+        col = row0.column(align=True)
+        col.label(text="Action Sets")
 
-        row = layout.row()
+        row1 = layout.row()
+        row1.template_list("VIEW3D_UL_vr_action_sets", "", scene, "vr_action_sets",
+                          scene, "vr_action_sets_selected", rows=3)
 
-        row.template_list("VIEW3D_UL_vr_actions", "", scene, "vr_actions",
-                          scene, "vr_actions_selected", rows=2)
+        col = row1.column(align=True)
+        col.operator("view3d.vr_action_set_add", icon='ADD', text="")
+        col.operator("view3d.vr_action_set_remove", icon='REMOVE', text="")
 
-        col = row.column(align=True)
-        col.operator("view3d.vr_action_add", icon='ADD', text="")
-        col.operator("view3d.vr_action_remove", icon='REMOVE', text="")
-
-        col.menu("VIEW3D_MT_action_menu", icon='DOWNARROW_HLT', text="")
-
-        if action_selected:
-            layout.prop(action_selected, "type", text="Type")
-            layout.prop(action_selected, "user_path0", text="User Path 0")
-            layout.prop(action_selected, "component_path0", text="Component Path 0")
-            layout.prop(action_selected, "user_path1", text="User Path 1")
-            layout.prop(action_selected, "component_path1", text="Component Path 1")
-
-            if action_selected.type == 'BUTTON':
-                layout.prop(action_selected,
-                            "threshold", text="Threshold")
-                layout.prop(action_selected,
-                            "op", text="Operator")
-                layout.prop(action_selected,
-                            "op_flag", text="Operator Flag")
-                layout.operator("view3d.vr_action_state_get", icon='PLAY', text="Get current states")
-                

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list