diff options
author | Peter Kim <pk15950@gmail.com> | 2022-03-25 07:22:50 +0300 |
---|---|---|
committer | Peter Kim <pk15950@gmail.com> | 2022-03-25 07:22:50 +0300 |
commit | 5aa25f6a3f0a41aef27d6e477ad8b2e2771b000f (patch) | |
tree | 74b20a4c6d5d76a816af40561d6d0670c01e297f /viewport_vr_preview | |
parent | d6f0fb5b17f00c1c498f9afa8775bf8502b97778 (diff) |
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).
Diffstat (limited to 'viewport_vr_preview')
-rw-r--r-- | viewport_vr_preview/gui.py | 3 | ||||
-rw-r--r-- | viewport_vr_preview/operators.py | 34 |
2 files changed, 36 insertions, 1 deletions
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, |