-
Notifications
You must be signed in to change notification settings - Fork 40
/
RenderBurst41.py
224 lines (163 loc) · 6.96 KB
/
RenderBurst41.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
bl_info = {
"name": "Render Burst",
"category": "Render",
"blender": (4, 1, 1),
"author" : "Aidy Burrows, Gleb Alexandrov, Roman Alexandrov, CreativeShrimp.com <support@creativeshrimp.com>",
"version" : (1, 2, 1),
"description" :
"Render all cameras, one by one, and store results.",
}
import bpy
import os
# BugFix: If cameras were bound to markers all cameras wouldn't get rendered.
markersDict = {}
# Make a note of markers in scene and any bound cameras, remove the bindings
def unbindMarkers():
scene = bpy.context.scene
for marker in scene.timeline_markers:
if marker.camera:
markersDict[marker] = marker.camera
marker.camera = None
# Put the bindings of cameras to markers back
def bindMarkers():
scene = bpy.context.scene
for marker in scene.timeline_markers:
if marker in markersDict:
marker.camera = markersDict[marker]
# Regular code:
def ShowMessageBox(message = "", title = "Message Box", icon = 'INFO'):
def draw(self, context):
self.layout.label(text=message)
bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)
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, thrd = None):
self.rendering = True
def post(self, dummy, thrd = None):
self.shots.pop(0)
self.rendering = False
def cancelled(self, dummy, thrd = None):
self.stop = True
def execute(self, context):
# Unbind the markers otherwise all cameras will be the same
unbindMarkers()
# Regular code
self.stop = False
self.rendering = False
scene = bpy.context.scene
wm = bpy.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.visible_get() == True]
else:
self.shots = [ o.name+'' for o in bpy.context.visible_objects if o.type=='CAMERA' and o.visible_get() == 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 = bpy.context.window_manager.event_timer_add(0.5, window=bpy.context.window)
bpy.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)
bpy.context.window_manager.event_timer_remove(self._timer)
# Part of the markers bugfix - putting markers if any back again.
if len(self.shots) == 0:
bindMarkers()
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
row = self.layout.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():
from bpy.utils import register_class
register_class(RenderBurst)
register_class(RbFilterSettings)
register_class(RenderBurstCamerasPanel)
register_class(OBJECT_OT_RBButton)
bpy.types.WindowManager.rb_filter = bpy.props.PointerProperty(name="Render Burst Filter", type=RbFilterSettings)
bpy.types.TOPBAR_MT_render.append(menu_func)
def unregister():
from bpy.utils import unregister_class
unregister_class(RenderBurst)
bpy.types.TOPBAR_MT_render.remove(menu_func)
unregister_class(RbFilterSettings)
unregister_class(RenderBurstCamerasPanel)
unregister_class(OBJECT_OT_RBButton)
if __name__ == "__main__":
register()