78ea4fa6c3ff42bf28b5462f87becdfa1021e0c3
[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 == '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         col.prop(tex, "noise_intensity", text="Intensity")
680         if musgrave_type in {'RIDGED_MULTIFRACTAL', 'HYBRID_MULTIFRACTAL'}:
681             col.prop(tex, "gain")
682
683         layout.label(text="Noise:")
684
685         layout.prop(tex, "noise_basis", text="Basis")
686
687         row = layout.row()
688         row.prop(tex, "noise_scale", text="Size")
689         row.prop(tex, "nabla")
690
691
692 class TEXTURE_PT_voronoi(TextureTypePanel, Panel):
693     bl_label = "Voronoi"
694     tex_type = 'VORONOI'
695     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
696
697     def draw(self, context):
698         layout = self.layout
699
700         tex = context.texture
701
702         split = layout.split()
703
704         col = split.column()
705         col.label(text="Distance Metric:")
706         col.prop(tex, "distance_metric", text="")
707         sub = col.column()
708         sub.active = tex.distance_metric == 'MINKOVSKY'
709         sub.prop(tex, "minkovsky_exponent", text="Exponent")
710         col.label(text="Coloring:")
711         col.prop(tex, "color_mode", text="")
712         col.prop(tex, "noise_intensity", text="Intensity")
713
714         col = split.column()
715         sub = col.column(align=True)
716         sub.label(text="Feature Weights:")
717         sub.prop(tex, "weight_1", text="1", slider=True)
718         sub.prop(tex, "weight_2", text="2", slider=True)
719         sub.prop(tex, "weight_3", text="3", slider=True)
720         sub.prop(tex, "weight_4", text="4", slider=True)
721
722         layout.label(text="Noise:")
723         row = layout.row()
724         row.prop(tex, "noise_scale", text="Size")
725         row.prop(tex, "nabla")
726
727
728 class TEXTURE_PT_distortednoise(TextureTypePanel, Panel):
729     bl_label = "Distorted Noise"
730     tex_type = 'DISTORTED_NOISE'
731     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
732
733     def draw(self, context):
734         layout = self.layout
735
736         tex = context.texture
737
738         layout.prop(tex, "noise_distortion")
739         layout.prop(tex, "noise_basis", text="Basis")
740
741         split = layout.split()
742
743         col = split.column()
744         col.prop(tex, "distortion", text="Distortion")
745         col.prop(tex, "noise_scale", text="Size")
746
747         split.prop(tex, "nabla")
748
749
750 class TEXTURE_PT_voxeldata(TextureButtonsPanel, Panel):
751     bl_label = "Voxel Data"
752     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
753
754     @classmethod
755     def poll(cls, context):
756         tex = context.texture
757         engine = context.scene.render.engine
758         return tex and (tex.type == 'VOXEL_DATA' and (engine in cls.COMPAT_ENGINES))
759
760     def draw(self, context):
761         layout = self.layout
762
763         tex = context.texture
764         vd = tex.voxel_data
765
766         layout.prop(vd, "file_format")
767         if vd.file_format in {'BLENDER_VOXEL', 'RAW_8BIT'}:
768             layout.prop(vd, "filepath")
769         if vd.file_format == 'RAW_8BIT':
770             layout.prop(vd, "resolution")
771         elif vd.file_format == 'SMOKE':
772             layout.prop(vd, "domain_object")
773             layout.prop(vd, "smoke_data_type")
774         elif vd.file_format == 'HAIR':
775             layout.prop(vd, "domain_object")
776             layout.prop(vd, "hair_data_type")
777         elif vd.file_format == 'IMAGE_SEQUENCE':
778             layout.template_ID(tex, "image", open="image.open")
779             layout.template_image(tex, "image", tex.image_user, compact=True)
780             #layout.prop(vd, "frame_duration")
781
782         if vd.file_format in {'BLENDER_VOXEL', 'RAW_8BIT'}:
783             layout.prop(vd, "use_still_frame")
784             row = layout.row()
785             row.active = vd.use_still_frame
786             row.prop(vd, "still_frame")
787
788         layout.prop(vd, "interpolation")
789         layout.prop(vd, "extension")
790         layout.prop(vd, "intensity")
791
792
793 class TEXTURE_PT_pointdensity(TextureButtonsPanel, Panel):
794     bl_label = "Point Density"
795     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
796
797     @classmethod
798     def poll(cls, context):
799         tex = context.texture
800         engine = context.scene.render.engine
801         return tex and (tex.type == 'POINT_DENSITY' and (engine in cls.COMPAT_ENGINES))
802
803     def draw(self, context):
804         layout = self.layout
805
806         tex = context.texture
807         pd = tex.point_density
808
809         layout.prop(pd, "point_source", expand=True)
810
811         split = layout.split()
812
813         col = split.column()
814         if pd.point_source == 'PARTICLE_SYSTEM':
815             col.label(text="Object:")
816             col.prop(pd, "object", text="")
817
818             sub = col.column()
819             sub.enabled = bool(pd.object)
820             if pd.object:
821                 sub.label(text="System:")
822                 sub.prop_search(pd, "particle_system", pd.object, "particle_systems", text="")
823             sub.label(text="Cache:")
824             sub.prop(pd, "particle_cache_space", text="")
825         else:
826             col.label(text="Object:")
827             col.prop(pd, "object", text="")
828             col.label(text="Cache:")
829             col.prop(pd, "vertex_cache_space", text="")
830
831         col.separator()
832
833         if pd.point_source == 'PARTICLE_SYSTEM':
834             col.label(text="Color Source:")
835             col.prop(pd, "color_source", text="")
836             if pd.color_source in {'PARTICLE_SPEED', 'PARTICLE_VELOCITY'}:
837                 col.prop(pd, "speed_scale")
838             if pd.color_source in {'PARTICLE_SPEED', 'PARTICLE_AGE'}:
839                 layout.template_color_ramp(pd, "color_ramp", expand=True)
840
841         col = split.column()
842         col.label()
843         col.prop(pd, "radius")
844         col.label(text="Falloff:")
845         col.prop(pd, "falloff", text="")
846         if pd.falloff == 'SOFT':
847             col.prop(pd, "falloff_soft")
848         if pd.falloff == 'PARTICLE_VELOCITY':
849             col.prop(pd, "falloff_speed_scale")
850
851         col.prop(pd, "use_falloff_curve")
852
853         if pd.use_falloff_curve:
854             col = layout.column()
855             col.label(text="Falloff Curve")
856             col.template_curve_mapping(pd, "falloff_curve", brush=False)
857
858
859 class TEXTURE_PT_pointdensity_turbulence(TextureButtonsPanel, Panel):
860     bl_label = "Turbulence"
861     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
862
863     @classmethod
864     def poll(cls, context):
865         tex = context.texture
866         engine = context.scene.render.engine
867         return tex and (tex.type == 'POINT_DENSITY' and (engine in cls.COMPAT_ENGINES))
868
869     def draw_header(self, context):
870         pd = context.texture.point_density
871
872         self.layout.prop(pd, "use_turbulence", text="")
873
874     def draw(self, context):
875         layout = self.layout
876
877         tex = context.texture
878         pd = tex.point_density
879         layout.active = pd.use_turbulence
880
881         split = layout.split()
882
883         col = split.column()
884         col.label(text="Influence:")
885         col.prop(pd, "turbulence_influence", text="")
886         col.label(text="Noise Basis:")
887         col.prop(pd, "noise_basis", text="")
888
889         col = split.column()
890         col.label()
891         col.prop(pd, "turbulence_scale")
892         col.prop(pd, "turbulence_depth")
893         col.prop(pd, "turbulence_strength")
894
895
896 class TEXTURE_PT_ocean(TextureTypePanel, Panel):
897     bl_label = "Ocean"
898     tex_type = 'OCEAN'
899     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
900
901     def draw(self, context):
902         layout = self.layout
903
904         tex = context.texture
905         ot = tex.ocean
906
907         col = layout.column()
908         col.prop(ot, "ocean_object")
909         col.prop(ot, "output")
910
911
912 class TEXTURE_PT_mapping(TextureSlotPanel, Panel):
913     bl_label = "Mapping"
914     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
915
916     @classmethod
917     def poll(cls, context):
918         idblock = context_tex_datablock(context)
919         if isinstance(idblock, Brush) and not context.sculpt_object:
920             return False
921
922         if not getattr(context, "texture_slot", None):
923             return False
924
925         engine = context.scene.render.engine
926         return (engine in cls.COMPAT_ENGINES)
927
928     def draw(self, context):
929         layout = self.layout
930
931         idblock = context_tex_datablock(context)
932
933         tex = context.texture_slot
934
935         if not isinstance(idblock, Brush):
936             split = layout.split(percentage=0.3)
937             col = split.column()
938             col.label(text="Coordinates:")
939             col = split.column()
940             col.prop(tex, "texture_coords", text="")
941
942             if tex.texture_coords == 'ORCO':
943                 """
944                 ob = context.object
945                 if ob and ob.type == 'MESH':
946                     split = layout.split(percentage=0.3)
947                     split.label(text="Mesh:")
948                     split.prop(ob.data, "texco_mesh", text="")
949                 """
950             elif tex.texture_coords == 'UV':
951                 split = layout.split(percentage=0.3)
952                 split.label(text="Map:")
953                 ob = context.object
954                 if ob and ob.type == 'MESH':
955                     split.prop_search(tex, "uv_layer", ob.data, "uv_textures", text="")
956                 else:
957                     split.prop(tex, "uv_layer", text="")
958
959             elif tex.texture_coords == 'OBJECT':
960                 split = layout.split(percentage=0.3)
961                 split.label(text="Object:")
962                 split.prop(tex, "object", text="")
963
964             elif tex.texture_coords == 'ALONG_STROKE':
965                 split = layout.split(percentage=0.3)
966                 split.label(text="Use Tips:")
967                 split.prop(tex, "use_tips", text="")
968
969         if isinstance(idblock, Brush):
970             if context.sculpt_object or context.image_paint_object:
971                 brush_texture_settings(layout, idblock, context.sculpt_object)
972         else:
973             if isinstance(idblock, FreestyleLineStyle):
974                 split = layout.split(percentage=0.3)
975                 split.label(text="Projection:")
976                 split.prop(tex, "mapping", text="")
977
978                 split = layout.split(percentage=0.3)
979                 split.separator()
980                 row = split.row()
981                 row.prop(tex, "mapping_x", text="")
982                 row.prop(tex, "mapping_y", text="")
983                 row.prop(tex, "mapping_z", text="")
984
985             elif isinstance(idblock, Material):
986                 split = layout.split(percentage=0.3)
987                 split.label(text="Projection:")
988                 split.prop(tex, "mapping", text="")
989
990                 split = layout.split()
991
992                 col = split.column()
993                 if tex.texture_coords in {'ORCO', 'UV'}:
994                     col.prop(tex, "use_from_dupli")
995                     if (idblock.type == 'VOLUME' and tex.texture_coords == 'ORCO'):
996                         col.prop(tex, "use_map_to_bounds")
997                 elif tex.texture_coords == 'OBJECT':
998                     col.prop(tex, "use_from_original")
999                     if (idblock.type == 'VOLUME'):
1000                         col.prop(tex, "use_map_to_bounds")
1001                 else:
1002                     col.label()
1003
1004                 col = split.column()
1005                 row = col.row()
1006                 row.prop(tex, "mapping_x", text="")
1007                 row.prop(tex, "mapping_y", text="")
1008                 row.prop(tex, "mapping_z", text="")
1009
1010             row = layout.row()
1011             row.column().prop(tex, "offset")
1012             row.column().prop(tex, "scale")
1013
1014
1015 class TEXTURE_PT_influence(TextureSlotPanel, Panel):
1016     bl_label = "Influence"
1017     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
1018
1019     @classmethod
1020     def poll(cls, context):
1021         idblock = context_tex_datablock(context)
1022         if isinstance(idblock, Brush):
1023             return False
1024
1025         if not getattr(context, "texture_slot", None):
1026             return False
1027
1028         engine = context.scene.render.engine
1029         return (engine in cls.COMPAT_ENGINES)
1030
1031     def draw(self, context):
1032
1033         layout = self.layout
1034
1035         idblock = context_tex_datablock(context)
1036
1037         tex = context.texture_slot
1038
1039         def factor_but(layout, toggle, factor, name):
1040             row = layout.row(align=True)
1041             row.prop(tex, toggle, text="")
1042             sub = row.row(align=True)
1043             sub.active = getattr(tex, toggle)
1044             sub.prop(tex, factor, text=name, slider=True)
1045             return sub  # XXX, temp. use_map_normal needs to override.
1046
1047         if isinstance(idblock, Material):
1048             if idblock.type in {'SURFACE', 'WIRE'}:
1049                 split = layout.split()
1050
1051                 col = split.column()
1052                 col.label(text="Diffuse:")
1053                 factor_but(col, "use_map_diffuse", "diffuse_factor", "Intensity")
1054                 factor_but(col, "use_map_color_diffuse", "diffuse_color_factor", "Color")
1055                 factor_but(col, "use_map_alpha", "alpha_factor", "Alpha")
1056                 factor_but(col, "use_map_translucency", "translucency_factor", "Translucency")
1057
1058                 col.label(text="Specular:")
1059                 factor_but(col, "use_map_specular", "specular_factor", "Intensity")
1060                 factor_but(col, "use_map_color_spec", "specular_color_factor", "Color")
1061                 factor_but(col, "use_map_hardness", "hardness_factor", "Hardness")
1062
1063                 col = split.column()
1064                 col.label(text="Shading:")
1065                 factor_but(col, "use_map_ambient", "ambient_factor", "Ambient")
1066                 factor_but(col, "use_map_emit", "emit_factor", "Emit")
1067                 factor_but(col, "use_map_mirror", "mirror_factor", "Mirror")
1068                 factor_but(col, "use_map_raymir", "raymir_factor", "Ray Mirror")
1069
1070                 col.label(text="Geometry:")
1071                 # XXX replace 'or' when displacement is fixed to not rely on normal influence value.
1072                 sub_tmp = factor_but(col, "use_map_normal", "normal_factor", "Normal")
1073                 sub_tmp.active = (tex.use_map_normal or tex.use_map_displacement)
1074                 # END XXX
1075
1076                 factor_but(col, "use_map_warp", "warp_factor", "Warp")
1077                 factor_but(col, "use_map_displacement", "displacement_factor", "Displace")
1078
1079                 #~ sub = col.column()
1080                 #~ 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
1081                 #~ sub.prop(tex, "default_value", text="Amount", slider=True)
1082             elif idblock.type == 'HALO':
1083                 layout.label(text="Halo:")
1084
1085                 split = layout.split()
1086
1087                 col = split.column()
1088                 factor_but(col, "use_map_color_diffuse", "diffuse_color_factor", "Color")
1089                 factor_but(col, "use_map_alpha", "alpha_factor", "Alpha")
1090
1091                 col = split.column()
1092                 factor_but(col, "use_map_raymir", "raymir_factor", "Size")
1093                 factor_but(col, "use_map_hardness", "hardness_factor", "Hardness")
1094                 factor_but(col, "use_map_translucency", "translucency_factor", "Add")
1095             elif idblock.type == 'VOLUME':
1096                 layout.label(text="Volume:")
1097
1098                 split = layout.split()
1099
1100                 col = split.column()
1101                 factor_but(col, "use_map_density", "density_factor", "Density")
1102                 factor_but(col, "use_map_emission", "emission_factor", "Emission")
1103                 factor_but(col, "use_map_scatter", "scattering_factor", "Scattering")
1104                 factor_but(col, "use_map_reflect", "reflection_factor", "Reflection")
1105
1106                 col = split.column()
1107                 col.label(text=" ")
1108                 factor_but(col, "use_map_color_emission", "emission_color_factor", "Emission Color")
1109                 factor_but(col, "use_map_color_transmission", "transmission_color_factor", "Transmission Color")
1110                 factor_but(col, "use_map_color_reflection", "reflection_color_factor", "Reflection Color")
1111
1112                 layout.label(text="Geometry:")
1113
1114                 split = layout.split()
1115
1116                 col = split.column()
1117                 factor_but(col, "use_map_warp", "warp_factor", "Warp")
1118
1119                 col = split.column()
1120                 factor_but(col, "use_map_displacement", "displacement_factor", "Displace")
1121
1122         elif isinstance(idblock, Lamp):
1123             split = layout.split()
1124
1125             col = split.column()
1126             factor_but(col, "use_map_color", "color_factor", "Color")
1127
1128             col = split.column()
1129             factor_but(col, "use_map_shadow", "shadow_factor", "Shadow")
1130
1131         elif isinstance(idblock, World):
1132             split = layout.split()
1133
1134             col = split.column()
1135             factor_but(col, "use_map_blend", "blend_factor", "Blend")
1136             factor_but(col, "use_map_horizon", "horizon_factor", "Horizon")
1137
1138             col = split.column()
1139             factor_but(col, "use_map_zenith_up", "zenith_up_factor", "Zenith Up")
1140             factor_but(col, "use_map_zenith_down", "zenith_down_factor", "Zenith Down")
1141         elif isinstance(idblock, ParticleSettings):
1142             split = layout.split()
1143
1144             col = split.column()
1145             col.label(text="General:")
1146             factor_but(col, "use_map_time", "time_factor", "Time")
1147             factor_but(col, "use_map_life", "life_factor", "Lifetime")
1148             factor_but(col, "use_map_density", "density_factor", "Density")
1149             factor_but(col, "use_map_size", "size_factor", "Size")
1150
1151             col = split.column()
1152             col.label(text="Physics:")
1153             factor_but(col, "use_map_velocity", "velocity_factor", "Velocity")
1154             factor_but(col, "use_map_damp", "damp_factor", "Damp")
1155             factor_but(col, "use_map_gravity", "gravity_factor", "Gravity")
1156             factor_but(col, "use_map_field", "field_factor", "Force Fields")
1157
1158             layout.label(text="Hair:")
1159
1160             split = layout.split()
1161
1162             col = split.column()
1163             factor_but(col, "use_map_length", "length_factor", "Length")
1164             factor_but(col, "use_map_clump", "clump_factor", "Clump")
1165
1166             col = split.column()
1167             factor_but(col, "use_map_kink_amp", "kink_amp_factor", "Kink Amplitude")
1168             factor_but(col, "use_map_kink_freq", "kink_freq_factor", "Kink Frequency")
1169             factor_but(col, "use_map_rough", "rough_factor", "Rough")
1170
1171         elif isinstance(idblock, FreestyleLineStyle):
1172             split = layout.split()
1173
1174             col = split.column()
1175             factor_but(col, "use_map_color_diffuse", "diffuse_color_factor", "Color")
1176             col = split.column()
1177             factor_but(col, "use_map_alpha", "alpha_factor", "Alpha")
1178
1179         layout.separator()
1180
1181         if not isinstance(idblock, ParticleSettings):
1182             split = layout.split()
1183
1184             col = split.column()
1185             col.prop(tex, "blend_type", text="Blend")
1186             col.prop(tex, "use_rgb_to_intensity")
1187             # color is used on gray-scale textures even when use_rgb_to_intensity is disabled.
1188             col.prop(tex, "color", text="")
1189
1190             col = split.column()
1191             col.prop(tex, "invert", text="Negative")
1192             col.prop(tex, "use_stencil")
1193
1194         if isinstance(idblock, Material) or isinstance(idblock, World):
1195             col.prop(tex, "default_value", text="DVar", slider=True)
1196
1197         if isinstance(idblock, Material):
1198             layout.label(text="Bump Mapping:")
1199
1200             # only show bump settings if activated but not for normal-map images
1201             row = layout.row()
1202
1203             sub = row.row()
1204             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))
1205             sub.prop(tex, "bump_method", text="Method")
1206
1207             # the space setting is supported for: derivative-maps + bump-maps (DEFAULT,BEST_QUALITY), not for normal-maps
1208             sub = row.row()
1209             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))
1210             sub.prop(tex, "bump_objectspace", text="Space")
1211
1212
1213 class TEXTURE_PT_custom_props(TextureButtonsPanel, PropertyPanel, Panel):
1214     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
1215     _context_path = "texture"
1216     _property_type = Texture
1217
1218 if __name__ == "__main__":  # only for live edit.
1219     bpy.utils.register_module(__name__)