-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path__init__.py
325 lines (261 loc) · 11.2 KB
/
__init__.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import bpy
from bpy.types import Operator
bl_info = {
"name": "Render Markers",
"author": "Edward S. White",
"description": "Renders only frames with timeline markers",
"blender": (2, 80, 0),
"version": (1, 3, 0),
"location": "Render Menu > Render Markers",
"category": "Render"
}
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 RM_OT_rendermarkers(Operator):
"""Render images only at timeline marker positions"""
bl_idname = "render.rendermarkers"
bl_label = "Render Markers"
bl_description = "Render images only at timeline marker positions"
_timer = None
scene = None
markers = None
prevpath = None
renderpath = None
prevframe = None
timeframe = None
stop = None
rendering = None
def rmpre(self, dummy, thrd=None):
self.rendering = True
def rmpost(self, context, thrd=None):
self.markers.pop(0)
if len(self.markers):
self.timeframe = self.markers[0].frame
else:
self.stop = True
bpy.context.scene.frame_current = self.timeframe
self.rendering = False
def rmcancel(self, dummy, thrd=None):
self.scene.frame_current = self.prevframe
self.scene.render.filepath = self.prevpath
print("Cancelled")
self.stop = True
def execute(self, context):
bpy.app.handlers.render_pre.append(self.rmpre)
bpy.app.handlers.render_post.append(self.rmpost)
bpy.app.handlers.render_cancel.append(self.rmcancel)
scene = bpy.context.scene
self.scene = scene
# Save current scene settings
self.renderpath = scene.render.filepath
self.prevpath = scene.render.filepath
self.prevframe = scene.frame_current
scene.frame_current
# Get list of all markers in the scene
mlist = scene.timeline_markers
# sort markers by time
self.markers = sorted(mlist, key=lambda mlist: mlist.frame)
self.timeframe = self.markers[0].frame
wm = bpy.context.window_manager
self._timer = wm.event_timer_add(0.1, window=bpy.context.window)
wm.modal_handler_add(self)
return {'RUNNING_MODAL'}
def modal(self, context, event):
if event.type in {'ESC'}:
self.rmcancel(context)
return {'CANCELLED'}
if event.type == 'TIMER':
if True in (not self.markers, self.stop is True):
bpy.app.handlers.render_pre.remove(self.rmpre)
bpy.app.handlers.render_post.remove(self.rmpost)
bpy.app.handlers.render_cancel.remove(self.rmcancel)
bpy.context.window_manager.event_timer_remove(self._timer)
bpy.context.scene.frame_current = self.prevframe
bpy.context.scene.render.filepath = self.prevpath
ShowMessageBox("Finished Rendering",
"Render Images at Markers",
'INFO')
return {"FINISHED"}
elif not self.rendering:
scene = bpy.context.scene
# render images holding for each marker
scene.render.filepath = self.renderpath + "_" + \
str(self.timeframe).zfill(4)
bpy.ops.render.render(animation=False,
write_still=True
)
return {'PASS_THROUGH'}
def draw(self, context):
layout = self.layout
row = layout.row()
row.label(text="Output file location")
row = layout.row()
row.label(text="Press Esc if location is not correct.")
file_path = bpy.context.scene.render.filepath
box = layout.box()
row = box.row()
row.alignment = 'LEFT'
row.label(text=file_path)
def invoke(self, context, event):
scene = bpy.context.scene
animation_formats = ['FFMPEG', 'AVI_JPEG', 'AVI_RAW', 'FRAMESERVER']
if scene.render.image_settings.file_format in animation_formats:
print("Movie file formats are not supported in Render Markers.")
ShowMessageBox("Movie file formats are not supported.",
"Render Images at Markers",
'ERROR')
return {'FINISHED'}
# Get list of all markers in the scene
mlist = scene.timeline_markers
if not mlist:
print("No markers in the current scene.")
ShowMessageBox("No markers in the current scene.",
"Viewport Render Images at Markers",
'ERROR')
return {'FINISHED'}
return context.window_manager.invoke_props_dialog(self)
class RM_OT_renderanimmarkers(Operator):
"""Render the same frame until a new marker is reached"""
bl_idname = "render.renderanimmarkers"
bl_label = "Render Markers"
bl_description = "Render the same frame until a new marker is reached"
_timer = None
scene = None
markers = None
renderpath = None
prevpath = None
prevframe = None
timeframe = None
totalframe = None
stop = None
rendering = None
def rampre(self, dummy, thrd=None):
self.rendering = True
def rampost(self, context, thrd=None):
self.timeframe += 1
for m in self.markers: # check if new marker has been reached
if self.timeframe == m.frame:
bpy.context.scene.frame_current = self.timeframe
if self.timeframe > bpy.context.scene.frame_end:
self.stop = True
self.scene.render.filepath = self.prevpath
self.rendering = False
def ramcancel(self, dummy, thrd=None):
self.scene.frame_current = self.prevframe
self.scene.render.filepath = self.prevpath
print("Cancelled")
self.stop = True
def execute(self, context):
bpy.app.handlers.render_pre.append(self.rampre)
bpy.app.handlers.render_post.append(self.rampost)
bpy.app.handlers.render_cancel.append(self.ramcancel)
scene = bpy.context.scene
# Get list of all markers in the scene
mlist = scene.timeline_markers
self.markers = sorted(mlist, key=lambda mlist: mlist.frame)
self.renderpath = scene.render.filepath
self.prevpath = scene.render.filepath
self.prevframe = scene.frame_current
self.timeframe = scene.frame_start
self.totalframe = scene.frame_end - scene.frame_start
scene.frame_current = self.timeframe
wm = bpy.context.window_manager
self._timer = wm.event_timer_add(0.1, window=bpy.context.window)
wm.modal_handler_add(self)
return {"RUNNING_MODAL"}
def modal(self, context, event):
if event.type in {'ESC'}:
self.ramcancel(context)
return {'CANCELLED'}
if event.type == 'TIMER':
if True in (not self.markers, self.stop is True):
bpy.app.handlers.render_pre.remove(self.rampre)
bpy.app.handlers.render_post.remove(self.rampost)
bpy.app.handlers.render_cancel.remove(self.ramcancel)
bpy.context.window_manager.event_timer_remove(self._timer)
bpy.context.scene.frame_current = self.prevframe
bpy.context.scene.render.filepath = self.prevpath
ShowMessageBox("Finished Rendering",
"Render Holding on Markers",
'INFO')
return {"FINISHED"}
elif not self.rendering:
scene = bpy.context.scene
# render images holding for each marker
scene.render.filepath = self.renderpath + "_" + \
str(self.timeframe).zfill(4)
bpy.ops.render.render(animation=False,
write_still=True
)
return {'PASS_THROUGH'}
def draw(self, context):
layout = self.layout
row = layout.row()
row.label(text="Output File Location")
row = layout.row()
row.label(text="Press Esc if location is not correct.")
file_path = bpy.context.scene.render.filepath
box = layout.box()
row = box.row()
row.alignment = 'LEFT'
row.label(text=file_path)
def invoke(self, context, event):
scene = bpy.context.scene
self.scene = scene
# Check for not a movie format
animation_formats = ['FFMPEG', 'AVI_JPEG', 'AVI_RAW']
if scene.render.image_settings.file_format in animation_formats:
print("Movie file formats are not supported in Render Markers.")
ShowMessageBox("Movie file formats are not supported.",
"Render Holding on Markers",
'ERROR')
return {'FINISHED'}
# Get list of all markers in the scene
mlist = scene.timeline_markers
if not mlist:
print("No markers in the current scene.")
ShowMessageBox("No markers in the current scene.",
"Viewport Render Images at Markers",
'ERROR')
return {'FINISHED'}
return context.window_manager.invoke_props_dialog(self)
classes = (
RM_OT_rendermarkers,
RM_OT_renderanimmarkers,
)
def menu_func_render(self, context):
self.layout.operator(RM_OT_rendermarkers.bl_idname,
text="Render Images at Markers",
icon='RENDER_STILL'
)
def menu_func_animrender(self, context):
self.layout.operator(RM_OT_renderanimmarkers.bl_idname,
text="Render Holding on Markers",
icon='RENDER_ANIMATION'
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.TOPBAR_MT_render.append(menu_func_render)
bpy.types.TOPBAR_MT_render.append(menu_func_animrender)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
bpy.types.TOPBAR_MT_render.remove(menu_func_render)
bpy.types.TOPBAR_MT_render.remove(menu_func_animrender)
if __name__ == "__main__":
register()