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