1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
20 from bpy
.types
import Operator
23 def get_rig_and_cam(obj
):
24 if obj
.type == 'ARMATURE':
26 for child
in obj
.children
:
27 if child
.type == 'CAMERA':
32 elif (obj
.type == 'CAMERA'
33 and obj
.parent
is not None
34 and "rig_id" in obj
.parent
35 and obj
.parent
["rig_id"].lower() in {"dolly_rig",
36 "crane_rig", "2d_rig"}):
37 return obj
.parent
, obj
41 class CameraRigMixin():
43 def poll(cls
, context
):
44 if context
.active_object
is not None:
45 return get_rig_and_cam(context
.active_object
) != (None, None)
50 class ADD_CAMERA_RIGS_OT_set_scene_camera(Operator
):
51 bl_idname
= "add_camera_rigs.set_scene_camera"
52 bl_label
= "Make Camera Active"
53 bl_description
= "Makes the camera parented to this rig the active scene camera"
56 def poll(cls
, context
):
57 if context
.active_object
is not None:
58 rig
, cam
= get_rig_and_cam(context
.active_object
)
60 return cam
is not context
.scene
.camera
64 def execute(self
, context
):
65 rig
, cam
= get_rig_and_cam(context
.active_object
)
66 scene_cam
= context
.scene
.camera
68 context
.scene
.camera
= cam
72 class ADD_CAMERA_RIGS_OT_add_marker_bind(Operator
, CameraRigMixin
):
73 bl_idname
= "add_camera_rigs.add_marker_bind"
74 bl_label
= "Add Marker and Bind Camera"
75 bl_description
= "Add marker to current frame then bind rig camera to it (for camera switching)"
77 def execute(self
, context
):
78 rig
, cam
= get_rig_and_cam(context
.active_object
)
80 marker
= context
.scene
.timeline_markers
.new(
81 "cam_" + str(context
.scene
.frame_current
),
82 frame
=context
.scene
.frame_current
89 class ADD_CAMERA_RIGS_OT_add_dof_object(Operator
, CameraRigMixin
):
90 bl_idname
= "add_camera_rigs.add_dof_object"
91 bl_label
= "Add DOF Object"
92 bl_description
= "Create Empty and add as DOF Object"
94 def execute(self
, context
):
95 rig
, cam
= get_rig_and_cam(context
.active_object
)
96 bone
= rig
.data
.bones
['Aim_shape_rotation-MCH']
99 empty_obj
= bpy
.data
.objects
.new("EmptyDOF", None)
100 context
.scene
.collection
.objects
.link(empty_obj
)
102 # Parent to Aim Child bone
103 empty_obj
.parent
= rig
104 empty_obj
.parent_type
= "BONE"
105 empty_obj
.parent_bone
= "Aim_shape_rotation-MCH"
108 empty_obj
.location
= bone
.head
110 # Make this new empty the dof_object
111 cam
.data
.dof
.use_dof
= True
112 cam
.data
.dof
.focus_object
= empty_obj
118 ADD_CAMERA_RIGS_OT_set_scene_camera
,
119 ADD_CAMERA_RIGS_OT_add_marker_bind
,
120 ADD_CAMERA_RIGS_OT_add_dof_object
,
125 from bpy
.utils
import register_class
131 from bpy
.utils
import unregister_class
133 unregister_class(cls
)