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