-
Notifications
You must be signed in to change notification settings - Fork 40
/
RenderBurst27.py
168 lines (129 loc) · 5.3 KB
/
RenderBurst27.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
bl_info = {
"name": "Render Burst",
"category": "Render",
"author" : "Aidy Burrows, Gleb Alexandrov, Roman Alexandrov, CreativeShrimp.com <[email protected]>",
"version" : (1, 0, 27),
"description" :
"Render all cameras, one by one, and store results.",
}
import os
import bpy
class RenderBurst(bpy.types.Operator):
"""Render all cameras"""
bl_idname = "render.renderburst"
bl_label = "Render Burst"
_timer = None
shots = None
stop = None
rendering = None
path = "//"
disablerbbutton = False
def pre(self, dummy):
self.rendering = True
def post(self, dummy):
self.shots.pop(0)
self.rendering = False
def cancelled(self, dummy):
self.stop = True
def execute(self, context):
self.stop = False
self.rendering = False
scene = context.scene
wm = context.window_manager
if wm.rb_filter.rb_filter_enum == 'selected':
self.shots = [ o.name+'' for o in bpy.context.selected_objects if o.type=='CAMERA' and o.is_visible(scene) == True]
else:
self.shots = [ o.name+'' for o in bpy.data.objects if o.type=='CAMERA' and o.is_visible(scene) == True ]
if len(self.shots) < 0:
self.report({"WARNING"}, 'No cameras defined')
return {"FINISHED"}
bpy.app.handlers.render_pre.append(self.pre)
bpy.app.handlers.render_post.append(self.post)
bpy.app.handlers.render_cancel.append(self.cancelled)
self._timer = context.window_manager.event_timer_add(0.5, context.window)
context.window_manager.modal_handler_add(self)
return {"RUNNING_MODAL"}
def modal(self, context, event):
if event.type == 'TIMER':
if True in (not self.shots, self.stop is True):
bpy.app.handlers.render_pre.remove(self.pre)
bpy.app.handlers.render_post.remove(self.post)
bpy.app.handlers.render_cancel.remove(self.cancelled)
context.window_manager.event_timer_remove(self._timer)
return {"FINISHED"}
elif self.rendering is False:
sc = bpy.context.scene
sc.camera = bpy.data.objects[self.shots[0]]
lpath = self.path
fpath = sc.render.filepath
is_relative_path = True
if fpath != "":
if fpath[0]+fpath[1] == "//":
is_relative_path = True
fpath = bpy.path.abspath(fpath)
else:
is_relative_path = False
lpath = os.path.dirname(fpath)
if is_relative_path:
lpath = bpy.path.relpath(lpath)
lpath = lpath.rstrip("/")
lpath = lpath.rstrip("\\")
if lpath=="":
lpath="/"
lpath+="/"
sc.render.filepath = lpath + self.shots[0] + sc.render.file_extension
bpy.ops.render.render("INVOKE_DEFAULT", write_still=True)
return {"PASS_THROUGH"}
# ui part
class RbFilterSettings(bpy.types.PropertyGroup):
rb_filter_enum = bpy.props.EnumProperty(
name = "Filter",
description = "Choose your destiny",
items = [
("all", "All Cameras", "Render all cameras"),
("selected", "Selected Only", "Render selected only"),
],
default = 'all'
)
class RenderBurstCamerasPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
bl_label = "Render Burst"
bl_idname = "SCENE_PT_layout"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "render"
def draw(self, context):
wm = context.window_manager
box = self.layout.box()
row = box.row()
row.prop(wm.rb_filter, "rb_filter_enum", expand=True)
row = self.layout.row()
row.operator("rb.renderbutton", text='Render!')
row = self.layout.row()
class OBJECT_OT_RBButton(bpy.types.Operator):
bl_idname = "rb.renderbutton"
bl_label = "Render"
#@classmethod
#def poll(cls, context):
# return True
def execute(self, context):
if bpy.context.scene.render.filepath is None or len(bpy.context.scene.render.filepath)<1:
self.report({"ERROR"}, 'Output path not defined. Please, define the output path on the render settings panel')
return {"FINISHED"}
animation_formats = [ 'FFMPEG', 'AVI_JPEG', 'AVI_RAW', 'FRAMESERVER' ]
if bpy.context.scene.render.image_settings.file_format in animation_formats:
self.report({"ERROR"}, 'Animation formats are not supported. Yet :)')
return {"FINISHED"}
bpy.ops.render.renderburst()
return{'FINISHED'}
def menu_func(self, context):
self.layout.operator(RenderBurst.bl_idname)
def register():
bpy.utils.register_module(__name__)
bpy.types.WindowManager.rb_filter = bpy.props.PointerProperty(type=RbFilterSettings)
bpy.types.INFO_MT_render.append(menu_func)
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_render.remove(menu_func)
if __name__ == "__main__":
register()