[Bf-extensions-cvs] [5aa25f6a] master: VR: Add "Camera Landmark from Session" operator

Peter Kim noreply at git.blender.org
Fri Mar 25 05:23:06 CET 2022


Commit: 5aa25f6a3f0a41aef27d6e477ad8b2e2771b000f
Author: Peter Kim
Date:   Fri Mar 25 13:22:50 2022 +0900
Branches: master
https://developer.blender.org/rBA5aa25f6a3f0a41aef27d6e477ad8b2e2771b000f

VR: Add "Camera Landmark from Session" operator

Creates a new camera and "Custom Object"-type landmark from the VR
headset pose.

In contrast to the existing "Landmark from Session" operator that only
saves the headset rotation around the global z-axis, this preserves the
exact rotation of the headset by assigning it to the newly-created
camera (although the landmark itself still only inherits the z-rotation
component).

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

M	viewport_vr_preview/gui.py
M	viewport_vr_preview/operators.py

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

diff --git a/viewport_vr_preview/gui.py b/viewport_vr_preview/gui.py
index 163cbd48..376e9de8 100644
--- a/viewport_vr_preview/gui.py
+++ b/viewport_vr_preview/gui.py
@@ -88,6 +88,7 @@ class VIEW3D_MT_vr_landmark_menu(Menu):
     def draw(self, _context):
         layout = self.layout
 
+        layout.operator("view3d.vr_camera_landmark_from_session")
         layout.operator("view3d.vr_landmark_from_camera")
         layout.operator("view3d.update_vr_landmark")
         layout.separator()
@@ -156,7 +157,7 @@ class VIEW3D_PT_vr_landmarks(Panel):
                             "base_scale", text="Scale")
 
 
-### View.
+### Actions.
 class VIEW3D_PT_vr_actionmaps(Panel):
     bl_space_type = 'VIEW_3D'
     bl_region_type = 'UI'
diff --git a/viewport_vr_preview/operators.py b/viewport_vr_preview/operators.py
index dc2dd4b9..67638ea4 100644
--- a/viewport_vr_preview/operators.py
+++ b/viewport_vr_preview/operators.py
@@ -97,6 +97,39 @@ class VIEW3D_OT_vr_landmark_from_session(Operator):
         return {'FINISHED'}
 
 
+class VIEW3D_OT_vr_camera_landmark_from_session(Operator):
+    bl_idname = "view3d.vr_camera_landmark_from_session"
+    bl_label = "Add Camera and VR Landmark from Session"
+    bl_description = "Create a new Camera and VR Landmark from the viewer pose of the running VR session and select it"
+    bl_options = {'UNDO', 'REGISTER'}
+
+    @classmethod
+    def poll(cls, context):
+        return bpy.types.XrSessionState.is_running(context)
+
+    def execute(self, context):
+        scene = context.scene
+        landmarks = scene.vr_landmarks
+        wm = context.window_manager
+
+        lm = landmarks.add()
+        lm.type = 'OBJECT'
+        scene.vr_landmarks_selected = len(landmarks) - 1
+
+        loc = wm.xr_session_state.viewer_pose_location
+        rot = wm.xr_session_state.viewer_pose_rotation.to_euler()
+
+        cam = bpy.data.cameras.new("Camera_" + lm.name)
+        new_cam = bpy.data.objects.new("Camera_" + lm.name, cam)
+        scene.collection.objects.link(new_cam)
+        new_cam.location = loc
+        new_cam.rotation_euler = rot
+
+        lm.base_pose_object = new_cam
+
+        return {'FINISHED'}
+
+
 class VIEW3D_OT_update_vr_landmark(Operator):
     bl_idname = "view3d.update_vr_landmark"
     bl_label = "Update Custom VR Landmark"
@@ -480,6 +513,7 @@ classes = (
     VIEW3D_OT_vr_landmark_remove,
     VIEW3D_OT_vr_landmark_activate,
     VIEW3D_OT_vr_landmark_from_session,
+    VIEW3D_OT_vr_camera_landmark_from_session,
     VIEW3D_OT_add_camera_from_vr_landmark,
     VIEW3D_OT_camera_to_vr_landmark,
     VIEW3D_OT_vr_landmark_from_camera,



More information about the Bf-extensions-cvs mailing list