Fix [#34005] blender will close immediately in debug mode on deleting objects
[blender.git] / release / scripts / startup / bl_ui / properties_render.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2
3 #
4 #  This program is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU General Public License
6 #  as published by the Free Software Foundation; either version 2
7 #  of the License, or (at your option) any later version.
8 #
9 #  This program is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #  GNU General Public License for more details.
13 #
14 #  You should have received a copy of the GNU General Public License
15 #  along with this program; if not, write to the Free Software Foundation,
16 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18 # ##### END GPL LICENSE BLOCK #####
19
20 # <pep8 compliant>
21 import bpy
22 from bpy.types import Menu, Panel, UIList
23
24
25 class RENDER_MT_presets(Menu):
26     bl_label = "Render Presets"
27     preset_subdir = "render"
28     preset_operator = "script.execute_preset"
29     draw = Menu.draw_preset
30
31
32 class RENDER_MT_ffmpeg_presets(Menu):
33     bl_label = "FFMPEG Presets"
34     preset_subdir = "ffmpeg"
35     preset_operator = "script.python_file_run"
36     draw = Menu.draw_preset
37
38
39 class RENDER_MT_framerate_presets(Menu):
40     bl_label = "Frame Rate Presets"
41     preset_subdir = "framerate"
42     preset_operator = "script.execute_preset"
43     draw = Menu.draw_preset
44
45
46 class RENDER_UL_renderlayers(UIList):
47     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
48         # assert(isinstance(item, bpy.types.SceneRenderLayer)
49         layer = item
50         if self.layout_type in {'DEFAULT', 'COMPACT'}:
51             layout.label(layer.name, icon_value=icon)
52             layout.prop(layer, "use", text="", index=index)
53         elif self.layout_type in {'GRID'}:
54             layout.alignment = 'CENTER'
55             layout.label("", icon_value=icon)
56
57 #       else if (RNA_struct_is_a(itemptr->type, &RNA_SceneRenderLayer)) {
58 #               uiItemL(sub, name, icon);
59 #               uiBlockSetEmboss(block, UI_EMBOSS);
60 #               uiDefButR(block, OPTION, 0, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, itemptr, "use", 0, 0, 0, 0, 0,  NULL);
61 #       }
62
63
64 class RenderButtonsPanel():
65     bl_space_type = 'PROPERTIES'
66     bl_region_type = 'WINDOW'
67     bl_context = "render"
68     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
69
70     @classmethod
71     def poll(cls, context):
72         rd = context.scene.render
73         return context.scene and (rd.engine in cls.COMPAT_ENGINES)
74
75
76 class RENDER_PT_render(RenderButtonsPanel, Panel):
77     bl_label = "Render"
78     COMPAT_ENGINES = {'BLENDER_RENDER'}
79
80     def draw(self, context):
81         layout = self.layout
82
83         rd = context.scene.render
84
85         row = layout.row(align=True)
86         row.operator("render.render", text="Render", icon='RENDER_STILL')
87         row.operator("render.render", text="Animation", icon='RENDER_ANIMATION').animation = True
88         row.operator("render.play_rendered_anim", text="Play", icon='PLAY')
89
90         layout.prop(rd, "display_mode", text="Display")
91
92
93 class RENDER_PT_layers(RenderButtonsPanel, Panel):
94     bl_label = "Layers"
95     bl_options = {'DEFAULT_CLOSED'}
96     COMPAT_ENGINES = {'BLENDER_RENDER'}
97
98     def draw(self, context):
99         layout = self.layout
100
101         scene = context.scene
102         rd = scene.render
103
104         row = layout.row()
105         row.template_list("RENDER_UL_renderlayers", "", rd, "layers", rd.layers, "active_index", rows=2)
106
107         col = row.column(align=True)
108         col.operator("scene.render_layer_add", icon='ZOOMIN', text="")
109         col.operator("scene.render_layer_remove", icon='ZOOMOUT', text="")
110
111         row = layout.row()
112         rl = rd.layers.active
113         if rl:
114             row.prop(rl, "name")
115         row.prop(rd, "use_single_layer", text="", icon_only=True)
116
117         split = layout.split()
118
119         col = split.column()
120         col.prop(scene, "layers", text="Scene")
121         col.label(text="")
122         col.prop(rl, "light_override", text="Light")
123         col.prop(rl, "material_override", text="Material")
124
125         col = split.column()
126         col.prop(rl, "layers", text="Layer")
127         col.label(text="Mask Layers:")
128         col.prop(rl, "layers_zmask", text="")
129
130         layout.separator()
131         layout.label(text="Include:")
132
133         split = layout.split()
134
135         col = split.column()
136         col.prop(rl, "use_zmask")
137         row = col.row()
138         row.prop(rl, "invert_zmask", text="Negate")
139         row.active = rl.use_zmask
140         col.prop(rl, "use_all_z")
141
142         col = split.column()
143         col.prop(rl, "use_solid")
144         col.prop(rl, "use_halo")
145         col.prop(rl, "use_ztransp")
146
147         col = split.column()
148         col.prop(rl, "use_sky")
149         col.prop(rl, "use_edge_enhance")
150         col.prop(rl, "use_strand")
151
152         layout.separator()
153
154         split = layout.split()
155
156         col = split.column()
157         col.label(text="Passes:")
158         col.prop(rl, "use_pass_combined")
159         col.prop(rl, "use_pass_z")
160         col.prop(rl, "use_pass_vector")
161         col.prop(rl, "use_pass_normal")
162         col.prop(rl, "use_pass_uv")
163         col.prop(rl, "use_pass_mist")
164         col.prop(rl, "use_pass_object_index")
165         col.prop(rl, "use_pass_material_index")
166         col.prop(rl, "use_pass_color")
167
168         col = split.column()
169         col.label()
170         col.prop(rl, "use_pass_diffuse")
171         row = col.row()
172         row.prop(rl, "use_pass_specular")
173         row.prop(rl, "exclude_specular", text="")
174         row = col.row()
175         row.prop(rl, "use_pass_shadow")
176         row.prop(rl, "exclude_shadow", text="")
177         row = col.row()
178         row.prop(rl, "use_pass_emit")
179         row.prop(rl, "exclude_emit", text="")
180         row = col.row()
181         row.prop(rl, "use_pass_ambient_occlusion")
182         row.prop(rl, "exclude_ambient_occlusion", text="")
183         row = col.row()
184         row.prop(rl, "use_pass_environment")
185         row.prop(rl, "exclude_environment", text="")
186         row = col.row()
187         row.prop(rl, "use_pass_indirect")
188         row.prop(rl, "exclude_indirect", text="")
189         row = col.row()
190         row.prop(rl, "use_pass_reflection")
191         row.prop(rl, "exclude_reflection", text="")
192         row = col.row()
193         row.prop(rl, "use_pass_refraction")
194         row.prop(rl, "exclude_refraction", text="")
195
196
197 class RENDER_PT_dimensions(RenderButtonsPanel, Panel):
198     bl_label = "Dimensions"
199     COMPAT_ENGINES = {'BLENDER_RENDER'}
200
201     def draw(self, context):
202         layout = self.layout
203
204         scene = context.scene
205         rd = scene.render
206
207         row = layout.row(align=True)
208         row.menu("RENDER_MT_presets", text=bpy.types.RENDER_MT_presets.bl_label)
209         row.operator("render.preset_add", text="", icon='ZOOMIN')
210         row.operator("render.preset_add", text="", icon='ZOOMOUT').remove_active = True
211
212         split = layout.split()
213
214         col = split.column()
215         sub = col.column(align=True)
216         sub.label(text="Resolution:")
217         sub.prop(rd, "resolution_x", text="X")
218         sub.prop(rd, "resolution_y", text="Y")
219         sub.prop(rd, "resolution_percentage", text="")
220
221         sub.label(text="Aspect Ratio:")
222         sub.prop(rd, "pixel_aspect_x", text="X")
223         sub.prop(rd, "pixel_aspect_y", text="Y")
224
225         row = col.row()
226         row.prop(rd, "use_border", text="Border")
227         sub = row.row()
228         sub.active = rd.use_border
229         sub.prop(rd, "use_crop_to_border", text="Crop")
230
231         col = split.column()
232         sub = col.column(align=True)
233         sub.label(text="Frame Range:")
234         sub.prop(scene, "frame_start")
235         sub.prop(scene, "frame_end")
236         sub.prop(scene, "frame_step")
237
238         sub.label(text="Frame Rate:")
239         if rd.fps_base == 1:
240             fps_rate = round(rd.fps / rd.fps_base)
241         else:
242             fps_rate = round(rd.fps / rd.fps_base, 2)
243
244         # TODO: Change the following to iterate over existing presets
245         custom_framerate = (fps_rate not in {23.98, 24, 25, 29.97, 30, 50, 59.94, 60})
246
247         if custom_framerate is True:
248             fps_label_text = "Custom (" + str(fps_rate) + " fps)"
249         else:
250             fps_label_text = str(fps_rate) + " fps"
251
252         sub.menu("RENDER_MT_framerate_presets", text=fps_label_text)
253
254         if custom_framerate or (bpy.types.RENDER_MT_framerate_presets.bl_label == "Custom"):
255             sub.prop(rd, "fps")
256             sub.prop(rd, "fps_base", text="/")
257         subrow = sub.row(align=True)
258         subrow.label(text="Time Remapping:")
259         subrow = sub.row(align=True)
260         subrow.prop(rd, "frame_map_old", text="Old")
261         subrow.prop(rd, "frame_map_new", text="New")
262
263
264 class RENDER_PT_antialiasing(RenderButtonsPanel, Panel):
265     bl_label = "Anti-Aliasing"
266     COMPAT_ENGINES = {'BLENDER_RENDER'}
267
268     def draw_header(self, context):
269         rd = context.scene.render
270
271         self.layout.prop(rd, "use_antialiasing", text="")
272
273     def draw(self, context):
274         layout = self.layout
275
276         rd = context.scene.render
277         layout.active = rd.use_antialiasing
278
279         split = layout.split()
280
281         col = split.column()
282         col.row().prop(rd, "antialiasing_samples", expand=True)
283         sub = col.row()
284         sub.enabled = not rd.use_border
285         sub.prop(rd, "use_full_sample")
286
287         col = split.column()
288         col.prop(rd, "pixel_filter_type", text="")
289         col.prop(rd, "filter_size", text="Size")
290
291
292 class RENDER_PT_motion_blur(RenderButtonsPanel, Panel):
293     bl_label = "Sampled Motion Blur"
294     bl_options = {'DEFAULT_CLOSED'}
295     COMPAT_ENGINES = {'BLENDER_RENDER'}
296
297     @classmethod
298     def poll(cls, context):
299         rd = context.scene.render
300         return not rd.use_full_sample and (rd.engine in cls.COMPAT_ENGINES)
301
302     def draw_header(self, context):
303         rd = context.scene.render
304
305         self.layout.prop(rd, "use_motion_blur", text="")
306
307     def draw(self, context):
308         layout = self.layout
309
310         rd = context.scene.render
311         layout.active = rd.use_motion_blur
312
313         row = layout.row()
314         row.prop(rd, "motion_blur_samples")
315         row.prop(rd, "motion_blur_shutter")
316
317
318 class RENDER_PT_shading(RenderButtonsPanel, Panel):
319     bl_label = "Shading"
320     bl_options = {'DEFAULT_CLOSED'}
321     COMPAT_ENGINES = {'BLENDER_RENDER'}
322
323     def draw(self, context):
324         layout = self.layout
325
326         rd = context.scene.render
327
328         split = layout.split()
329
330         col = split.column()
331         col.prop(rd, "use_textures", text="Textures")
332         col.prop(rd, "use_shadows", text="Shadows")
333         col.prop(rd, "use_sss", text="Subsurface Scattering")
334         col.prop(rd, "use_envmaps", text="Environment Map")
335
336         col = split.column()
337         col.prop(rd, "use_raytrace", text="Ray Tracing")
338         col.prop(rd, "alpha_mode", text="Alpha")
339
340
341 class RENDER_PT_performance(RenderButtonsPanel, Panel):
342     bl_label = "Performance"
343     bl_options = {'DEFAULT_CLOSED'}
344     COMPAT_ENGINES = {'BLENDER_RENDER'}
345
346     def draw(self, context):
347         layout = self.layout
348
349         rd = context.scene.render
350
351         split = layout.split()
352
353         col = split.column()
354         sub = col.column(align=True)
355         sub.label(text="Threads:")
356         sub.row().prop(rd, "threads_mode", expand=True)
357         subsub = sub.column()
358         subsub.enabled = rd.threads_mode == 'FIXED'
359         subsub.prop(rd, "threads")
360
361         sub = col.column(align=True)
362         sub.label(text="Tile Size:")
363         sub.prop(rd, "tile_x", text="X")
364         sub.prop(rd, "tile_y", text="Y")
365
366         col = split.column()
367         col.label(text="Memory:")
368         sub = col.column()
369         sub.enabled = not (rd.use_border or rd.use_full_sample)
370         sub.prop(rd, "use_save_buffers")
371         sub = col.column()
372         sub.active = rd.use_compositing
373         sub.prop(rd, "use_free_image_textures")
374         sub.prop(rd, "use_free_unused_nodes")
375         sub = col.column()
376         sub.active = rd.use_raytrace
377         sub.label(text="Acceleration structure:")
378         sub.prop(rd, "raytrace_method", text="")
379         if rd.raytrace_method == 'OCTREE':
380             sub.prop(rd, "octree_resolution", text="Resolution")
381         else:
382             sub.prop(rd, "use_instances", text="Instances")
383         sub.prop(rd, "use_local_coords", text="Local Coordinates")
384
385
386 class RENDER_PT_post_processing(RenderButtonsPanel, Panel):
387     bl_label = "Post Processing"
388     bl_options = {'DEFAULT_CLOSED'}
389     COMPAT_ENGINES = {'BLENDER_RENDER'}
390
391     def draw(self, context):
392         layout = self.layout
393
394         rd = context.scene.render
395
396         split = layout.split()
397
398         col = split.column()
399         col.prop(rd, "use_compositing")
400         col.prop(rd, "use_sequencer")
401
402         split.prop(rd, "dither_intensity", text="Dither", slider=True)
403
404         layout.separator()
405
406         split = layout.split()
407
408         col = split.column()
409         col.prop(rd, "use_fields", text="Fields")
410         sub = col.column()
411         sub.active = rd.use_fields
412         sub.row().prop(rd, "field_order", expand=True)
413         sub.prop(rd, "use_fields_still", text="Still")
414
415         col = split.column()
416         col.prop(rd, "use_edge_enhance")
417         sub = col.column()
418         sub.active = rd.use_edge_enhance
419         sub.prop(rd, "edge_threshold", text="Threshold", slider=True)
420         sub.prop(rd, "edge_color", text="")
421
422
423 class RENDER_PT_stamp(RenderButtonsPanel, Panel):
424     bl_label = "Stamp"
425     bl_options = {'DEFAULT_CLOSED'}
426     COMPAT_ENGINES = {'BLENDER_RENDER'}
427
428     def draw_header(self, context):
429         rd = context.scene.render
430
431         self.layout.prop(rd, "use_stamp", text="")
432
433     def draw(self, context):
434         layout = self.layout
435
436         rd = context.scene.render
437
438         layout.active = rd.use_stamp
439
440         layout.prop(rd, "stamp_font_size", text="Font Size")
441
442         row = layout.row()
443         row.column().prop(rd, "stamp_foreground", slider=True)
444         row.column().prop(rd, "stamp_background", slider=True)
445
446         split = layout.split()
447
448         col = split.column()
449         col.prop(rd, "use_stamp_time", text="Time")
450         col.prop(rd, "use_stamp_date", text="Date")
451         col.prop(rd, "use_stamp_render_time", text="RenderTime")
452         col.prop(rd, "use_stamp_frame", text="Frame")
453         col.prop(rd, "use_stamp_scene", text="Scene")
454
455         col = split.column()
456         col.prop(rd, "use_stamp_camera", text="Camera")
457         col.prop(rd, "use_stamp_lens", text="Lens")
458         col.prop(rd, "use_stamp_filename", text="Filename")
459         col.prop(rd, "use_stamp_marker", text="Marker")
460         col.prop(rd, "use_stamp_sequencer_strip", text="Seq. Strip")
461
462         row = layout.split(percentage=0.2)
463         row.prop(rd, "use_stamp_note", text="Note")
464         sub = row.row()
465         sub.active = rd.use_stamp_note
466         sub.prop(rd, "stamp_note_text", text="")
467
468
469 class RENDER_PT_output(RenderButtonsPanel, Panel):
470     bl_label = "Output"
471     COMPAT_ENGINES = {'BLENDER_RENDER'}
472
473     def draw(self, context):
474         layout = self.layout
475
476         rd = context.scene.render
477         image_settings = rd.image_settings
478         file_format = image_settings.file_format
479
480         layout.prop(rd, "filepath", text="")
481
482         flow = layout.column_flow()
483         flow.prop(rd, "use_overwrite")
484         flow.prop(rd, "use_placeholder")
485         flow.prop(rd, "use_file_extension")
486
487         layout.template_image_settings(image_settings, color_management=False)
488
489         if file_format == 'QUICKTIME_CARBON':
490             layout.operator("scene.render_data_set_quicktime_codec")
491
492         elif file_format == 'QUICKTIME_QTKIT':
493             quicktime = rd.quicktime
494
495             split = layout.split()
496             col = split.column()
497             col.prop(quicktime, "codec_type", text="Video Codec")
498             col.prop(quicktime, "codec_spatial_quality", text="Quality")
499
500             # Audio
501             col.prop(quicktime, "audiocodec_type", text="Audio Codec")
502             if quicktime.audiocodec_type != 'No audio':
503                 split = layout.split()
504                 if quicktime.audiocodec_type == 'LPCM':
505                     split.prop(quicktime, "audio_bitdepth", text="")
506
507                 split.prop(quicktime, "audio_samplerate", text="")
508
509                 split = layout.split()
510                 col = split.column()
511                 if quicktime.audiocodec_type == 'AAC':
512                     col.prop(quicktime, "audio_bitrate")
513
514                 subsplit = split.split()
515                 col = subsplit.column()
516
517                 if quicktime.audiocodec_type == 'AAC':
518                     col.prop(quicktime, "audio_codec_isvbr")
519
520                 col = subsplit.column()
521                 col.prop(quicktime, "audio_resampling_hq")
522
523
524 class RENDER_PT_encoding(RenderButtonsPanel, Panel):
525     bl_label = "Encoding"
526     bl_options = {'DEFAULT_CLOSED'}
527     COMPAT_ENGINES = {'BLENDER_RENDER'}
528
529     @classmethod
530     def poll(cls, context):
531         rd = context.scene.render
532         return rd.image_settings.file_format in {'FFMPEG', 'XVID', 'H264', 'THEORA'}
533
534     def draw(self, context):
535         layout = self.layout
536
537         rd = context.scene.render
538         ffmpeg = rd.ffmpeg
539
540         layout.menu("RENDER_MT_ffmpeg_presets", text="Presets")
541
542         split = layout.split()
543         split.prop(rd.ffmpeg, "format")
544         if ffmpeg.format in {'AVI', 'QUICKTIME', 'MKV', 'OGG'}:
545             split.prop(ffmpeg, "codec")
546         elif rd.ffmpeg.format == 'H264':
547             split.prop(ffmpeg, "use_lossless_output")
548         else:
549             split.label()
550
551         row = layout.row()
552         row.prop(ffmpeg, "video_bitrate")
553         row.prop(ffmpeg, "gopsize")
554
555         split = layout.split()
556
557         col = split.column()
558         col.label(text="Rate:")
559         col.prop(ffmpeg, "minrate", text="Minimum")
560         col.prop(ffmpeg, "maxrate", text="Maximum")
561         col.prop(ffmpeg, "buffersize", text="Buffer")
562
563         col = split.column()
564         col.prop(ffmpeg, "use_autosplit")
565         col.label(text="Mux:")
566         col.prop(ffmpeg, "muxrate", text="Rate")
567         col.prop(ffmpeg, "packetsize", text="Packet Size")
568
569         layout.separator()
570
571         # Audio:
572         if ffmpeg.format != 'MP3':
573             layout.prop(ffmpeg, "audio_codec", text="Audio Codec")
574
575         row = layout.row()
576         row.prop(ffmpeg, "audio_bitrate")
577         row.prop(ffmpeg, "audio_volume", slider=True)
578
579
580 class RENDER_PT_bake(RenderButtonsPanel, Panel):
581     bl_label = "Bake"
582     bl_options = {'DEFAULT_CLOSED'}
583     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
584
585     def draw(self, context):
586         layout = self.layout
587
588         rd = context.scene.render
589
590         layout.operator("object.bake_image", icon='RENDER_STILL')
591
592         layout.prop(rd, "bake_type")
593
594         multires_bake = False
595         if rd.bake_type in ['NORMALS', 'DISPLACEMENT', 'AO']:
596             layout.prop(rd, "use_bake_multires")
597             multires_bake = rd.use_bake_multires
598
599         if not multires_bake:
600             if rd.bake_type == 'NORMALS':
601                 layout.prop(rd, "bake_normal_space")
602             elif rd.bake_type in {'DISPLACEMENT', 'AO'}:
603                 layout.prop(rd, "use_bake_normalize")
604
605             # col.prop(rd, "bake_aa_mode")
606             # col.prop(rd, "use_bake_antialiasing")
607
608             layout.separator()
609
610             split = layout.split()
611
612             col = split.column()
613             col.prop(rd, "use_bake_to_vertex_color")
614             sub = col.column()
615             sub.active = not rd.use_bake_to_vertex_color
616             sub.prop(rd, "use_bake_clear")
617             sub.prop(rd, "bake_margin")
618             sub.prop(rd, "bake_quad_split", text="Split")
619
620             col = split.column()
621             col.prop(rd, "use_bake_selected_to_active")
622             sub = col.column()
623             sub.active = rd.use_bake_selected_to_active
624             sub.prop(rd, "bake_distance")
625             sub.prop(rd, "bake_bias")
626         else:
627             split = layout.split()
628
629             col = split.column()
630             col.prop(rd, "use_bake_clear")
631             col.prop(rd, "bake_margin")
632
633             if rd.bake_type == 'DISPLACEMENT':
634                 col = split.column()
635                 col.prop(rd, "use_bake_lores_mesh")
636             if rd.bake_type == 'AO':
637                 col = split.column()
638                 col.prop(rd, "bake_bias")
639                 col.prop(rd, "bake_samples")
640
641
642 if __name__ == "__main__":  # only for live edit.
643     bpy.utils.register_module(__name__)