1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
6 from bpy
.types
import Operator
9 def get_rig_and_cam(obj
):
10 if (obj
.type == 'ARMATURE'
12 and obj
["rig_id"].lower() in {"dolly_rig",
13 "crane_rig", "2d_rig"}):
15 for child
in obj
.children
:
16 if child
.type == 'CAMERA':
21 elif (obj
.type == 'CAMERA'
22 and obj
.parent
is not None
23 and "rig_id" in obj
.parent
24 and obj
.parent
["rig_id"].lower() in {"dolly_rig",
25 "crane_rig", "2d_rig"}):
26 return obj
.parent
, obj
30 class CameraRigMixin():
32 def poll(cls
, context
):
33 if context
.active_object
is not None:
34 return get_rig_and_cam(context
.active_object
) != (None, None)
39 class ADD_CAMERA_RIGS_OT_set_scene_camera(Operator
):
40 bl_idname
= "add_camera_rigs.set_scene_camera"
41 bl_label
= "Make Camera Active"
42 bl_description
= "Makes the camera parented to this rig the active scene camera"
45 def poll(cls
, context
):
46 if context
.active_object
is not None:
47 rig
, cam
= get_rig_and_cam(context
.active_object
)
49 return cam
is not context
.scene
.camera
53 def execute(self
, context
):
54 rig
, cam
= get_rig_and_cam(context
.active_object
)
55 scene_cam
= context
.scene
.camera
57 context
.scene
.camera
= cam
61 class ADD_CAMERA_RIGS_OT_add_marker_bind(Operator
, CameraRigMixin
):
62 bl_idname
= "add_camera_rigs.add_marker_bind"
63 bl_label
= "Add Marker and Bind Camera"
64 bl_description
= "Add marker to current frame then bind rig camera to it (for camera switching)"
66 def execute(self
, context
):
67 rig
, cam
= get_rig_and_cam(context
.active_object
)
69 marker
= context
.scene
.timeline_markers
.new(
70 "cam_" + str(context
.scene
.frame_current
),
71 frame
=context
.scene
.frame_current
78 class ADD_CAMERA_RIGS_OT_set_dof_bone(Operator
, CameraRigMixin
):
79 bl_idname
= "add_camera_rigs.set_dof_bone"
80 bl_label
= "Set DOF Bone"
81 bl_description
= "Set the Aim bone as a DOF target"
83 def execute(self
, context
):
84 rig
, cam
= get_rig_and_cam(context
.active_object
)
86 cam
.data
.dof
.focus_object
= rig
87 cam
.data
.dof
.focus_subtarget
= (
88 'Center-MCH' if rig
["rig_id"].lower() == '2d_rig'
89 else 'Aim_shape_rotation-MCH')
95 ADD_CAMERA_RIGS_OT_set_scene_camera
,
96 ADD_CAMERA_RIGS_OT_add_marker_bind
,
97 ADD_CAMERA_RIGS_OT_set_dof_bone
,
102 from bpy
.utils
import register_class
108 from bpy
.utils
import unregister_class
110 unregister_class(cls
)