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 for child
in obj
.children
:
11 if child
.type == 'CAMERA':
16 elif (obj
.type == 'CAMERA'
17 and obj
.parent
is not None
18 and "rig_id" in obj
.parent
19 and obj
.parent
["rig_id"].lower() in {"dolly_rig",
20 "crane_rig", "2d_rig"}):
21 return obj
.parent
, obj
25 class CameraRigMixin():
27 def poll(cls
, context
):
28 if context
.active_object
is not None:
29 return get_rig_and_cam(context
.active_object
) != (None, None)
34 class ADD_CAMERA_RIGS_OT_set_scene_camera(Operator
):
35 bl_idname
= "add_camera_rigs.set_scene_camera"
36 bl_label
= "Make Camera Active"
37 bl_description
= "Makes the camera parented to this rig the active scene camera"
40 def poll(cls
, context
):
41 if context
.active_object
is not None:
42 rig
, cam
= get_rig_and_cam(context
.active_object
)
44 return cam
is not context
.scene
.camera
48 def execute(self
, context
):
49 rig
, cam
= get_rig_and_cam(context
.active_object
)
50 scene_cam
= context
.scene
.camera
52 context
.scene
.camera
= cam
56 class ADD_CAMERA_RIGS_OT_add_marker_bind(Operator
, CameraRigMixin
):
57 bl_idname
= "add_camera_rigs.add_marker_bind"
58 bl_label
= "Add Marker and Bind Camera"
59 bl_description
= "Add marker to current frame then bind rig camera to it (for camera switching)"
61 def execute(self
, context
):
62 rig
, cam
= get_rig_and_cam(context
.active_object
)
64 marker
= context
.scene
.timeline_markers
.new(
65 "cam_" + str(context
.scene
.frame_current
),
66 frame
=context
.scene
.frame_current
73 class ADD_CAMERA_RIGS_OT_add_dof_object(Operator
, CameraRigMixin
):
74 bl_idname
= "add_camera_rigs.add_dof_object"
75 bl_label
= "Add DOF Object"
76 bl_description
= "Create Empty and add as DOF Object"
78 def execute(self
, context
):
79 rig
, cam
= get_rig_and_cam(context
.active_object
)
80 bone
= rig
.data
.bones
['Aim_shape_rotation-MCH']
83 empty_obj
= bpy
.data
.objects
.new("EmptyDOF", None)
84 context
.scene
.collection
.objects
.link(empty_obj
)
86 # Parent to Aim Child bone
87 empty_obj
.parent
= rig
88 empty_obj
.parent_type
= "BONE"
89 empty_obj
.parent_bone
= "Aim_shape_rotation-MCH"
92 empty_obj
.location
= bone
.head
94 # Make this new empty the dof_object
95 cam
.data
.dof
.use_dof
= True
96 cam
.data
.dof
.focus_object
= empty_obj
102 ADD_CAMERA_RIGS_OT_set_scene_camera
,
103 ADD_CAMERA_RIGS_OT_add_marker_bind
,
104 ADD_CAMERA_RIGS_OT_add_dof_object
,
109 from bpy
.utils
import register_class
115 from bpy
.utils
import unregister_class
117 unregister_class(cls
)