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