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).
This commit is contained in:
Peter Kim 2022-03-25 13:22:50 +09:00
parent d6f0fb5b17
commit 5aa25f6a3f
2 changed files with 36 additions and 1 deletions

View File

@ -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'

View File

@ -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,