-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcam_switcher.py
127 lines (96 loc) · 3.81 KB
/
cam_switcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import bpy
bl_info = {
"name": "Camera Switcher",
"description": "Switch Cameras and create Bound Timeline "
"markers naturally.",
"author": "Daniel Fairhead",
"version": (1, 1),
"blender": (2, 65, 0),
"location": "3D View > Tools",
"category": "3D View",
"wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/3D_interaction/Camera_Switcher"
}
# Helper internal functions:
def marker_now(context):
''' Drop a marker in the timeline at the current frame and return it,
or return the current marker if there is already one there '''
markers = context.scene.timeline_markers
now = context.scene.frame_current
for m in markers:
if m.frame == now:
return m
return markers.new(name='new', frame=now)
class CutToCamera(bpy.types.Operator):
bl_idname = "view3d.cut_to_camera"
bl_label = "Cuts to the selected camera, and adds a marker linking to it."
def execute(self, context):
marker = marker_now(context)
cam = context.active_object
marker.camera = cam
marker.name = cam.name
return {'FINISHED'}
class CameraSwitcherPanel(bpy.types.Panel):
bl_label = "Camera Switcher"
bl_idname = "CAM_SWITCHER_BOX"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOL_PROPS'
bl_context = "objectmode"
bpy.types.Scene.camera_switcher_split = \
bpy.props.BoolProperty(name="Group By Prefix", default=True)
def draw(self, context):
layout = self.layout
scene = context.scene
cams = sorted((c for c in scene.objects
if c.type == 'CAMERA' and c.data.camswitcher_show),
key=lambda c: c.data.camswitcher_sort_prefix + c.name)
current_group = ""
for cam in cams:
if scene.camera_switcher_split:
new_group = cam.data.camswitcher_sort_prefix.split("_")[0]
if current_group != new_group:
current_group = new_group
row = layout.row()
row.label(current_group, icon="CAMERA_DATA")
row = layout.row(align=True)
row.label(text=cam.name)
row.context_pointer_set("active_object", cam)
row.operator('view3d.object_as_camera', text="Preview")
row.operator('view3d.cut_to_camera', text='Take')
row = layout.row()
row.prop(scene, "camera_switcher_split")
class CameraSwitcherCamProps(bpy.types.Panel):
""" A panel in the Properties > Camera Data
with sort prefix and 'hide' options. """
bl_label = "Camera Switcher Options"
bl_idname = "CAM_SWITCH_CAMERA_options"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "data"
@classmethod
def poll(self, context):
return True if context.camera else False
def draw(self, context):
layout = self.layout
obj = context.object
layout.prop(obj.data, "camswitcher_sort_prefix")
layout.prop(obj.data, "camswitcher_show")
def register():
bpy.utils.register_class(CutToCamera)
bpy.utils.register_class(CameraSwitcherPanel)
bpy.utils.register_class(CameraSwitcherCamProps)
bpy.types.Camera.camswitcher_show = bpy.props.BoolProperty(
name="Show in Switcher",
description="Show this camera in the Camera Switcher",
default=True
)
bpy.types.Camera.camswitcher_sort_prefix = bpy.props.StringProperty(
name="Sort Prefix",
description="Prefix for sorting camera names in switcher",
default=""
)
def unregister():
bpy.utils.unregister_class(CameraSwitcherPanel)
bpy.utils.unregister_class(CutToCamera)
bpy.utils.unregister_class(CameraSwitcherCamProps)
if __name__ == "__main__":
register()