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