1 # SPDX-License-Identifier: GPL-2.0-or-later
4 from bpy
.types
import Operator
7 def get_rig_and_cam(obj
):
8 if (obj
.type == 'ARMATURE'
10 and obj
["rig_id"].lower() in {"dolly_rig",
11 "crane_rig", "2d_rig"}):
13 for child
in obj
.children
:
14 if child
.type == 'CAMERA':
19 elif (obj
.type == 'CAMERA'
20 and obj
.parent
is not None
21 and "rig_id" in obj
.parent
22 and obj
.parent
["rig_id"].lower() in {"dolly_rig",
23 "crane_rig", "2d_rig"}):
24 return obj
.parent
, obj
28 class CameraRigMixin():
30 def poll(cls
, context
):
31 if context
.active_object
is not None:
32 return get_rig_and_cam(context
.active_object
) != (None, None)
37 class ADD_CAMERA_RIGS_OT_set_scene_camera(Operator
):
38 bl_idname
= "add_camera_rigs.set_scene_camera"
39 bl_label
= "Make Camera Active"
40 bl_description
= "Makes the camera parented to this rig the active scene camera"
43 def poll(cls
, context
):
44 if context
.active_object
is not None:
45 rig
, cam
= get_rig_and_cam(context
.active_object
)
47 return cam
is not context
.scene
.camera
51 def execute(self
, context
):
52 rig
, cam
= get_rig_and_cam(context
.active_object
)
53 scene_cam
= context
.scene
.camera
55 context
.scene
.camera
= cam
59 class ADD_CAMERA_RIGS_OT_add_marker_bind(Operator
, CameraRigMixin
):
60 bl_idname
= "add_camera_rigs.add_marker_bind"
61 bl_label
= "Add Marker and Bind Camera"
62 bl_description
= "Add marker to current frame then bind rig camera to it (for camera switching)"
64 def execute(self
, context
):
65 rig
, cam
= get_rig_and_cam(context
.active_object
)
67 marker
= context
.scene
.timeline_markers
.new(
68 "cam_" + str(context
.scene
.frame_current
),
69 frame
=context
.scene
.frame_current
76 class ADD_CAMERA_RIGS_OT_set_dof_bone(Operator
, CameraRigMixin
):
77 bl_idname
= "add_camera_rigs.set_dof_bone"
78 bl_label
= "Set DOF Bone"
79 bl_description
= "Set the Aim bone as a DOF target"
81 def execute(self
, context
):
82 rig
, cam
= get_rig_and_cam(context
.active_object
)
84 cam
.data
.dof
.focus_object
= rig
85 cam
.data
.dof
.focus_subtarget
= 'Aim_shape_rotation-MCH'
91 ADD_CAMERA_RIGS_OT_set_scene_camera
,
92 ADD_CAMERA_RIGS_OT_add_marker_bind
,
93 ADD_CAMERA_RIGS_OT_set_dof_bone
,
98 from bpy
.utils
import register_class
104 from bpy
.utils
import unregister_class
106 unregister_class(cls
)