[Bf-extensions-cvs] [3340c3d0] xr-actions-D9124: Add patch changes.

Peter Kim noreply at git.blender.org
Tue Oct 13 14:46:55 CEST 2020


Commit: 3340c3d0cd73846fc4f348fc377ba4e11a69eb91
Author: Peter Kim
Date:   Tue Oct 6 18:56:13 2020 +0900
Branches: xr-actions-D9124
https://developer.blender.org/rBA3340c3d0cd73846fc4f348fc377ba4e11a69eb91

Add patch changes.

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

M	viewport_vr_preview.py

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

diff --git a/viewport_vr_preview.py b/viewport_vr_preview.py
index 62933c09..f1c5d908 100644
--- a/viewport_vr_preview.py
+++ b/viewport_vr_preview.py
@@ -34,6 +34,7 @@ from bpy.props import (
     BoolProperty,
 )
 from bpy.app.handlers import persistent
+from mathutils import Quaternion
 
 bl_info = {
     "name": "VR Scene Inspection",
@@ -283,6 +284,265 @@ class VIEW3D_PT_vr_landmarks(Panel):
                             "base_pose_angle", text="Angle")
 
 
+ at persistent
+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
+
+    if wm.xr_session_state and len(actions) > 0:
+        wm.xr_session_state.create_action_set(context, action_set.name)
+
+        type = 'BUTTON'
+        op_flag = 'PRESS'
+        interaction_path0 = ""
+        interaction_path1 = ""
+
+        for action in actions:
+            if action.type == 'BUTTON':
+                type = 'BUTTON'		
+                if action.op_flag == 'PRESS':	
+                    op_flag = 'PRESS'
+                elif action.op_flag == 'RELEASE':	
+                    op_flag = 'RELEASE'
+                elif action.op_flag == 'MODAL':
+                    op_flag = 'MODAL'
+                else:
+                    continue
+            elif action.type == 'POSE':
+                type = 'POSE'					
+            elif action.type == 'HAPTIC':
+                type = 'HAPTIC'
+            else:
+                continue
+
+            wm.xr_session_state.create_action(context, action_set.name, action.name, type, action.user_path0, action.user_path1, action.op, op_flag)         
+
+            if action.type == 'POSE':
+                wm.xr_session_state.create_action_space(context, action_set.name, action.name, action.user_path0, action.user_path1, \
+                            action.pose_location, action.pose_rotation)
+                if action.pose_is_controller:
+                    wm.xr_session_state.set_controller_pose_action(context, action_set.name, action.name)
+
+            interaction_path0 = action.user_path0 + action.component_path0
+            interaction_path1 = action.user_path1 + action.component_path1
+
+            wm.xr_session_state.create_action_binding(context, action_set.name, action_set.profile, action.name, interaction_path0, interaction_path1, False)  
+
+        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",
+        default="action_set",
+    )
+    profile: bpy.props.StringProperty(
+        name="OpenXR interaction profile path",
+    )
+
+
+class VRAction(PropertyGroup):
+    name: bpy.props.StringProperty(
+        name="VR action",
+        default="action",
+    )
+    type: bpy.props.EnumProperty(
+        name="VR action type",
+        items=[
+            ('BUTTON', "Button", "Button input"),
+            ('POSE', "Pose", "Pose input"),
+            ('HAPTIC', "Haptic", "Haptic output"),
+        ],
+        default='BUTTON',
+    )
+    user_path0: bpy.props.StringProperty(
+        name="OpenXR user path",
+    )
+    component_path0: bpy.props.StringProperty(
+        name="OpenXR component path",
+    )
+    user_path1: bpy.props.StringProperty(
+        name="OpenXR user path",
+    )
+    component_path1: bpy.props.StringProperty(
+        name="OpenXR component path",
+    )
+    op: bpy.props.StringProperty(
+        name="Python operator",
+    )
+    op_flag: bpy.props.EnumProperty(
+        name="Operator flag",
+        items=[
+            ('PRESS', "Press",
+             "Execute operator on press "
+             "(non-modal operators only)"),
+            ('RELEASE', "Release",
+             "Execute operator on release "
+             "(non-modal operators only)"),
+            ('MODAL', "Modal",
+             "Use modal execution "
+             "(modal operators only)"),
+        ],
+        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",
+    )	
+    pose_location: bpy.props.FloatVectorProperty(
+        name="Pose location offset",
+        subtype='TRANSLATION',
+    )
+    pose_rotation: bpy.props.FloatVectorProperty(
+        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",
+    )
+    haptic_frequency: bpy.props.FloatProperty(
+        name="Haptic frequency",
+    )
+    haptic_amplitude: bpy.props.FloatProperty(
+        name="Haptic amplitude",
+    )
+
+    @staticmethod
+    def get_selected_action(context):
+        scene = context.scene
+        actions = scene.vr_actions
+
+        return (
+            None if (len(actions) <
+                     1) else actions[scene.vr_actions_selected]
+        )
+
+
+class VIEW3D_UL_vr_actions(UIList):
+    def draw_item(self, context, layout, _data, item, icon, _active_data,
+                  _active_propname, index):
+        action = item
+
+        layout.emboss = 'NONE'
+
+        layout.prop(action, "name", text="")
+
+
+class VIEW3D_PT_vr_actions(Panel):
+    bl_space_type = 'VIEW_3D'
+    bl_region_type = 'UI'
+    bl_category = "VR"
+    bl_label = "Actions"
+    bl_options = {'DEFAULT_CLOSED'}
+
+    def draw(self, context):
+        layout = self.layout
+        scene = context.scene
+        action_set = scene.vr_action_set[0]
+        action_selected = VRAction.get_selected_action(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")
+
+        row = layout.row()
+
+        row.template_list("VIEW3D_UL_vr_actions", "", scene, "vr_actions",
+                          scene, "vr_actions_selected", rows=2)
+
+        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,
+                            "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")
+                layout.prop(action_selected,
+                            "state0", text="State 0")
+                layout.prop(action_selected,
+                            "state1", text="State 1")
+            elif action_selected.type == 'POSE':
+                layout.prop(action_selected,
+                            "pose_is_controller", text="Use for Controller Poses")
+                layout.prop(action_selected,
+                            "pose_location", text="Location Offset")
+                layout.prop(action_selected,
+                            "pose_rotation", text="Rotation Offset")
+                layout.operator("view3d.vr_pose_action_state_get", icon='PLAY', text="Get current states")
+                layout.prop(action_selected,
+                            "pose_state_location0", text="Location State 0")
+                layout.prop(action_selected,
+                            "pose_state_rotation0", text="Rotation State 0")     
+                layout.prop(action_selected,
+                            "pose_state_location1", text="Location State 1")
+                layout.prop(action_selected,
+                            "pose_state_rotation1", text="Rotation State 1")   
+            elif action_selected.type == 'HAPTIC':
+                layout.prop(action_selected,
+                            "haptic_duration", text="Duration")
+                layout.prop(action_selected,
+                            "haptic_frequency", text="Frequency")
+                layout.prop(action_selected,
+                            "haptic_amplitude", text="Amplitude")
+                layout.operator("view3d.vr_haptic_action_apply", icon='PLAY', text="Apply haptic action")
+
+
 class VIEW3D_PT_vr_session_view(Panel):
     bl_space_type = 'VIEW_3D'
     bl_region_type = 'UI'
@@ -299,6 +559,7 @@ class VIEW3D_PT_vr_session_view(Panel):
         col = layout.column(align=True, heading="Show")
         col.prop(session_settings, "show_floor", text="Floor")
         co

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list