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