Merge branch 'master' into blender2.8
[blender.git] / release / scripts / startup / bl_ui / properties_texture.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import Menu, Panel, UIList
22
23 from bpy.types import (
24     Brush,
25     FreestyleLineStyle,
26     Lamp,
27     Material,
28     Object,
29     ParticleSettings,
30     Texture,
31     World,
32 )
33
34 from rna_prop_ui import PropertyPanel
35
36 from .properties_paint_common import brush_texture_settings
37
38
39 class TEXTURE_MT_specials(Menu):
40     bl_label = "Texture Specials"
41     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
42
43     def draw(self, context):
44         layout = self.layout
45
46         layout.operator("texture.slot_copy", icon='COPYDOWN')
47         layout.operator("texture.slot_paste", icon='PASTEDOWN')
48
49
50 class TEXTURE_MT_envmap_specials(Menu):
51     bl_label = "Environment Map Specials"
52     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
53
54     def draw(self, context):
55         layout = self.layout
56
57         layout.operator("texture.envmap_save", icon='IMAGEFILE')
58         layout.operator("texture.envmap_clear", icon='FILE_REFRESH')
59         layout.operator("texture.envmap_clear_all", icon='FILE_REFRESH')
60
61
62 class TEXTURE_UL_texslots(UIList):
63
64     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
65         # assert(isinstance(item, bpy.types.MaterialTextureSlot)
66         ma = data
67         slot = item
68         tex = slot.texture if slot else None
69         if self.layout_type in {'DEFAULT', 'COMPACT'}:
70             if tex:
71                 layout.prop(tex, "name", text="", emboss=False, icon_value=icon)
72             else:
73                 layout.label(text="", icon_value=icon)
74             if tex and isinstance(item, bpy.types.MaterialTextureSlot):
75                 layout.prop(ma, "use_textures", text="", index=index)
76         elif self.layout_type == 'GRID':
77             layout.alignment = 'CENTER'
78             layout.label(text="", icon_value=icon)
79
80
81 from .properties_material import active_node_mat
82
83
84 def context_tex_datablock(context):
85     idblock = context.material
86     if idblock:
87         return active_node_mat(idblock)
88
89     idblock = context.lamp
90     if idblock:
91         return idblock
92
93     idblock = context.world
94     if idblock:
95         return idblock
96
97     idblock = context.brush
98     if idblock:
99         return idblock
100
101     idblock = context.line_style
102     if idblock:
103         return idblock
104
105     if context.particle_system:
106         idblock = context.particle_system.settings
107
108     return idblock
109
110
111 def id_tex_datablock(bid):
112     if isinstance(bid, Object):
113         if bid.type == 'LAMP':
114             return bid.data
115         return bid.active_material
116
117     return bid
118
119
120 class TextureButtonsPanel:
121     bl_space_type = 'PROPERTIES'
122     bl_region_type = 'WINDOW'
123     bl_context = "texture"
124
125     @classmethod
126     def poll(cls, context):
127         tex = context.texture
128         return tex and (tex.type != 'NONE' or tex.use_nodes) and (context.engine in cls.COMPAT_ENGINES)
129
130
131 class TEXTURE_PT_context_texture(TextureButtonsPanel, Panel):
132     bl_label = ""
133     bl_options = {'HIDE_HEADER'}
134     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
135
136     @classmethod
137     def poll(cls, context):
138         engine = context.engine
139         # if not (hasattr(context, "texture_slot") or hasattr(context, "texture_node")):
140         #     return False
141         return ((context.material or
142                  context.world or
143                  context.lamp or
144                  context.texture or
145                  context.line_style or
146                  context.particle_system or
147                  isinstance(context.space_data.pin_id, ParticleSettings) or
148                  context.texture_user) and
149                 (engine in cls.COMPAT_ENGINES))
150
151     def draw(self, context):
152         layout = self.layout
153
154         slot = getattr(context, "texture_slot", None)
155         node = getattr(context, "texture_node", None)
156         space = context.space_data
157         tex = context.texture
158         idblock = context_tex_datablock(context)
159         pin_id = space.pin_id
160
161         space.use_limited_texture_context = True
162
163         if space.use_pin_id and not isinstance(pin_id, Texture):
164             idblock = id_tex_datablock(pin_id)
165             pin_id = None
166
167         if not space.use_pin_id:
168             layout.row().prop(space, "texture_context", expand=True)
169             pin_id = None
170
171         if space.texture_context == 'OTHER':
172             if not pin_id:
173                 layout.template_texture_user()
174             user = context.texture_user
175             if user or pin_id:
176                 layout.separator()
177
178                 row = layout.row()
179
180                 if pin_id:
181                     row.template_ID(space, "pin_id")
182                 else:
183                     propname = context.texture_user_property.identifier
184                     row.template_ID(user, propname, new="texture.new")
185
186                 if tex:
187                     split = layout.split(percentage=0.2)
188                     if tex.use_nodes:
189                         if slot:
190                             split.label(text="Output:")
191                             split.prop(slot, "output_node", text="")
192                     else:
193                         split.label(text="Type:")
194                         split.prop(tex, "type", text="")
195             return
196
197         tex_collection = (pin_id is None) and (node is None) and (not isinstance(idblock, Brush))
198
199         if tex_collection:
200             row = layout.row()
201
202             row.template_list("TEXTURE_UL_texslots", "", idblock, "texture_slots",
203                               idblock, "active_texture_index", rows=2)
204
205             col = row.column(align=True)
206             col.operator("texture.slot_move", text="", icon='TRIA_UP').type = 'UP'
207             col.operator("texture.slot_move", text="", icon='TRIA_DOWN').type = 'DOWN'
208             col.menu("TEXTURE_MT_specials", icon='DOWNARROW_HLT', text="")
209
210         if tex_collection:
211             layout.template_ID(idblock, "active_texture", new="texture.new")
212         elif node:
213             layout.template_ID(node, "texture", new="texture.new")
214         elif idblock:
215             layout.template_ID(idblock, "texture", new="texture.new")
216
217         if pin_id:
218             layout.template_ID(space, "pin_id")
219
220         if tex:
221             split = layout.split(percentage=0.2)
222             if tex.use_nodes:
223                 if slot:
224                     split.label(text="Output:")
225                     split.prop(slot, "output_node", text="")
226             else:
227                 split.label(text="Type:")
228                 split.prop(tex, "type", text="")
229
230
231 class TEXTURE_PT_preview(TextureButtonsPanel, Panel):
232     bl_label = "Preview"
233     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
234
235     def draw(self, context):
236         layout = self.layout
237
238         tex = context.texture
239         slot = getattr(context, "texture_slot", None)
240         idblock = context_tex_datablock(context)
241
242         if idblock:
243             layout.template_preview(tex, parent=idblock, slot=slot)
244         else:
245             layout.template_preview(tex, slot=slot)
246
247         # Show Alpha Button for Brush Textures, see #29502
248         if context.space_data.texture_context == 'BRUSH':
249             layout.prop(tex, "use_preview_alpha")
250
251
252 class TEXTURE_PT_colors(TextureButtonsPanel, Panel):
253     bl_label = "Colors"
254     bl_options = {'DEFAULT_CLOSED'}
255     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
256
257     def draw(self, context):
258         layout = self.layout
259
260         tex = context.texture
261
262         layout.prop(tex, "use_color_ramp", text="Ramp")
263         if tex.use_color_ramp:
264             layout.template_color_ramp(tex, "color_ramp", expand=True)
265
266         split = layout.split()
267
268         col = split.column()
269         col.label(text="RGB Multiply:")
270         sub = col.column(align=True)
271         sub.prop(tex, "factor_red", text="R")
272         sub.prop(tex, "factor_green", text="G")
273         sub.prop(tex, "factor_blue", text="B")
274
275         col = split.column()
276         col.label(text="Adjust:")
277         col.prop(tex, "intensity")
278         col.prop(tex, "contrast")
279         col.prop(tex, "saturation")
280
281         col = layout.column()
282         col.prop(tex, "use_clamp", text="Clamp")
283
284 # Texture Slot Panels #
285
286
287 class TextureSlotPanel(TextureButtonsPanel):
288     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
289
290     @classmethod
291     def poll(cls, context):
292         if not hasattr(context, "texture_slot"):
293             return False
294
295         engine = context.engine
296         return TextureButtonsPanel.poll(cls, context) and (engine in cls.COMPAT_ENGINES)
297
298
299 # Texture Type Panels #
300
301
302 class TextureTypePanel(TextureButtonsPanel):
303
304     @classmethod
305     def poll(cls, context):
306         tex = context.texture
307         engine = context.engine
308         return tex and ((tex.type == cls.tex_type and not tex.use_nodes) and (engine in cls.COMPAT_ENGINES))
309
310
311 class TEXTURE_PT_clouds(TextureTypePanel, Panel):
312     bl_label = "Clouds"
313     tex_type = 'CLOUDS'
314     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
315
316     def draw(self, context):
317         layout = self.layout
318
319         tex = context.texture
320
321         layout.row().prop(tex, "cloud_type", expand=True)
322         layout.label(text="Noise:")
323         layout.row().prop(tex, "noise_type", text="Type", expand=True)
324         layout.prop(tex, "noise_basis", text="Basis")
325
326         split = layout.split()
327
328         col = split.column()
329         col.prop(tex, "noise_scale", text="Size")
330         col.prop(tex, "noise_depth", text="Depth")
331
332         split.prop(tex, "nabla", text="Nabla")
333
334
335 class TEXTURE_PT_wood(TextureTypePanel, Panel):
336     bl_label = "Wood"
337     tex_type = 'WOOD'
338     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
339
340     def draw(self, context):
341         layout = self.layout
342
343         tex = context.texture
344
345         layout.row().prop(tex, "noise_basis_2", expand=True)
346         layout.row().prop(tex, "wood_type", expand=True)
347
348         col = layout.column()
349         col.active = tex.wood_type in {'RINGNOISE', 'BANDNOISE'}
350         col.label(text="Noise:")
351         col.row().prop(tex, "noise_type", text="Type", expand=True)
352         layout.prop(tex, "noise_basis", text="Basis")
353
354         split = layout.split()
355         split.active = tex.wood_type in {'RINGNOISE', 'BANDNOISE'}
356
357         col = split.column()
358         col.prop(tex, "noise_scale", text="Size")
359         col.prop(tex, "turbulence")
360
361         split.prop(tex, "nabla")
362
363
364 class TEXTURE_PT_marble(TextureTypePanel, Panel):
365     bl_label = "Marble"
366     tex_type = 'MARBLE'
367     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
368
369     def draw(self, context):
370         layout = self.layout
371
372         tex = context.texture
373
374         layout.row().prop(tex, "marble_type", expand=True)
375         layout.row().prop(tex, "noise_basis_2", expand=True)
376         layout.label(text="Noise:")
377         layout.row().prop(tex, "noise_type", text="Type", expand=True)
378         layout.prop(tex, "noise_basis", text="Basis")
379
380         split = layout.split()
381
382         col = split.column()
383         col.prop(tex, "noise_scale", text="Size")
384         col.prop(tex, "noise_depth", text="Depth")
385
386         col = split.column()
387         col.prop(tex, "turbulence")
388         col.prop(tex, "nabla")
389
390
391 class TEXTURE_PT_magic(TextureTypePanel, Panel):
392     bl_label = "Magic"
393     tex_type = 'MAGIC'
394     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
395
396     def draw(self, context):
397         layout = self.layout
398
399         tex = context.texture
400
401         row = layout.row()
402         row.prop(tex, "noise_depth", text="Depth")
403         row.prop(tex, "turbulence")
404
405
406 class TEXTURE_PT_blend(TextureTypePanel, Panel):
407     bl_label = "Blend"
408     tex_type = 'BLEND'
409     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
410
411     def draw(self, context):
412         layout = self.layout
413
414         tex = context.texture
415
416         layout.prop(tex, "progression")
417
418         sub = layout.row()
419
420         sub.active = (tex.progression in {'LINEAR', 'QUADRATIC', 'EASING', 'RADIAL'})
421         sub.prop(tex, "use_flip_axis", expand=True)
422
423
424 class TEXTURE_PT_stucci(TextureTypePanel, Panel):
425     bl_label = "Stucci"
426     tex_type = 'STUCCI'
427     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
428
429     def draw(self, context):
430         layout = self.layout
431
432         tex = context.texture
433
434         layout.row().prop(tex, "stucci_type", expand=True)
435         layout.label(text="Noise:")
436         layout.row().prop(tex, "noise_type", text="Type", expand=True)
437         layout.prop(tex, "noise_basis", text="Basis")
438
439         row = layout.row()
440         row.prop(tex, "noise_scale", text="Size")
441         row.prop(tex, "turbulence")
442
443
444 class TEXTURE_PT_image(TextureTypePanel, Panel):
445     bl_label = "Image"
446     tex_type = 'IMAGE'
447     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
448
449     def draw(self, context):
450         layout = self.layout
451
452         tex = context.texture
453
454         layout.template_image(tex, "image", tex.image_user)
455
456
457 def texture_filter_common(tex, layout):
458     layout.label(text="Filter:")
459     layout.prop(tex, "filter_type", text="")
460     if tex.use_mipmap and tex.filter_type in {'AREA', 'EWA', 'FELINE'}:
461         if tex.filter_type == 'FELINE':
462             layout.prop(tex, "filter_lightprobes", text="Light Probes")
463         else:
464             layout.prop(tex, "filter_eccentricity", text="Eccentricity")
465
466     layout.prop(tex, "filter_size")
467     layout.prop(tex, "use_filter_size_min")
468
469
470 class TEXTURE_PT_image_sampling(TextureTypePanel, Panel):
471     bl_label = "Image Sampling"
472     bl_options = {'DEFAULT_CLOSED'}
473     tex_type = 'IMAGE'
474     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
475
476     def draw(self, context):
477         if context.engine == 'BLENDER_GAME':
478             self.draw_bge(context)
479         else:
480             self.draw_bi(context)
481
482     def draw_bi(self, context):
483         layout = self.layout
484
485         idblock = context_tex_datablock(context)
486         tex = context.texture
487         slot = getattr(context, "texture_slot", None)
488
489         split = layout.split()
490
491         col = split.column()
492         col.label(text="Alpha:")
493         row = col.row()
494         row.active = bool(tex.image and tex.image.use_alpha)
495         row.prop(tex, "use_alpha", text="Use")
496         col.prop(tex, "use_calculate_alpha", text="Calculate")
497         col.prop(tex, "invert_alpha", text="Invert")
498         col.separator()
499         col.prop(tex, "use_flip_axis", text="Flip X/Y Axis")
500
501         col = split.column()
502
503         # Only for Material based textures, not for Lamp/World...
504         if slot and isinstance(idblock, Material):
505             col.prop(tex, "use_normal_map")
506             row = col.row()
507             row.active = tex.use_normal_map
508             row.prop(slot, "normal_map_space", text="")
509
510             row = col.row()
511             row.active = not tex.use_normal_map
512             row.prop(tex, "use_derivative_map")
513
514         col.prop(tex, "use_mipmap")
515         row = col.row()
516         row.active = tex.use_mipmap
517         row.prop(tex, "use_mipmap_gauss")
518         col.prop(tex, "use_interpolation")
519
520         texture_filter_common(tex, col)
521
522     def draw_bge(self, context):
523         layout = self.layout
524
525         idblock = context_tex_datablock(context)
526         tex = context.texture
527         slot = getattr(context, "texture_slot", None)
528
529         split = layout.split()
530
531         col = split.column()
532         col.label(text="Alpha:")
533         col.prop(tex, "use_calculate_alpha", text="Calculate")
534         col.prop(tex, "invert_alpha", text="Invert")
535
536         col = split.column()
537
538         # Only for Material based textures, not for Lamp/World...
539         if slot and isinstance(idblock, Material):
540             col.prop(tex, "use_normal_map")
541             row = col.row()
542             row.active = tex.use_normal_map
543             row.prop(slot, "normal_map_space", text="")
544
545             row = col.row()
546             row.active = not tex.use_normal_map
547             row.prop(tex, "use_derivative_map")
548
549
550 class TEXTURE_PT_image_mapping(TextureTypePanel, Panel):
551     bl_label = "Image Mapping"
552     bl_options = {'DEFAULT_CLOSED'}
553     tex_type = 'IMAGE'
554     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
555
556     def draw(self, context):
557         layout = self.layout
558
559         tex = context.texture
560
561         layout.prop(tex, "extension")
562
563         split = layout.split()
564
565         if tex.extension == 'REPEAT':
566             col = split.column(align=True)
567             col.label(text="Repeat:")
568             col.prop(tex, "repeat_x", text="X")
569             col.prop(tex, "repeat_y", text="Y")
570
571             col = split.column(align=True)
572             col.label(text="Mirror:")
573             row = col.row(align=True)
574             row.prop(tex, "use_mirror_x", text="X")
575             row.active = (tex.repeat_x > 1)
576             row = col.row(align=True)
577             row.prop(tex, "use_mirror_y", text="Y")
578             row.active = (tex.repeat_y > 1)
579             layout.separator()
580
581         elif tex.extension == 'CHECKER':
582             col = split.column(align=True)
583             row = col.row(align=True)
584             row.prop(tex, "use_checker_even", text="Even")
585             row.prop(tex, "use_checker_odd", text="Odd")
586
587             col = split.column()
588             col.prop(tex, "checker_distance", text="Distance")
589
590             layout.separator()
591
592         split = layout.split()
593
594         col = split.column(align=True)
595         # col.prop(tex, "crop_rectangle")
596         col.label(text="Crop Minimum:")
597         col.prop(tex, "crop_min_x", text="X")
598         col.prop(tex, "crop_min_y", text="Y")
599
600         col = split.column(align=True)
601         col.label(text="Crop Maximum:")
602         col.prop(tex, "crop_max_x", text="X")
603         col.prop(tex, "crop_max_y", text="Y")
604
605
606 class TEXTURE_PT_envmap(TextureTypePanel, Panel):
607     bl_label = "Environment Map"
608     tex_type = 'ENVIRONMENT_MAP'
609     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
610
611     def draw(self, context):
612         layout = self.layout
613
614         tex = context.texture
615         env = tex.environment_map
616
617         row = layout.row()
618         row.prop(env, "source", expand=True)
619         row.menu("TEXTURE_MT_envmap_specials", icon='DOWNARROW_HLT', text="")
620
621         if env.source == 'IMAGE_FILE':
622             layout.template_ID(tex, "image", open="image.open")
623             layout.template_image(tex, "image", tex.image_user, compact=True)
624         else:
625             layout.prop(env, "mapping")
626             if env.mapping == 'PLANE':
627                 layout.prop(env, "zoom")
628             layout.prop(env, "viewpoint_object")
629
630             split = layout.split()
631
632             col = split.column()
633             col.prop(env, "layers_ignore")
634             col.prop(env, "resolution")
635             col.prop(env, "depth")
636
637             col = split.column(align=True)
638
639             col.label(text="Clipping:")
640             col.prop(env, "clip_start", text="Start")
641             col.prop(env, "clip_end", text="End")
642
643
644 class TEXTURE_PT_envmap_sampling(TextureTypePanel, Panel):
645     bl_label = "Environment Map Sampling"
646     bl_options = {'DEFAULT_CLOSED'}
647     tex_type = 'ENVIRONMENT_MAP'
648     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
649
650     def draw(self, context):
651         layout = self.layout
652
653         tex = context.texture
654
655         texture_filter_common(tex, layout)
656
657
658 class TEXTURE_PT_musgrave(TextureTypePanel, Panel):
659     bl_label = "Musgrave"
660     tex_type = 'MUSGRAVE'
661     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
662
663     def draw(self, context):
664         layout = self.layout
665
666         tex = context.texture
667
668         layout.prop(tex, "musgrave_type")
669
670         split = layout.split()
671
672         col = split.column()
673         col.prop(tex, "dimension_max", text="Dimension")
674         col.prop(tex, "lacunarity")
675         col.prop(tex, "octaves")
676
677         musgrave_type = tex.musgrave_type
678         col = split.column()
679         if musgrave_type in {'HETERO_TERRAIN', 'RIDGED_MULTIFRACTAL', 'HYBRID_MULTIFRACTAL'}:
680             col.prop(tex, "offset")
681         col.prop(tex, "noise_intensity", text="Intensity")
682         if musgrave_type in {'RIDGED_MULTIFRACTAL', 'HYBRID_MULTIFRACTAL'}:
683             col.prop(tex, "gain")
684
685         layout.label(text="Noise:")
686
687         layout.prop(tex, "noise_basis", text="Basis")
688
689         row = layout.row()
690         row.prop(tex, "noise_scale", text="Size")
691         row.prop(tex, "nabla")
692
693
694 class TEXTURE_PT_voronoi(TextureTypePanel, Panel):
695     bl_label = "Voronoi"
696     tex_type = 'VORONOI'
697     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
698
699     def draw(self, context):
700         layout = self.layout
701
702         tex = context.texture
703
704         split = layout.split()
705
706         col = split.column()
707         col.label(text="Distance Metric:")
708         col.prop(tex, "distance_metric", text="")
709         sub = col.column()
710         sub.active = tex.distance_metric == 'MINKOVSKY'
711         sub.prop(tex, "minkovsky_exponent", text="Exponent")
712         col.label(text="Coloring:")
713         col.prop(tex, "color_mode", text="")
714         col.prop(tex, "noise_intensity", text="Intensity")
715
716         col = split.column()
717         sub = col.column(align=True)
718         sub.label(text="Feature Weights:")
719         sub.prop(tex, "weight_1", text="1", slider=True)
720         sub.prop(tex, "weight_2", text="2", slider=True)
721         sub.prop(tex, "weight_3", text="3", slider=True)
722         sub.prop(tex, "weight_4", text="4", slider=True)
723
724         layout.label(text="Noise:")
725         row = layout.row()
726         row.prop(tex, "noise_scale", text="Size")
727         row.prop(tex, "nabla")
728
729
730 class TEXTURE_PT_distortednoise(TextureTypePanel, Panel):
731     bl_label = "Distorted Noise"
732     tex_type = 'DISTORTED_NOISE'
733     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
734
735     def draw(self, context):
736         layout = self.layout
737
738         tex = context.texture
739
740         layout.prop(tex, "noise_distortion")
741         layout.prop(tex, "noise_basis", text="Basis")
742
743         split = layout.split()
744
745         col = split.column()
746         col.prop(tex, "distortion", text="Distortion")
747         col.prop(tex, "noise_scale", text="Size")
748
749         split.prop(tex, "nabla")
750
751
752 class TEXTURE_PT_voxeldata(TextureButtonsPanel, Panel):
753     bl_label = "Voxel Data"
754     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
755
756     @classmethod
757     def poll(cls, context):
758         tex = context.texture
759         engine = context.engine
760         return tex and (tex.type == 'VOXEL_DATA' and (engine in cls.COMPAT_ENGINES))
761
762     def draw(self, context):
763         layout = self.layout
764
765         tex = context.texture
766         vd = tex.voxel_data
767
768         layout.prop(vd, "file_format")
769         if vd.file_format in {'BLENDER_VOXEL', 'RAW_8BIT'}:
770             layout.prop(vd, "filepath")
771         if vd.file_format == 'RAW_8BIT':
772             layout.prop(vd, "resolution")
773         elif vd.file_format == 'SMOKE':
774             layout.prop(vd, "domain_object")
775             layout.prop(vd, "smoke_data_type")
776         elif vd.file_format == 'HAIR':
777             layout.prop(vd, "domain_object")
778             layout.prop(vd, "hair_data_type")
779         elif vd.file_format == 'IMAGE_SEQUENCE':
780             layout.template_ID(tex, "image", open="image.open")
781             layout.template_image(tex, "image", tex.image_user, compact=True)
782             # layout.prop(vd, "frame_duration")
783
784         if vd.file_format in {'BLENDER_VOXEL', 'RAW_8BIT'}:
785             layout.prop(vd, "use_still_frame")
786             row = layout.row()
787             row.active = vd.use_still_frame
788             row.prop(vd, "still_frame")
789
790         layout.prop(vd, "interpolation")
791         layout.prop(vd, "extension")
792         layout.prop(vd, "intensity")
793
794
795 class TEXTURE_PT_pointdensity(TextureButtonsPanel, Panel):
796     bl_label = "Point Density"
797     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
798
799     @classmethod
800     def poll(cls, context):
801         tex = context.texture
802         engine = context.engine
803         return tex and (tex.type == 'POINT_DENSITY' and (engine in cls.COMPAT_ENGINES))
804
805     def draw(self, context):
806         layout = self.layout
807
808         tex = context.texture
809         pd = tex.point_density
810
811         layout.row().prop(pd, "point_source", expand=True)
812
813         split = layout.split()
814
815         col = split.column()
816         if pd.point_source == 'PARTICLE_SYSTEM':
817             col.label(text="Object:")
818             col.prop(pd, "object", text="")
819
820             sub = col.column()
821             sub.enabled = bool(pd.object)
822             if pd.object:
823                 sub.label(text="System:")
824                 sub.prop_search(pd, "particle_system", pd.object, "particle_systems", text="")
825             sub.label(text="Cache:")
826             sub.prop(pd, "particle_cache_space", text="")
827         else:
828             col.label(text="Object:")
829             col.prop(pd, "object", text="")
830             col.label(text="Cache:")
831             col.prop(pd, "vertex_cache_space", text="")
832
833         col.separator()
834
835         col.label(text="Color Source:")
836         if pd.point_source == 'PARTICLE_SYSTEM':
837             col.prop(pd, "particle_color_source", text="")
838             if pd.particle_color_source in {'PARTICLE_SPEED', 'PARTICLE_VELOCITY'}:
839                 col.prop(pd, "speed_scale")
840             if pd.particle_color_source in {'PARTICLE_SPEED', 'PARTICLE_AGE'}:
841                 layout.template_color_ramp(pd, "color_ramp", expand=True)
842         else:
843             col.prop(pd, "vertex_color_source", text="")
844             if pd.vertex_color_source == 'VERTEX_COLOR':
845                 if pd.object and pd.object.data:
846                     col.prop_search(pd, "vertex_attribute_name", pd.object.data, "vertex_colors", text="")
847             if pd.vertex_color_source == 'VERTEX_WEIGHT':
848                 if pd.object:
849                     col.prop_search(pd, "vertex_attribute_name", pd.object, "vertex_groups", text="")
850                 layout.template_color_ramp(pd, "color_ramp", expand=True)
851
852         col = split.column()
853         col.label()
854         col.prop(pd, "radius")
855         col.label(text="Falloff:")
856         col.prop(pd, "falloff", text="")
857         if pd.falloff == 'SOFT':
858             col.prop(pd, "falloff_soft")
859         if pd.falloff == 'PARTICLE_VELOCITY':
860             col.prop(pd, "falloff_speed_scale")
861
862         col.prop(pd, "use_falloff_curve")
863
864         if pd.use_falloff_curve:
865             col = layout.column()
866             col.label(text="Falloff Curve")
867             col.template_curve_mapping(pd, "falloff_curve", brush=False)
868
869
870 class TEXTURE_PT_pointdensity_turbulence(TextureButtonsPanel, Panel):
871     bl_label = "Turbulence"
872     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
873
874     @classmethod
875     def poll(cls, context):
876         tex = context.texture
877         engine = context.engine
878         return tex and (tex.type == 'POINT_DENSITY' and (engine in cls.COMPAT_ENGINES))
879
880     def draw_header(self, context):
881         pd = context.texture.point_density
882
883         self.layout.prop(pd, "use_turbulence", text="")
884
885     def draw(self, context):
886         layout = self.layout
887
888         tex = context.texture
889         pd = tex.point_density
890         layout.active = pd.use_turbulence
891
892         split = layout.split()
893
894         col = split.column()
895         col.label(text="Influence:")
896         col.prop(pd, "turbulence_influence", text="")
897         col.label(text="Noise Basis:")
898         col.prop(pd, "noise_basis", text="")
899
900         col = split.column()
901         col.label()
902         col.prop(pd, "turbulence_scale")
903         col.prop(pd, "turbulence_depth")
904         col.prop(pd, "turbulence_strength")
905
906
907 class TEXTURE_PT_ocean(TextureTypePanel, Panel):
908     bl_label = "Ocean"
909     tex_type = 'OCEAN'
910     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
911
912     def draw(self, context):
913         layout = self.layout
914
915         tex = context.texture
916         ot = tex.ocean
917
918         col = layout.column()
919         col.prop(ot, "ocean_object")
920         col.prop(ot, "output")
921
922
923 class TEXTURE_PT_mapping(TextureSlotPanel, Panel):
924     bl_label = "Mapping"
925     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
926
927     @classmethod
928     def poll(cls, context):
929         idblock = context_tex_datablock(context)
930         if isinstance(idblock, Brush) and not context.sculpt_object:
931             return False
932
933         if not getattr(context, "texture_slot", None):
934             return False
935
936         engine = context.engine
937         return (engine in cls.COMPAT_ENGINES)
938
939     def draw(self, context):
940         layout = self.layout
941
942         idblock = context_tex_datablock(context)
943
944         tex = context.texture_slot
945
946         if not isinstance(idblock, Brush):
947             split = layout.split(percentage=0.3)
948             col = split.column()
949             col.label(text="Coordinates:")
950             col = split.column()
951             col.prop(tex, "texture_coords", text="")
952
953             if tex.texture_coords == 'ORCO':
954                 """
955                 ob = context.object
956                 if ob and ob.type == 'MESH':
957                     split = layout.split(percentage=0.3)
958                     split.label(text="Mesh:")
959                     split.prop(ob.data, "texco_mesh", text="")
960                 """
961             elif tex.texture_coords == 'UV':
962                 split = layout.split(percentage=0.3)
963                 split.label(text="Map:")
964                 ob = context.object
965                 if ob and ob.type == 'MESH':
966                     split.prop_search(tex, "uv_layer", ob.data, "uv_layers", text="")
967                 else:
968                     split.prop(tex, "uv_layer", text="")
969
970             elif tex.texture_coords == 'OBJECT':
971                 split = layout.split(percentage=0.3)
972                 split.label(text="Object:")
973                 split.prop(tex, "object", text="")
974
975             elif tex.texture_coords == 'ALONG_STROKE':
976                 split = layout.split(percentage=0.3)
977                 split.label(text="Use Tips:")
978                 split.prop(tex, "use_tips", text="")
979
980         if isinstance(idblock, Brush):
981             if context.sculpt_object or context.image_paint_object:
982                 brush_texture_settings(layout, idblock, context.sculpt_object)
983         else:
984             if isinstance(idblock, FreestyleLineStyle):
985                 split = layout.split(percentage=0.3)
986                 split.label(text="Projection:")
987                 split.prop(tex, "mapping", text="")
988
989                 split = layout.split(percentage=0.3)
990                 split.separator()
991                 row = split.row()
992                 row.prop(tex, "mapping_x", text="")
993                 row.prop(tex, "mapping_y", text="")
994                 row.prop(tex, "mapping_z", text="")
995
996             elif isinstance(idblock, Material):
997                 split = layout.split(percentage=0.3)
998                 split.label(text="Projection:")
999                 split.prop(tex, "mapping", text="")
1000
1001                 split = layout.split()
1002
1003                 col = split.column()
1004                 if tex.texture_coords in {'ORCO', 'UV'}:
1005                     col.prop(tex, "use_from_dupli")
1006                     if (idblock.type == 'VOLUME' and tex.texture_coords == 'ORCO'):
1007                         col.prop(tex, "use_map_to_bounds")
1008                 elif tex.texture_coords == 'OBJECT':
1009                     col.prop(tex, "use_from_original")
1010                     if (idblock.type == 'VOLUME'):
1011                         col.prop(tex, "use_map_to_bounds")
1012                 else:
1013                     col.label()
1014
1015                 col = split.column()
1016                 row = col.row()
1017                 row.prop(tex, "mapping_x", text="")
1018                 row.prop(tex, "mapping_y", text="")
1019                 row.prop(tex, "mapping_z", text="")
1020
1021             row = layout.row()
1022             row.column().prop(tex, "offset")
1023             row.column().prop(tex, "scale")
1024
1025
1026 class TEXTURE_PT_influence(TextureSlotPanel, Panel):
1027     bl_label = "Influence"
1028     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
1029
1030     @classmethod
1031     def poll(cls, context):
1032         idblock = context_tex_datablock(context)
1033         if isinstance(idblock, Brush):
1034             return False
1035
1036         if not getattr(context, "texture_slot", None):
1037             return False
1038
1039         engine = context.engine
1040         return (engine in cls.COMPAT_ENGINES)
1041
1042     def draw(self, context):
1043
1044         layout = self.layout
1045
1046         idblock = context_tex_datablock(context)
1047
1048         tex = context.texture_slot
1049
1050         def factor_but(layout, toggle, factor, name):
1051             row = layout.row(align=True)
1052             row.prop(tex, toggle, text="")
1053             sub = row.row(align=True)
1054             sub.active = getattr(tex, toggle)
1055             sub.prop(tex, factor, text=name, slider=True)
1056             return sub  # XXX, temp. use_map_normal needs to override.
1057
1058         if isinstance(idblock, Material):
1059             if idblock.type in {'SURFACE', 'WIRE'}:
1060                 split = layout.split()
1061
1062                 col = split.column()
1063                 col.label(text="Diffuse:")
1064                 factor_but(col, "use_map_diffuse", "diffuse_factor", "Intensity")
1065                 factor_but(col, "use_map_color_diffuse", "diffuse_color_factor", "Color")
1066                 factor_but(col, "use_map_alpha", "alpha_factor", "Alpha")
1067                 factor_but(col, "use_map_translucency", "translucency_factor", "Translucency")
1068
1069                 col.label(text="Specular:")
1070                 factor_but(col, "use_map_specular", "specular_factor", "Intensity")
1071                 factor_but(col, "use_map_color_spec", "specular_color_factor", "Color")
1072                 factor_but(col, "use_map_hardness", "hardness_factor", "Hardness")
1073
1074                 col = split.column()
1075                 col.label(text="Shading:")
1076                 factor_but(col, "use_map_ambient", "ambient_factor", "Ambient")
1077                 factor_but(col, "use_map_emit", "emit_factor", "Emit")
1078                 factor_but(col, "use_map_mirror", "mirror_factor", "Mirror")
1079                 factor_but(col, "use_map_raymir", "raymir_factor", "Ray Mirror")
1080
1081                 col.label(text="Geometry:")
1082                 # XXX replace 'or' when displacement is fixed to not rely on normal influence value.
1083                 sub_tmp = factor_but(col, "use_map_normal", "normal_factor", "Normal")
1084                 sub_tmp.active = (tex.use_map_normal or tex.use_map_displacement)
1085                 # END XXX
1086
1087                 factor_but(col, "use_map_warp", "warp_factor", "Warp")
1088                 factor_but(col, "use_map_displacement", "displacement_factor", "Displace")
1089
1090                 #~ sub = col.column()
1091                 #~ sub.active = tex.use_map_translucency or tex.map_emit or tex.map_alpha or tex.map_raymir or tex.map_hardness or tex.map_ambient or tex.map_specularity or tex.map_reflection or tex.map_mirror
1092                 #~ sub.prop(tex, "default_value", text="Amount", slider=True)
1093             elif idblock.type == 'HALO':
1094                 layout.label(text="Halo:")
1095
1096                 split = layout.split()
1097
1098                 col = split.column()
1099                 factor_but(col, "use_map_color_diffuse", "diffuse_color_factor", "Color")
1100                 factor_but(col, "use_map_alpha", "alpha_factor", "Alpha")
1101
1102                 col = split.column()
1103                 factor_but(col, "use_map_raymir", "raymir_factor", "Size")
1104                 factor_but(col, "use_map_hardness", "hardness_factor", "Hardness")
1105                 factor_but(col, "use_map_translucency", "translucency_factor", "Add")
1106             elif idblock.type == 'VOLUME':
1107                 layout.label(text="Volume:")
1108
1109                 split = layout.split()
1110
1111                 col = split.column()
1112                 factor_but(col, "use_map_density", "density_factor", "Density")
1113                 factor_but(col, "use_map_emission", "emission_factor", "Emission")
1114                 factor_but(col, "use_map_scatter", "scattering_factor", "Scattering")
1115                 factor_but(col, "use_map_reflect", "reflection_factor", "Reflection")
1116
1117                 col = split.column()
1118                 col.label(text=" ")
1119                 factor_but(col, "use_map_color_emission", "emission_color_factor", "Emission Color")
1120                 factor_but(col, "use_map_color_transmission", "transmission_color_factor", "Transmission Color")
1121                 factor_but(col, "use_map_color_reflection", "reflection_color_factor", "Reflection Color")
1122
1123                 layout.label(text="Geometry:")
1124
1125                 split = layout.split()
1126
1127                 col = split.column()
1128                 factor_but(col, "use_map_warp", "warp_factor", "Warp")
1129
1130                 col = split.column()
1131                 factor_but(col, "use_map_displacement", "displacement_factor", "Displace")
1132
1133         elif isinstance(idblock, Lamp):
1134             split = layout.split()
1135
1136             col = split.column()
1137             factor_but(col, "use_map_color", "color_factor", "Color")
1138
1139             col = split.column()
1140             factor_but(col, "use_map_shadow", "shadow_factor", "Shadow")
1141
1142         elif isinstance(idblock, World):
1143             split = layout.split()
1144
1145             col = split.column()
1146             factor_but(col, "use_map_blend", "blend_factor", "Blend")
1147             factor_but(col, "use_map_horizon", "horizon_factor", "Horizon")
1148
1149             col = split.column()
1150             factor_but(col, "use_map_zenith_up", "zenith_up_factor", "Zenith Up")
1151             factor_but(col, "use_map_zenith_down", "zenith_down_factor", "Zenith Down")
1152         elif isinstance(idblock, ParticleSettings):
1153             split = layout.split()
1154
1155             col = split.column()
1156             col.label(text="General:")
1157             factor_but(col, "use_map_time", "time_factor", "Time")
1158             factor_but(col, "use_map_life", "life_factor", "Lifetime")
1159             factor_but(col, "use_map_density", "density_factor", "Density")
1160             factor_but(col, "use_map_size", "size_factor", "Size")
1161
1162             col = split.column()
1163             col.label(text="Physics:")
1164             factor_but(col, "use_map_velocity", "velocity_factor", "Velocity")
1165             factor_but(col, "use_map_damp", "damp_factor", "Damp")
1166             factor_but(col, "use_map_gravity", "gravity_factor", "Gravity")
1167             factor_but(col, "use_map_field", "field_factor", "Force Fields")
1168
1169             layout.label(text="Hair:")
1170
1171             split = layout.split()
1172
1173             col = split.column()
1174             factor_but(col, "use_map_length", "length_factor", "Length")
1175             factor_but(col, "use_map_clump", "clump_factor", "Clump")
1176             factor_but(col, "use_map_twist", "twist_factor", "Twist")
1177
1178             col = split.column()
1179             factor_but(col, "use_map_kink_amp", "kink_amp_factor", "Kink Amplitude")
1180             factor_but(col, "use_map_kink_freq", "kink_freq_factor", "Kink Frequency")
1181             factor_but(col, "use_map_rough", "rough_factor", "Rough")
1182
1183         elif isinstance(idblock, FreestyleLineStyle):
1184             split = layout.split()
1185
1186             col = split.column()
1187             factor_but(col, "use_map_color_diffuse", "diffuse_color_factor", "Color")
1188             col = split.column()
1189             factor_but(col, "use_map_alpha", "alpha_factor", "Alpha")
1190
1191         layout.separator()
1192
1193         if not isinstance(idblock, ParticleSettings):
1194             split = layout.split()
1195
1196             col = split.column()
1197             col.prop(tex, "blend_type", text="Blend")
1198             col.prop(tex, "use_rgb_to_intensity")
1199             # color is used on gray-scale textures even when use_rgb_to_intensity is disabled.
1200             col.prop(tex, "color", text="")
1201
1202             col = split.column()
1203             col.prop(tex, "invert", text="Negative")
1204             col.prop(tex, "use_stencil")
1205
1206         if isinstance(idblock, Material) or isinstance(idblock, World):
1207             col.prop(tex, "default_value", text="DVar", slider=True)
1208
1209         if isinstance(idblock, Material):
1210             layout.label(text="Bump Mapping:")
1211
1212             # only show bump settings if activated but not for normal-map images
1213             row = layout.row()
1214
1215             sub = row.row()
1216             sub.active = (
1217                 (tex.use_map_normal or tex.use_map_warp) and
1218                 not (tex.texture.type == 'IMAGE' and
1219                      (tex.texture.use_normal_map or tex.texture.use_derivative_map))
1220             )
1221             sub.prop(tex, "bump_method", text="Method")
1222
1223             # the space setting is supported for: derivative-maps + bump-maps
1224             # (DEFAULT,BEST_QUALITY), not for normal-maps
1225             sub = row.row()
1226             sub.active = (
1227                 (tex.use_map_normal or tex.use_map_warp) and
1228                 not (tex.texture.type == 'IMAGE' and tex.texture.use_normal_map) and
1229                 ((tex.bump_method in {'BUMP_LOW_QUALITY', 'BUMP_MEDIUM_QUALITY', 'BUMP_BEST_QUALITY'}) or
1230                  (tex.texture.type == 'IMAGE' and tex.texture.use_derivative_map))
1231             )
1232             sub.prop(tex, "bump_objectspace", text="Space")
1233
1234
1235 class TEXTURE_PT_custom_props(TextureButtonsPanel, PropertyPanel, Panel):
1236     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
1237     _context_path = "texture"
1238     _property_type = Texture
1239
1240
1241 classes = (
1242     TEXTURE_MT_specials,
1243     TEXTURE_MT_envmap_specials,
1244     TEXTURE_UL_texslots,
1245     TEXTURE_PT_context_texture,
1246     TEXTURE_PT_preview,
1247     TEXTURE_PT_colors,
1248     TEXTURE_PT_clouds,
1249     TEXTURE_PT_wood,
1250     TEXTURE_PT_marble,
1251     TEXTURE_PT_magic,
1252     TEXTURE_PT_blend,
1253     TEXTURE_PT_stucci,
1254     TEXTURE_PT_image,
1255     TEXTURE_PT_image_sampling,
1256     TEXTURE_PT_image_mapping,
1257     TEXTURE_PT_envmap,
1258     TEXTURE_PT_envmap_sampling,
1259     TEXTURE_PT_musgrave,
1260     TEXTURE_PT_voronoi,
1261     TEXTURE_PT_distortednoise,
1262     TEXTURE_PT_voxeldata,
1263     TEXTURE_PT_pointdensity,
1264     TEXTURE_PT_pointdensity_turbulence,
1265     TEXTURE_PT_ocean,
1266     TEXTURE_PT_mapping,
1267     TEXTURE_PT_influence,
1268     TEXTURE_PT_custom_props,
1269 )
1270
1271 if __name__ == "__main__":  # only for live edit.
1272     from bpy.utils import register_class
1273     for cls in classes:
1274         register_class(cls)