code cleanup: python/pep8 and double-promotion warnings.
[blender-staging.git] / intern / cycles / blender / addon / ui.py
1 #
2 # Copyright 2011, Blender Foundation.
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
19 # <pep8 compliant>
20
21 import bpy
22
23 from bpy.types import Panel, Menu
24
25
26 class CYCLES_MT_integrator_presets(Menu):
27     bl_label = "Integrator Presets"
28     preset_subdir = "cycles/integrator"
29     preset_operator = "script.execute_preset"
30     COMPAT_ENGINES = {'CYCLES'}
31     draw = Menu.draw_preset
32
33
34 class CyclesButtonsPanel():
35     bl_space_type = "PROPERTIES"
36     bl_region_type = "WINDOW"
37     bl_context = "render"
38
39     @classmethod
40     def poll(cls, context):
41         rd = context.scene.render
42         return rd.engine == 'CYCLES'
43
44
45 class CyclesRender_PT_sampling(CyclesButtonsPanel, Panel):
46     bl_label = "Sampling"
47     bl_options = {'DEFAULT_CLOSED'}
48
49     def draw(self, context):
50         layout = self.layout
51
52         scene = context.scene
53         cscene = scene.cycles
54         device_type = context.user_preferences.system.compute_device_type
55
56         split = layout.split()
57
58         col = split.column()
59         sub = col.column()
60         sub.active = (device_type == 'NONE' or cscene.device == 'CPU')
61         sub.prop(cscene, "progressive")
62
63         sub = col.column(align=True)
64         sub.prop(cscene, "seed")
65         sub.prop(cscene, "sample_clamp")
66
67         if cscene.progressive or (device_type != 'NONE' and cscene.device == 'GPU'):
68             col = split.column()
69             col.label(text="Samples:")
70             sub = col.column(align=True)
71             sub.prop(cscene, "samples", text="Render")
72             sub.prop(cscene, "preview_samples", text="Preview")
73         else:
74             sub.label(text="AA Samples:")
75             sub.prop(cscene, "aa_samples", text="Render")
76             sub.prop(cscene, "preview_aa_samples", text="Preview")
77
78             col = split.column()
79             col.label(text="Samples:")
80             sub = col.column(align=True)
81             sub.prop(cscene, "diffuse_samples", text="Diffuse")
82             sub.prop(cscene, "glossy_samples", text="Glossy")
83             sub.prop(cscene, "transmission_samples", text="Transmission")
84             sub.prop(cscene, "ao_samples", text="AO")
85             sub.prop(cscene, "mesh_light_samples", text="Mesh Light")
86
87
88 class CyclesRender_PT_light_paths(CyclesButtonsPanel, Panel):
89     bl_label = "Light Paths"
90     bl_options = {'DEFAULT_CLOSED'}
91
92     def draw(self, context):
93         layout = self.layout
94
95         scene = context.scene
96         cscene = scene.cycles
97
98         row = layout.row(align=True)
99         row.menu("CYCLES_MT_integrator_presets", text=bpy.types.CYCLES_MT_integrator_presets.bl_label)
100         row.operator("render.cycles_integrator_preset_add", text="", icon="ZOOMIN")
101         row.operator("render.cycles_integrator_preset_add", text="", icon="ZOOMOUT").remove_active = True
102
103         split = layout.split()
104
105         col = split.column()
106
107         sub = col.column(align=True)
108         sub.label("Transparency:")
109         sub.prop(cscene, "transparent_max_bounces", text="Max")
110         sub.prop(cscene, "transparent_min_bounces", text="Min")
111         sub.prop(cscene, "use_transparent_shadows", text="Shadows")
112
113         col.separator()
114
115         col.prop(cscene, "no_caustics")
116         col.prop(cscene, "blur_glossy")
117
118         col = split.column()
119
120         sub = col.column(align=True)
121         sub.label(text="Bounces:")
122         sub.prop(cscene, "max_bounces", text="Max")
123         sub.prop(cscene, "min_bounces", text="Min")
124
125         sub = col.column(align=True)
126         sub.prop(cscene, "diffuse_bounces", text="Diffuse")
127         sub.prop(cscene, "glossy_bounces", text="Glossy")
128         sub.prop(cscene, "transmission_bounces", text="Transmission")
129
130
131 class CyclesRender_PT_motion_blur(CyclesButtonsPanel, Panel):
132     bl_label = "Motion Blur"
133     bl_options = {'DEFAULT_CLOSED'}
134
135     def draw_header(self, context):
136         rd = context.scene.render
137
138         self.layout.prop(rd, "use_motion_blur", text="")
139
140     def draw(self, context):
141         layout = self.layout
142
143         rd = context.scene.render
144         layout.active = rd.use_motion_blur
145
146         row = layout.row()
147         row.prop(rd, "motion_blur_shutter")
148
149
150 class CyclesRender_PT_film(CyclesButtonsPanel, Panel):
151     bl_label = "Film"
152
153     def draw(self, context):
154         layout = self.layout
155
156         scene = context.scene
157         cscene = scene.cycles
158
159         split = layout.split()
160
161         col = split.column()
162         col.prop(cscene, "film_exposure")
163         col.prop(cscene, "film_transparent")
164
165         col = split.column()
166         sub = col.column(align=True)
167         sub.prop(cscene, "filter_type", text="")
168         if cscene.filter_type != 'BOX':
169             sub.prop(cscene, "filter_width", text="Width")
170
171
172 class CyclesRender_PT_performance(CyclesButtonsPanel, Panel):
173     bl_label = "Performance"
174     bl_options = {'DEFAULT_CLOSED'}
175
176     def draw(self, context):
177         layout = self.layout
178
179         scene = context.scene
180         rd = scene.render
181         cscene = scene.cycles
182
183         split = layout.split()
184
185         col = split.column(align=True)
186
187         col.label(text="Threads:")
188         col.row().prop(rd, "threads_mode", expand=True)
189         sub = col.column()
190         sub.enabled = rd.threads_mode == 'FIXED'
191         sub.prop(rd, "threads")
192
193         sub = col.column(align=True)
194         sub.label(text="Tiles:")
195         sub.prop(cscene, "tile_order", text="")
196
197         sub.prop(rd, "tile_x", text="X")
198         sub.prop(rd, "tile_y", text="Y")
199
200         sub.prop(cscene, "use_progressive_refine")
201
202         subsub = sub.column()
203         subsub.enabled = not rd.use_border
204         subsub.prop(rd, "use_save_buffers")
205
206         col = split.column()
207
208         sub = col.column(align=True)
209         sub.label(text="Acceleration structure:")
210         sub.prop(cscene, "debug_bvh_type", text="")
211         sub.prop(cscene, "debug_use_spatial_splits")
212         sub.prop(cscene, "use_cache")
213
214         sub = col.column(align=True)
215         sub.label(text="Viewport:")
216         sub.prop(cscene, "preview_start_resolution")
217
218         sub = col.column(align=True)
219         sub.label(text="Final Render:")
220         sub.prop(rd, "use_persistent_data", text="Persistent Images")
221
222
223 class CyclesRender_PT_opengl(CyclesButtonsPanel, Panel):
224     bl_label = "OpenGL Render"
225     bl_options = {'DEFAULT_CLOSED'}
226
227     def draw(self, context):
228         layout = self.layout
229
230         rd = context.scene.render
231
232         split = layout.split()
233
234         col = split.column()
235         col.prop(rd, "use_antialiasing")
236         sub = col.row()
237         sub.active = rd.use_antialiasing
238         sub.prop(rd, "antialiasing_samples", expand=True)
239
240         col = split.column()
241         col.label(text="Alpha:")
242         col.prop(rd, "alpha_mode", text="")
243
244
245 class CyclesRender_PT_layers(CyclesButtonsPanel, Panel):
246     bl_label = "Layers"
247     bl_options = {'DEFAULT_CLOSED'}
248     COMPAT_ENGINES = {'BLENDER_RENDER'}
249
250     def draw(self, context):
251         layout = self.layout
252
253         scene = context.scene
254         rd = scene.render
255
256         row = layout.row()
257         row.template_list("RENDER_UL_renderlayers", "", rd, "layers", rd.layers, "active_index", rows=2)
258
259         col = row.column(align=True)
260         col.operator("scene.render_layer_add", icon='ZOOMIN', text="")
261         col.operator("scene.render_layer_remove", icon='ZOOMOUT', text="")
262
263         row = layout.row()
264         rl = rd.layers.active
265         row.prop(rl, "name")
266         row.prop(rd, "use_single_layer", text="", icon_only=True)
267
268         split = layout.split()
269
270         col = split.column()
271         col.prop(scene, "layers", text="Scene")
272         col.prop(rl, "layers_exclude", text="Exclude")
273
274         col = split.column()
275         col.prop(rl, "layers", text="Layer")
276         col.label(text="Mask Layers:")
277         col.prop(rl, "layers_zmask", text="")
278
279         split = layout.split()
280
281         col = split.column()
282         col.label(text="Material:")
283         col.prop(rl, "material_override", text="")
284
285         col = split.column()
286         col.prop(rl, "samples")
287         col.prop(rl, "use_sky", "Use Environment")
288
289         split = layout.split()
290
291         col = split.column()
292         col.label(text="Passes:")
293         col.prop(rl, "use_pass_combined")
294         col.prop(rl, "use_pass_z")
295         col.prop(rl, "use_pass_normal")
296         col.prop(rl, "use_pass_vector")
297         col.prop(rl, "use_pass_uv")
298         col.prop(rl, "use_pass_object_index")
299         col.prop(rl, "use_pass_material_index")
300         col.prop(rl, "use_pass_ambient_occlusion")
301         col.prop(rl, "use_pass_shadow")
302
303         col = split.column()
304         col.label()
305         col.label(text="Diffuse:")
306         row = col.row(align=True)
307         row.prop(rl, "use_pass_diffuse_direct", text="Direct", toggle=True)
308         row.prop(rl, "use_pass_diffuse_indirect", text="Indirect", toggle=True)
309         row.prop(rl, "use_pass_diffuse_color", text="Color", toggle=True)
310         col.label(text="Glossy:")
311         row = col.row(align=True)
312         row.prop(rl, "use_pass_glossy_direct", text="Direct", toggle=True)
313         row.prop(rl, "use_pass_glossy_indirect", text="Indirect", toggle=True)
314         row.prop(rl, "use_pass_glossy_color", text="Color", toggle=True)
315         col.label(text="Transmission:")
316         row = col.row(align=True)
317         row.prop(rl, "use_pass_transmission_direct", text="Direct", toggle=True)
318         row.prop(rl, "use_pass_transmission_indirect", text="Indirect", toggle=True)
319         row.prop(rl, "use_pass_transmission_color", text="Color", toggle=True)
320
321         col.prop(rl, "use_pass_emit", text="Emission")
322         col.prop(rl, "use_pass_environment")
323
324
325 class Cycles_PT_post_processing(CyclesButtonsPanel, Panel):
326     bl_label = "Post Processing"
327     bl_options = {'DEFAULT_CLOSED'}
328
329     def draw(self, context):
330         layout = self.layout
331
332         rd = context.scene.render
333
334         split = layout.split()
335
336         col = split.column()
337         col.prop(rd, "use_compositing")
338         col.prop(rd, "use_sequencer")
339
340         col = split.column()
341         col.prop(rd, "dither_intensity", text="Dither", slider=True)
342
343
344 class CyclesCamera_PT_dof(CyclesButtonsPanel, Panel):
345     bl_label = "Depth of Field"
346     bl_context = "data"
347
348     @classmethod
349     def poll(cls, context):
350         return context.camera and CyclesButtonsPanel.poll(context)
351
352     def draw(self, context):
353         layout = self.layout
354
355         cam = context.camera
356         ccam = cam.cycles
357
358         split = layout.split()
359
360         col = split.column()
361         col.label("Focus:")
362         col.prop(cam, "dof_object", text="")
363
364         sub = col.row()
365         sub.active = cam.dof_object is None
366         sub.prop(cam, "dof_distance", text="Distance")
367
368         col = split.column()
369
370         col.label("Aperture:")
371         sub = col.column(align=True)
372         sub.prop(ccam, "aperture_type", text="")
373         if ccam.aperture_type == 'RADIUS':
374             sub.prop(ccam, "aperture_size", text="Size")
375         elif ccam.aperture_type == 'FSTOP':
376             sub.prop(ccam, "aperture_fstop", text="Number")
377
378         sub = col.column(align=True)
379         sub.prop(ccam, "aperture_blades", text="Blades")
380         sub.prop(ccam, "aperture_rotation", text="Rotation")
381
382
383 class Cycles_PT_context_material(CyclesButtonsPanel, Panel):
384     bl_label = ""
385     bl_context = "material"
386     bl_options = {'HIDE_HEADER'}
387
388     @classmethod
389     def poll(cls, context):
390         return (context.material or context.object) and CyclesButtonsPanel.poll(context)
391
392     def draw(self, context):
393         layout = self.layout
394
395         mat = context.material
396         ob = context.object
397         slot = context.material_slot
398         space = context.space_data
399
400         if ob:
401             row = layout.row()
402
403             row.template_list("MATERIAL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=2)
404
405             col = row.column(align=True)
406             col.operator("object.material_slot_add", icon='ZOOMIN', text="")
407             col.operator("object.material_slot_remove", icon='ZOOMOUT', text="")
408
409             col.menu("MATERIAL_MT_specials", icon='DOWNARROW_HLT', text="")
410
411             if ob.mode == 'EDIT':
412                 row = layout.row(align=True)
413                 row.operator("object.material_slot_assign", text="Assign")
414                 row.operator("object.material_slot_select", text="Select")
415                 row.operator("object.material_slot_deselect", text="Deselect")
416
417         split = layout.split(percentage=0.65)
418
419         if ob:
420             split.template_ID(ob, "active_material", new="material.new")
421             row = split.row()
422
423             if slot:
424                 row.prop(slot, "link", text="")
425             else:
426                 row.label()
427         elif mat:
428             split.template_ID(space, "pin_id")
429             split.separator()
430
431
432 class Cycles_PT_mesh_displacement(CyclesButtonsPanel, Panel):
433     bl_label = "Displacement"
434     bl_context = "data"
435
436     @classmethod
437     def poll(cls, context):
438         if CyclesButtonsPanel.poll(context):
439             if context.mesh or context.curve or context.meta_ball:
440                 if context.scene.cycles.feature_set == 'EXPERIMENTAL':
441                     return True
442
443         return False
444
445     def draw(self, context):
446         layout = self.layout
447
448         mesh = context.mesh
449         curve = context.curve
450         mball = context.meta_ball
451
452         if mesh:
453             cdata = mesh.cycles
454         elif curve:
455             cdata = curve.cycles
456         elif mball:
457             cdata = mball.cycles
458
459         layout.prop(cdata, "displacement_method", text="Method")
460         layout.prop(cdata, "use_subdivision")
461         layout.prop(cdata, "dicing_rate")
462
463
464 class Cycles_PT_mesh_normals(CyclesButtonsPanel, Panel):
465     bl_label = "Normals"
466     bl_context = "data"
467
468     @classmethod
469     def poll(cls, context):
470         return CyclesButtonsPanel.poll(context) and context.mesh
471
472     def draw(self, context):
473         layout = self.layout
474
475         mesh = context.mesh
476
477         split = layout.split()
478
479         col = split.column()
480         col.prop(mesh, "show_double_sided")
481
482         col = split.column()
483         col.label()
484
485
486 class CyclesObject_PT_ray_visibility(CyclesButtonsPanel, Panel):
487     bl_label = "Ray Visibility"
488     bl_context = "object"
489     bl_options = {'DEFAULT_CLOSED'}
490
491     @classmethod
492     def poll(cls, context):
493         ob = context.object
494         return CyclesButtonsPanel.poll(context) and ob and ob.type in {'MESH', 'CURVE', 'CURVE', 'SURFACE', 'FONT', 'META'}  # todo: 'LAMP'
495
496     def draw(self, context):
497         layout = self.layout
498
499         ob = context.object
500         visibility = ob.cycles_visibility
501
502         flow = layout.column_flow()
503
504         flow.prop(visibility, "camera")
505         flow.prop(visibility, "diffuse")
506         flow.prop(visibility, "glossy")
507         flow.prop(visibility, "transmission")
508         flow.prop(visibility, "shadow")
509
510
511 def find_node(material, nodetype):
512     if material and material.node_tree:
513         ntree = material.node_tree
514
515         for node in ntree.nodes:
516             if getattr(node, "type", None) == nodetype:
517                 return node
518
519     return None
520
521
522 def find_node_input(node, name):
523     for input in node.inputs:
524         if input.name == name:
525             return input
526
527     return None
528
529
530 def panel_node_draw(layout, id_data, output_type, input_name):
531     if not id_data.use_nodes:
532         layout.prop(id_data, "use_nodes", icon='NODETREE')
533         return False
534
535     ntree = id_data.node_tree
536
537     node = find_node(id_data, output_type)
538     if not node:
539         layout.label(text="No output node")
540     else:
541         input = find_node_input(node, input_name)
542         layout.template_node_view(ntree, node, input)
543
544     return True
545
546
547 class CyclesLamp_PT_preview(CyclesButtonsPanel, Panel):
548     bl_label = "Preview"
549     bl_context = "data"
550     bl_options = {'DEFAULT_CLOSED'}
551
552     @classmethod
553     def poll(cls, context):
554         return context.lamp and CyclesButtonsPanel.poll(context)
555
556     def draw(self, context):
557         self.layout.template_preview(context.lamp)
558
559
560 class CyclesLamp_PT_lamp(CyclesButtonsPanel, Panel):
561     bl_label = "Lamp"
562     bl_context = "data"
563
564     @classmethod
565     def poll(cls, context):
566         return context.lamp and CyclesButtonsPanel.poll(context)
567
568     def draw(self, context):
569         layout = self.layout
570
571         lamp = context.lamp
572         clamp = lamp.cycles
573         cscene = context.scene.cycles
574         device_type = context.user_preferences.system.compute_device_type
575
576         layout.prop(lamp, "type", expand=True)
577
578         split = layout.split()
579         col = split.column(align=True)
580
581         if lamp.type in {'POINT', 'SUN', 'SPOT'}:
582             col.prop(lamp, "shadow_soft_size", text="Size")
583         elif lamp.type == 'AREA':
584             col.prop(lamp, "shape", text="")
585             sub = col.column(align=True)
586
587             if lamp.shape == 'SQUARE':
588                 sub.prop(lamp, "size")
589             elif lamp.shape == 'RECTANGLE':
590                 sub.prop(lamp, "size", text="Size X")
591                 sub.prop(lamp, "size_y", text="Size Y")
592
593         if not cscene.progressive and (device_type == 'NONE' or cscene.device == 'CPU'):
594             col.prop(clamp, "samples")
595
596         col = split.column()
597         col.prop(clamp, "cast_shadow")
598
599         layout.prop(clamp, "use_multiple_importance_sampling")
600
601         if lamp.type == 'HEMI':
602             layout.label(text="Not supported, interpreted as sun lamp")
603
604
605 class CyclesLamp_PT_nodes(CyclesButtonsPanel, Panel):
606     bl_label = "Nodes"
607     bl_context = "data"
608
609     @classmethod
610     def poll(cls, context):
611         return context.lamp and CyclesButtonsPanel.poll(context)
612
613     def draw(self, context):
614         layout = self.layout
615
616         lamp = context.lamp
617         if not panel_node_draw(layout, lamp, 'OUTPUT_LAMP', 'Surface'):
618             layout.prop(lamp, "color")
619
620
621 class CyclesLamp_PT_spot(CyclesButtonsPanel, Panel):
622     bl_label = "Spot Shape"
623     bl_context = "data"
624
625     @classmethod
626     def poll(cls, context):
627         lamp = context.lamp
628         return (lamp and lamp.type == 'SPOT') and CyclesButtonsPanel.poll(context)
629
630     def draw(self, context):
631         layout = self.layout
632
633         lamp = context.lamp
634
635         split = layout.split()
636
637         col = split.column()
638         sub = col.column()
639         sub.prop(lamp, "spot_size", text="Size")
640         sub.prop(lamp, "spot_blend", text="Blend", slider=True)
641
642         col = split.column()
643         col.prop(lamp, "show_cone")
644
645
646 class CyclesWorld_PT_preview(CyclesButtonsPanel, Panel):
647     bl_label = "Preview"
648     bl_context = "world"
649     bl_options = {'DEFAULT_CLOSED'}
650
651     @classmethod
652     def poll(cls, context):
653         return context.world and CyclesButtonsPanel.poll(context)
654
655     def draw(self, context):
656         self.layout.template_preview(context.world)
657
658
659 class CyclesWorld_PT_surface(CyclesButtonsPanel, Panel):
660     bl_label = "Surface"
661     bl_context = "world"
662
663     @classmethod
664     def poll(cls, context):
665         return context.world and CyclesButtonsPanel.poll(context)
666
667     def draw(self, context):
668         layout = self.layout
669
670         world = context.world
671
672         if not panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Surface'):
673             layout.prop(world, "horizon_color", text="Color")
674
675
676 class CyclesWorld_PT_volume(CyclesButtonsPanel, Panel):
677     bl_label = "Volume"
678     bl_context = "world"
679     bl_options = {'DEFAULT_CLOSED'}
680
681     @classmethod
682     def poll(cls, context):
683         # world = context.world
684         # world and world.node_tree and CyclesButtonsPanel.poll(context)
685         return False
686
687     def draw(self, context):
688         layout = self.layout
689         layout.active = False
690
691         world = context.world
692         panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Volume')
693
694
695 class CyclesWorld_PT_ambient_occlusion(CyclesButtonsPanel, Panel):
696     bl_label = "Ambient Occlusion"
697     bl_context = "world"
698
699     @classmethod
700     def poll(cls, context):
701         return context.world and CyclesButtonsPanel.poll(context)
702
703     def draw_header(self, context):
704         light = context.world.light_settings
705         self.layout.prop(light, "use_ambient_occlusion", text="")
706
707     def draw(self, context):
708         layout = self.layout
709         light = context.world.light_settings
710
711         layout.active = light.use_ambient_occlusion
712
713         row = layout.row()
714         row.prop(light, "ao_factor", text="Factor")
715         row.prop(light, "distance", text="Distance")
716
717
718 class CyclesWorld_PT_settings(CyclesButtonsPanel, Panel):
719     bl_label = "Settings"
720     bl_context = "world"
721     bl_options = {'DEFAULT_CLOSED'}
722
723     @classmethod
724     def poll(cls, context):
725         return context.world and CyclesButtonsPanel.poll(context)
726
727     def draw(self, context):
728         layout = self.layout
729
730         world = context.world
731         cworld = world.cycles
732         cscene = context.scene.cycles
733         device_type = context.user_preferences.system.compute_device_type
734
735         col = layout.column()
736
737         col.prop(cworld, "sample_as_light")
738         sub = col.row(align=True)
739         sub.active = cworld.sample_as_light
740         sub.prop(cworld, "sample_map_resolution")
741         if not cscene.progressive and (device_type == 'NONE' or cscene.device == 'CPU'):
742             sub.prop(cworld, "samples")
743
744
745 class CyclesMaterial_PT_preview(CyclesButtonsPanel, Panel):
746     bl_label = "Preview"
747     bl_context = "material"
748     bl_options = {'DEFAULT_CLOSED'}
749
750     @classmethod
751     def poll(cls, context):
752         return context.material and CyclesButtonsPanel.poll(context)
753
754     def draw(self, context):
755         self.layout.template_preview(context.material)
756
757
758 class CyclesMaterial_PT_surface(CyclesButtonsPanel, Panel):
759     bl_label = "Surface"
760     bl_context = "material"
761
762     @classmethod
763     def poll(cls, context):
764         return context.material and CyclesButtonsPanel.poll(context)
765
766     def draw(self, context):
767         layout = self.layout
768
769         mat = context.material
770         if not panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Surface'):
771             layout.prop(mat, "diffuse_color")
772
773
774 class CyclesMaterial_PT_volume(CyclesButtonsPanel, Panel):
775     bl_label = "Volume"
776     bl_context = "material"
777     bl_options = {'DEFAULT_CLOSED'}
778
779     @classmethod
780     def poll(cls, context):
781         # mat = context.material
782         # mat and mat.node_tree and CyclesButtonsPanel.poll(context)
783         return False
784
785     def draw(self, context):
786         layout = self.layout
787         layout.active = False
788
789         mat = context.material
790         cmat = mat.cycles
791
792         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Volume')
793
794         layout.prop(cmat, "homogeneous_volume")
795
796
797 class CyclesMaterial_PT_displacement(CyclesButtonsPanel, Panel):
798     bl_label = "Displacement"
799     bl_context = "material"
800
801     @classmethod
802     def poll(cls, context):
803         mat = context.material
804         return mat and mat.node_tree and CyclesButtonsPanel.poll(context)
805
806     def draw(self, context):
807         layout = self.layout
808
809         mat = context.material
810         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Displacement')
811
812
813 class CyclesMaterial_PT_settings(CyclesButtonsPanel, Panel):
814     bl_label = "Settings"
815     bl_context = "material"
816     bl_options = {'DEFAULT_CLOSED'}
817
818     @classmethod
819     def poll(cls, context):
820         return context.material and CyclesButtonsPanel.poll(context)
821
822     def draw(self, context):
823         layout = self.layout
824
825         mat = context.material
826         cmat = mat.cycles
827
828         split = layout.split()
829
830         col = split.column()
831         col.prop(mat, "diffuse_color", text="Viewport Color")
832
833         col = split.column()
834         col.prop(mat, "pass_index")
835
836         layout.prop(cmat, "sample_as_light")
837
838
839 class CyclesTexture_PT_context(CyclesButtonsPanel, Panel):
840     bl_label = ""
841     bl_context = "texture"
842     bl_options = {'HIDE_HEADER'}
843     COMPAT_ENGINES = {'CYCLES'}
844
845     def draw(self, context):
846         layout = self.layout
847
848         tex = context.texture
849         space = context.space_data
850         pin_id = space.pin_id
851         use_pin_id = space.use_pin_id
852         user = context.texture_user
853
854         if not use_pin_id or not isinstance(pin_id, bpy.types.Texture):
855             pin_id = None
856
857         if not pin_id:
858             layout.template_texture_user()
859
860         if user:
861             layout.separator()
862
863             split = layout.split(percentage=0.65)
864             col = split.column()
865
866             if pin_id:
867                 col.template_ID(space, "pin_id")
868             elif user:
869                 col.template_ID(user, "texture", new="texture.new")
870
871             if tex:
872                 split = layout.split(percentage=0.2)
873                 split.label(text="Type:")
874                 split.prop(tex, "type", text="")
875
876
877 class CyclesTexture_PT_node(CyclesButtonsPanel, Panel):
878     bl_label = "Node"
879     bl_context = "texture"
880
881     @classmethod
882     def poll(cls, context):
883         node = context.texture_node
884         return node and CyclesButtonsPanel.poll(context)
885
886     def draw(self, context):
887         layout = self.layout
888
889         node = context.texture_node
890         ntree = node.id_data
891         layout.template_node_view(ntree, node, None)
892
893
894 class CyclesTexture_PT_mapping(CyclesButtonsPanel, Panel):
895     bl_label = "Mapping"
896     bl_context = "texture"
897
898     @classmethod
899     def poll(cls, context):
900         node = context.texture_node
901         return node and CyclesButtonsPanel.poll(context)
902
903     def draw(self, context):
904         layout = self.layout
905
906         node = context.texture_node
907
908         mapping = node.texture_mapping
909
910         row = layout.row()
911
912         row.column().prop(mapping, "translation")
913         row.column().prop(mapping, "rotation")
914         row.column().prop(mapping, "scale")
915
916         layout.label(text="Projection:")
917
918         row = layout.row()
919         row.prop(mapping, "mapping_x", text="")
920         row.prop(mapping, "mapping_y", text="")
921         row.prop(mapping, "mapping_z", text="")
922
923
924 class CyclesTexture_PT_colors(CyclesButtonsPanel, Panel):
925     bl_label = "Color"
926     bl_context = "texture"
927     bl_options = {'DEFAULT_CLOSED'}
928
929     @classmethod
930     def poll(cls, context):
931         # node = context.texture_node
932         return False
933         #return node and CyclesButtonsPanel.poll(context)
934
935     def draw(self, context):
936         layout = self.layout
937
938         node = context.texture_node
939
940         mapping = node.color_mapping
941
942         split = layout.split()
943
944         col = split.column()
945         col.label(text="Blend:")
946         col.prop(mapping, "blend_type", text="")
947         col.prop(mapping, "blend_factor", text="Factor")
948         col.prop(mapping, "blend_color", text="")
949
950         col = split.column()
951         col.label(text="Adjust:")
952         col.prop(mapping, "brightness")
953         col.prop(mapping, "contrast")
954         col.prop(mapping, "saturation")
955
956         layout.separator()
957
958         layout.prop(mapping, "use_color_ramp", text="Ramp")
959         if mapping.use_color_ramp:
960             layout.template_color_ramp(mapping, "color_ramp", expand=True)
961
962
963 class CyclesParticle_PT_textures(CyclesButtonsPanel, Panel):
964     bl_label = "Textures"
965     bl_context = "particle"
966     bl_options = {'DEFAULT_CLOSED'}
967
968     @classmethod
969     def poll(cls, context):
970         psys = context.particle_system
971         return psys and CyclesButtonsPanel.poll(context)
972
973     def draw(self, context):
974         layout = self.layout
975
976         psys = context.particle_system
977         part = psys.settings
978
979         row = layout.row()
980         row.template_list("TEXTURE_UL_texslots", "", part, "texture_slots", part, "active_texture_index", rows=2)
981
982         col = row.column(align=True)
983         col.operator("texture.slot_move", text="", icon='TRIA_UP').type = 'UP'
984         col.operator("texture.slot_move", text="", icon='TRIA_DOWN').type = 'DOWN'
985         col.menu("TEXTURE_MT_specials", icon='DOWNARROW_HLT', text="")
986
987         if not part.active_texture:
988             layout.template_ID(part, "active_texture", new="texture.new")
989         else:
990             slot = part.texture_slots[part.active_texture_index]
991             layout.template_ID(slot, "texture", new="texture.new")
992
993
994 class CyclesRender_PT_CurveRendering(CyclesButtonsPanel, Panel):
995     bl_label = "Cycles Hair Rendering"
996     bl_context = "particle"
997
998     @classmethod
999     def poll(cls, context):
1000         scene = context.scene
1001         cscene = scene.cycles
1002         psys = context.particle_system
1003         device_type = context.user_preferences.system.compute_device_type
1004         experimental = ((cscene.feature_set == 'EXPERIMENTAL') and (cscene.device == 'CPU' or device_type == 'NONE'))
1005         return CyclesButtonsPanel.poll(context) and experimental and psys
1006
1007     def draw_header(self, context):
1008         ccscene = context.scene.cycles_curves
1009         self.layout.prop(ccscene, "use_curves", text="")
1010
1011     def draw(self, context):
1012         layout = self.layout
1013
1014         scene = context.scene
1015         ccscene = scene.cycles_curves
1016
1017         layout.active = ccscene.use_curves
1018
1019         layout.prop(ccscene, "preset", text="Mode")
1020
1021         if ccscene.preset == 'CUSTOM':
1022             layout.prop(ccscene, "primitive", text="Primitive")
1023
1024             if ccscene.primitive == 'TRIANGLES':
1025                 layout.prop(ccscene, "triangle_method", text="Method")
1026                 if ccscene.triangle_method == 'TESSELLATED_TRIANGLES':
1027                     layout.prop(ccscene, "resolution", text="Resolution")
1028                 layout.prop(ccscene, "use_smooth", text="Smooth")
1029             elif ccscene.primitive == 'LINE_SEGMENTS':
1030                 layout.prop(ccscene, "use_backfacing", text="Check back-faces")
1031
1032                 row = layout.row()
1033                 row.prop(ccscene, "use_encasing", text="Exclude encasing")
1034                 sub = row.row()
1035                 sub.active = ccscene.use_encasing
1036                 sub.prop(ccscene, "encasing_ratio", text="Ratio for encasing")
1037
1038                 layout.prop(ccscene, "line_method", text="Method")
1039                 layout.prop(ccscene, "use_tangent_normal", text="Use tangent normal as default")
1040                 layout.prop(ccscene, "use_tangent_normal_geometry", text="Use tangent normal geometry")
1041                 layout.prop(ccscene, "use_tangent_normal_correction", text="Correct tangent normal for slope")
1042                 layout.prop(ccscene, "interpolation", text="Interpolation")
1043
1044                 row = layout.row()
1045                 row.prop(ccscene, "segments", text="Segments")
1046                 row.prop(ccscene, "normalmix", text="Ray Mix")
1047             elif ccscene.primitive in {'CURVE_SEGMENTS', 'CURVE_RIBBONS'}:
1048                 layout.prop(ccscene, "subdivisions", text="Curve subdivisions")
1049                 layout.prop(ccscene, "use_backfacing", text="Check back-faces")
1050
1051                 layout.prop(ccscene, "interpolation", text="Interpolation")
1052                 row = layout.row()
1053                 row.prop(ccscene, "segments", text="Segments")
1054
1055             row = layout.row()
1056             row.prop(ccscene, "use_parents", text="Include parents")
1057
1058
1059 class CyclesParticle_PT_CurveSettings(CyclesButtonsPanel, Panel):
1060     bl_label = "Cycles Hair Settings"
1061     bl_context = "particle"
1062
1063     @classmethod
1064     def poll(cls, context):
1065         scene = context.scene
1066         cscene = scene.cycles
1067         ccscene = scene.cycles_curves
1068         use_curves = ccscene.use_curves and context.particle_system
1069         device_type = context.user_preferences.system.compute_device_type
1070         experimental = cscene.feature_set == 'EXPERIMENTAL' and (cscene.device == 'CPU' or device_type == 'NONE')
1071         return CyclesButtonsPanel.poll(context) and experimental and use_curves
1072
1073     def draw(self, context):
1074         layout = self.layout
1075
1076         psys = context.particle_settings
1077         cpsys = psys.cycles
1078
1079         row = layout.row()
1080         row.prop(cpsys, "shape", text="Shape")
1081         row.prop(cpsys, "use_closetip", text="Close tip")
1082
1083         layout.label(text="Width multiplier:")
1084         row = layout.row()
1085         row.prop(cpsys, "root_width", text="Root")
1086         row.prop(cpsys, "tip_width", text="Tip")
1087
1088
1089 class CyclesScene_PT_simplify(CyclesButtonsPanel, Panel):
1090     bl_label = "Simplify"
1091     bl_context = "scene"
1092     COMPAT_ENGINES = {'CYCLES'}
1093
1094     def draw_header(self, context):
1095         rd = context.scene.render
1096         self.layout.prop(rd, "use_simplify", text="")
1097
1098     def draw(self, context):
1099         layout = self.layout
1100
1101         rd = context.scene.render
1102
1103         layout.active = rd.use_simplify
1104
1105         row = layout.row()
1106         row.prop(rd, "simplify_subdivision", text="Subdivision")
1107         row.prop(rd, "simplify_child_particles", text="Child Particles")
1108
1109
1110 def draw_device(self, context):
1111     scene = context.scene
1112     layout = self.layout
1113
1114     if scene.render.engine == 'CYCLES':
1115         from . import engine
1116         cscene = scene.cycles
1117
1118         layout.prop(cscene, "feature_set")
1119
1120         device_type = context.user_preferences.system.compute_device_type
1121         if device_type == 'CUDA':
1122             layout.prop(cscene, "device")
1123         elif device_type == 'OPENCL' and cscene.feature_set == 'EXPERIMENTAL':
1124             layout.prop(cscene, "device")
1125
1126         if engine.with_osl() and (cscene.device == 'CPU' or device_type == 'NONE'):
1127             layout.prop(cscene, "shading_system")
1128
1129
1130 def draw_pause(self, context):
1131     layout = self.layout
1132     scene = context.scene
1133
1134     if scene.render.engine == "CYCLES":
1135         view = context.space_data
1136
1137         if view.viewport_shade == 'RENDERED':
1138             cscene = scene.cycles
1139             layername = scene.render.layers.active.name
1140             layout.prop(cscene, "preview_pause", icon="PAUSE", text="")
1141             layout.prop(cscene, "preview_active_layer", icon="RENDERLAYERS", text=layername)
1142
1143
1144 def get_panels():
1145     types = bpy.types
1146     return (
1147         types.RENDER_PT_render,
1148         types.RENDER_PT_output,
1149         types.RENDER_PT_encoding,
1150         types.RENDER_PT_dimensions,
1151         types.RENDER_PT_stamp,
1152         types.SCENE_PT_scene,
1153         types.SCENE_PT_color_management,
1154         types.SCENE_PT_custom_props,
1155         types.SCENE_PT_audio,
1156         types.SCENE_PT_unit,
1157         types.SCENE_PT_keying_sets,
1158         types.SCENE_PT_keying_set_paths,
1159         types.SCENE_PT_physics,
1160         types.WORLD_PT_context_world,
1161         types.WORLD_PT_custom_props,
1162         types.DATA_PT_context_mesh,
1163         types.DATA_PT_context_camera,
1164         types.DATA_PT_context_lamp,
1165         types.DATA_PT_context_speaker,
1166         types.DATA_PT_texture_space,
1167         types.DATA_PT_curve_texture_space,
1168         types.DATA_PT_mball_texture_space,
1169         types.DATA_PT_vertex_groups,
1170         types.DATA_PT_shape_keys,
1171         types.DATA_PT_uv_texture,
1172         types.DATA_PT_vertex_colors,
1173         types.DATA_PT_camera,
1174         types.DATA_PT_camera_display,
1175         types.DATA_PT_lens,
1176         types.DATA_PT_speaker,
1177         types.DATA_PT_distance,
1178         types.DATA_PT_cone,
1179         types.DATA_PT_customdata,
1180         types.DATA_PT_custom_props_mesh,
1181         types.DATA_PT_custom_props_camera,
1182         types.DATA_PT_custom_props_lamp,
1183         types.DATA_PT_custom_props_speaker,
1184         types.DATA_PT_custom_props_arm,
1185         types.DATA_PT_custom_props_curve,
1186         types.DATA_PT_custom_props_lattice,
1187         types.DATA_PT_custom_props_metaball,
1188         types.TEXTURE_PT_custom_props,
1189         types.TEXTURE_PT_clouds,
1190         types.TEXTURE_PT_wood,
1191         types.TEXTURE_PT_marble,
1192         types.TEXTURE_PT_magic,
1193         types.TEXTURE_PT_blend,
1194         types.TEXTURE_PT_stucci,
1195         types.TEXTURE_PT_image,
1196         types.TEXTURE_PT_image_sampling,
1197         types.TEXTURE_PT_image_mapping,
1198         types.TEXTURE_PT_musgrave,
1199         types.TEXTURE_PT_voronoi,
1200         types.TEXTURE_PT_distortednoise,
1201         types.TEXTURE_PT_voxeldata,
1202         types.TEXTURE_PT_pointdensity,
1203         types.TEXTURE_PT_pointdensity_turbulence,
1204         types.TEXTURE_PT_mapping,
1205         types.TEXTURE_PT_influence,
1206         types.TEXTURE_PT_colors,
1207         types.PARTICLE_PT_context_particles,
1208         types.PARTICLE_PT_custom_props,
1209         types.PARTICLE_PT_emission,
1210         types.PARTICLE_PT_hair_dynamics,
1211         types.PARTICLE_PT_cache,
1212         types.PARTICLE_PT_velocity,
1213         types.PARTICLE_PT_rotation,
1214         types.PARTICLE_PT_physics,
1215         types.SCENE_PT_rigid_body_world,
1216         types.SCENE_PT_rigid_body_cache,
1217         types.SCENE_PT_rigid_body_field_weights,
1218         types.PARTICLE_PT_boidbrain,
1219         types.PARTICLE_PT_render,
1220         types.PARTICLE_PT_draw,
1221         types.PARTICLE_PT_children,
1222         types.PARTICLE_PT_field_weights,
1223         types.PARTICLE_PT_force_fields,
1224         types.PARTICLE_PT_vertexgroups,
1225         types.MATERIAL_PT_custom_props,
1226         types.BONE_PT_custom_props,
1227         types.OBJECT_PT_custom_props,
1228         )
1229
1230
1231 def register():
1232     bpy.types.RENDER_PT_render.append(draw_device)
1233     bpy.types.VIEW3D_HT_header.append(draw_pause)
1234
1235     for panel in get_panels():
1236         panel.COMPAT_ENGINES.add('CYCLES')
1237
1238
1239 def unregister():
1240     bpy.types.RENDER_PT_render.remove(draw_device)
1241     bpy.types.VIEW3D_HT_header.remove(draw_pause)
1242
1243     for panel in get_panels():
1244         panel.COMPAT_ENGINES.remove('CYCLES')