-
Notifications
You must be signed in to change notification settings - Fork 5
/
PolyCamsRender_3.py
119 lines (90 loc) · 3.58 KB
/
PolyCamsRender_3.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
import bpy
from bpy_extras.io_utils import ExportHelper
from bpy.props import StringProperty, BoolProperty, EnumProperty
from bpy.types import Operator
from copy import copy
bl_info = {
"name": "PolyCams Render",
"author": "Alexander Nedovizin",
"version": (0, 3, 0),
"blender": (2, 6, 7),
"category": "Render"
}
class ExportSomeData(Operator, ExportHelper):
"""This appears in the tooltip of the operator and in the generated docs"""
bl_idname = "export_test.some_data" # important since its how bpy.ops.import_test.some_data is constructed
bl_label = "Export Some Data"
# ExportHelper mixin class uses this
filename_ext = ""
def execute(self, context):
return render_me(self.filepath)
def render_me(filepath):
sceneName = bpy.context.scene.name
scene = bpy.data.scenes[sceneName]
marks = scene.timeline_markers
lm=[[m.frame, i] for i,m in enumerate(marks)]
lm.sort()
diap = []
print('lm',lm)
for idx, l_mark in enumerate(lm[:-1]):
mark = marks[l_mark[1]]
if mark.name == "end":
continue
start_fr = mark.frame
if (len(marks)-1)>idx:
end_fr = marks[lm[idx+1][1]].frame
else:
end_fr = copy(scene.frame_end)
name_fr = mark.name
diap.append((start_fr, end_fr, name_fr))
if len(diap)==0:
diap.append((scene.frame_start, scene.frame_end, ''))
for d in diap:
scene.frame_start = d[0]
scene.frame_end = d[1]
for cam in bpy.data.objects:
if ( cam.type =='CAMERA' and not cam.hide_render):
bpy.data.scenes[sceneName].camera = cam
if d[2]!='':
bpy.data.scenes[sceneName].render.filepath = filepath+'\\'+d[2]+'\\'+cam.name+'\\'+d[2]
else:
bpy.data.scenes[sceneName].render.filepath = filepath+'\\'+cam.name+'\\'+cam.name
bpy.ops.render.render(animation=True)
print('Done!')
#print(bpy.data.scenes[sceneName].render.filepath)
return {'FINISHED'}
class RenderMe(bpy.types.Operator):
"""Cams render"""
bl_idname = "scene.render_me"
bl_label = "Render Me"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
bpy.ops.export_test.some_data('INVOKE_DEFAULT')
return {'FINISHED'}
def menu_func(self, context):
self.layout.operator(RenderMe.bl_idname)
def menu_func_export(self, context):
self.layout.operator(ExportSomeData.bl_idname, text="Cams Render!")
addon_keymaps = []
def register():
bpy.utils.register_class(RenderMe)
bpy.types.VIEW3D_MT_object.append(menu_func)
bpy.utils.register_class(ExportSomeData)
bpy.types.INFO_MT_file_export.append(menu_func_export)
# handle the keymap
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='Object Mode', space_type='EMPTY')
kmi = km.keymap_items.new(RenderMe.bl_idname, 'F12', 'PRESS', ctrl=True, shift=False)
addon_keymaps.append((km, kmi))
def unregister():
bpy.utils.unregister_class(RenderMe)
bpy.types.VIEW3D_MT_object.remove(menu_func)
bpy.utils.unregister_class(ExportSomeData)
bpy.types.INFO_MT_file_export.remove(menu_func_export)
# handle the keymap
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()
if __name__ == "__main__":
register()
bpy.ops.scene.render_me()