Moving classes to separate listing broke panel order
[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         col.label(text="Color Source:")
834         if pd.point_source == 'PARTICLE_SYSTEM':
835             col.prop(pd, "particle_color_source", text="")
836             if pd.particle_color_source in {'PARTICLE_SPEED', 'PARTICLE_VELOCITY'}:
837                 col.prop(pd, "speed_scale")
838             if pd.particle_color_source in {'PARTICLE_SPEED', 'PARTICLE_AGE'}:
839                 layout.template_color_ramp(pd, "color_ramp", expand=True)
840         else:
841             col.prop(pd, "vertex_color_source", text="")
842             if pd.vertex_color_source == 'VERTEX_COLOR':
843                 if pd.object and pd.object.data:
844                     col.prop_search(pd, "vertex_attribute_name", pd.object.data, "vertex_colors", text="")
845             if pd.vertex_color_source == 'VERTEX_WEIGHT':
846                 if pd.object:
847                     col.prop_search(pd, "vertex_attribute_name", pd.object, "vertex_groups", text="")
848                 layout.template_color_ramp(pd, "color_ramp", expand=True)
849
850         col = split.column()
851         col.label()
852         col.prop(pd, "radius")
853         col.label(text="Falloff:")
854         col.prop(pd, "falloff", text="")
855         if pd.falloff == 'SOFT':
856             col.prop(pd, "falloff_soft")
857         if pd.falloff == 'PARTICLE_VELOCITY':
858             col.prop(pd, "falloff_speed_scale")
859
860         col.prop(pd, "use_falloff_curve")
861
862         if pd.use_falloff_curve:
863             col = layout.column()
864             col.label(text="Falloff Curve")
865             col.template_curve_mapping(pd, "falloff_curve", brush=False)
866
867
868 class TEXTURE_PT_pointdensity_turbulence(TextureButtonsPanel, Panel):
869     bl_label = "Turbulence"
870     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
871
872     @classmethod
873     def poll(cls, context):
874         tex = context.texture
875         engine = context.scene.render.engine
876         return tex and (tex.type == 'POINT_DENSITY' and (engine in cls.COMPAT_ENGINES))
877
878     def draw_header(self, context):
879         pd = context.texture.point_density
880
881         self.layout.prop(pd, "use_turbulence", text="")
882
883     def draw(self, context):
884         layout = self.layout
885
886         tex = context.texture
887         pd = tex.point_density
888         layout.active = pd.use_turbulence
889
890         split = layout.split()
891
892         col = split.column()
893         col.label(text="Influence:")
894         col.prop(pd, "turbulence_influence", text="")
895         col.label(text="Noise Basis:")
896         col.prop(pd, "noise_basis", text="")
897
898         col = split.column()
899         col.label()
900         col.prop(pd, "turbulence_scale")
901         col.prop(pd, "turbulence_depth")
902         col.prop(pd, "turbulence_strength")
903
904
905 class TEXTURE_PT_ocean(TextureTypePanel, Panel):
906     bl_label = "Ocean"
907     tex_type = 'OCEAN'
908     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
909
910     def draw(self, context):
911         layout = self.layout
912
913         tex = context.texture
914         ot = tex.ocean
915
916         col = layout.column()
917         col.prop(ot, "ocean_object")
918         col.prop(ot, "output")
919
920
921 class TEXTURE_PT_mapping(TextureSlotPanel, Panel):
922     bl_label = "Mapping"
923     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
924
925     @classmethod
926     def poll(cls, context):
927         idblock = context_tex_datablock(context)
928         if isinstance(idblock, Brush) and not context.sculpt_object:
929             return False
930
931         if not getattr(context, "texture_slot", None):
932             return False
933
934         engine = context.scene.render.engine
935         return (engine in cls.COMPAT_ENGINES)
936
937     def draw(self, context):
938         layout = self.layout
939
940         idblock = context_tex_datablock(context)
941
942         tex = context.texture_slot
943
944         if not isinstance(idblock, Brush):
945             split = layout.split(percentage=0.3)
946             col = split.column()
947             col.label(text="Coordinates:")
948             col = split.column()
949             col.prop(tex, "texture_coords", text="")
950
951             if tex.texture_coords == 'ORCO':
952                 """
953                 ob = context.object
954                 if ob and ob.type == 'MESH':
955                     split = layout.split(percentage=0.3)
956                     split.label(text="Mesh:")
957                     split.prop(ob.data, "texco_mesh", text="")
958                 """
959             elif tex.texture_coords == 'UV':
960                 split = layout.split(percentage=0.3)
961                 split.label(text="Map:")
962                 ob = context.object
963                 if ob and ob.type == 'MESH':
964                     split.prop_search(tex, "uv_layer", ob.data, "uv_textures", text="")
965                 else:
966                     split.prop(tex, "uv_layer", text="")
967
968             elif tex.texture_coords == 'OBJECT':
969                 split = layout.split(percentage=0.3)
970                 split.label(text="Object:")
971                 split.prop(tex, "object", text="")
972
973             elif tex.texture_coords == 'ALONG_STROKE':
974                 split = layout.split(percentage=0.3)
975                 split.label(text="Use Tips:")
976                 split.prop(tex, "use_tips", text="")
977
978         if isinstance(idblock, Brush):
979             if context.sculpt_object or context.image_paint_object:
980                 brush_texture_settings(layout, idblock, context.sculpt_object)
981         else:
982             if isinstance(idblock, FreestyleLineStyle):
983                 split = layout.split(percentage=0.3)
984                 split.label(text="Projection:")
985                 split.prop(tex, "mapping", text="")
986
987                 split = layout.split(percentage=0.3)
988                 split.separator()
989                 row = split.row()
990                 row.prop(tex, "mapping_x", text="")
991                 row.prop(tex, "mapping_y", text="")
992                 row.prop(tex, "mapping_z", text="")
993
994             elif isinstance(idblock, Material):
995                 split = layout.split(percentage=0.3)
996                 split.label(text="Projection:")
997                 split.prop(tex, "mapping", text="")
998
999                 split = layout.split()
1000
1001                 col = split.column()
1002                 if tex.texture_coords in {'ORCO', 'UV'}:
1003                     col.prop(tex, "use_from_dupli")
1004                     if (idblock.type == 'VOLUME' and tex.texture_coords == 'ORCO'):
1005                         col.prop(tex, "use_map_to_bounds")
1006                 elif tex.texture_coords == 'OBJECT':
1007                     col.prop(tex, "use_from_original")
1008                     if (idblock.type == 'VOLUME'):
1009                         col.prop(tex, "use_map_to_bounds")
1010                 else:
1011                     col.label()
1012
1013                 col = split.column()
1014                 row = col.row()
1015                 row.prop(tex, "mapping_x", text="")
1016                 row.prop(tex, "mapping_y", text="")
1017                 row.prop(tex, "mapping_z", text="")
1018
1019             row = layout.row()
1020             row.column().prop(tex, "offset")
1021             row.column().prop(tex, "scale")
1022
1023
1024 class TEXTURE_PT_influence(TextureSlotPanel, Panel):
1025     bl_label = "Influence"
1026     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
1027
1028     @classmethod
1029     def poll(cls, context):
1030         idblock = context_tex_datablock(context)
1031         if isinstance(idblock, Brush):
1032             return False
1033
1034         if not getattr(context, "texture_slot", None):
1035             return False
1036
1037         engine = context.scene.render.engine
1038         return (engine in cls.COMPAT_ENGINES)
1039
1040     def draw(self, context):
1041
1042         layout = self.layout
1043
1044         idblock = context_tex_datablock(context)
1045
1046         tex = context.texture_slot
1047
1048         def factor_but(layout, toggle, factor, name):
1049             row = layout.row(align=True)
1050             row.prop(tex, toggle, text="")
1051             sub = row.row(align=True)
1052             sub.active = getattr(tex, toggle)
1053             sub.prop(tex, factor, text=name, slider=True)
1054             return sub  # XXX, temp. use_map_normal needs to override.
1055
1056         if isinstance(idblock, Material):
1057             if idblock.type in {'SURFACE', 'WIRE'}:
1058                 split = layout.split()
1059
1060                 col = split.column()
1061                 col.label(text="Diffuse:")
1062                 factor_but(col, "use_map_diffuse", "diffuse_factor", "Intensity")
1063                 factor_but(col, "use_map_color_diffuse", "diffuse_color_factor", "Color")
1064                 factor_but(col, "use_map_alpha", "alpha_factor", "Alpha")
1065                 factor_but(col, "use_map_translucency", "translucency_factor", "Translucency")
1066
1067                 col.label(text="Specular:")
1068                 factor_but(col, "use_map_specular", "specular_factor", "Intensity")
1069                 factor_but(col, "use_map_color_spec", "specular_color_factor", "Color")
1070                 factor_but(col, "use_map_hardness", "hardness_factor", "Hardness")
1071
1072                 col = split.column()
1073                 col.label(text="Shading:")
1074                 factor_but(col, "use_map_ambient", "ambient_factor", "Ambient")
1075                 factor_but(col, "use_map_emit", "emit_factor", "Emit")
1076                 factor_but(col, "use_map_mirror", "mirror_factor", "Mirror")
1077                 factor_but(col, "use_map_raymir", "raymir_factor", "Ray Mirror")
1078
1079                 col.label(text="Geometry:")
1080                 # XXX replace 'or' when displacement is fixed to not rely on normal influence value.
1081                 sub_tmp = factor_but(col, "use_map_normal", "normal_factor", "Normal")
1082                 sub_tmp.active = (tex.use_map_normal or tex.use_map_displacement)
1083                 # END XXX
1084
1085                 factor_but(col, "use_map_warp", "warp_factor", "Warp")
1086                 factor_but(col, "use_map_displacement", "displacement_factor", "Displace")
1087
1088                 #~ sub = col.column()
1089                 #~ 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
1090                 #~ sub.prop(tex, "default_value", text="Amount", slider=True)
1091             elif idblock.type == 'HALO':
1092                 layout.label(text="Halo:")
1093
1094                 split = layout.split()
1095
1096                 col = split.column()
1097                 factor_but(col, "use_map_color_diffuse", "diffuse_color_factor", "Color")
1098                 factor_but(col, "use_map_alpha", "alpha_factor", "Alpha")
1099
1100                 col = split.column()
1101                 factor_but(col, "use_map_raymir", "raymir_factor", "Size")
1102                 factor_but(col, "use_map_hardness", "hardness_factor", "Hardness")
1103                 factor_but(col, "use_map_translucency", "translucency_factor", "Add")
1104             elif idblock.type == 'VOLUME':
1105                 layout.label(text="Volume:")
1106
1107                 split = layout.split()
1108
1109                 col = split.column()
1110                 factor_but(col, "use_map_density", "density_factor", "Density")
1111                 factor_but(col, "use_map_emission", "emission_factor", "Emission")
1112                 factor_but(col, "use_map_scatter", "scattering_factor", "Scattering")
1113                 factor_but(col, "use_map_reflect", "reflection_factor", "Reflection")
1114
1115                 col = split.column()
1116                 col.label(text=" ")
1117                 factor_but(col, "use_map_color_emission", "emission_color_factor", "Emission Color")
1118                 factor_but(col, "use_map_color_transmission", "transmission_color_factor", "Transmission Color")
1119                 factor_but(col, "use_map_color_reflection", "reflection_color_factor", "Reflection Color")
1120
1121                 layout.label(text="Geometry:")
1122
1123                 split = layout.split()
1124
1125                 col = split.column()
1126                 factor_but(col, "use_map_warp", "warp_factor", "Warp")
1127
1128                 col = split.column()
1129                 factor_but(col, "use_map_displacement", "displacement_factor", "Displace")
1130
1131         elif isinstance(idblock, Lamp):
1132             split = layout.split()
1133
1134             col = split.column()
1135             factor_but(col, "use_map_color", "color_factor", "Color")
1136
1137             col = split.column()
1138             factor_but(col, "use_map_shadow", "shadow_factor", "Shadow")
1139
1140         elif isinstance(idblock, World):
1141             split = layout.split()
1142
1143             col = split.column()
1144             factor_but(col, "use_map_blend", "blend_factor", "Blend")
1145             factor_but(col, "use_map_horizon", "horizon_factor", "Horizon")
1146
1147             col = split.column()
1148             factor_but(col, "use_map_zenith_up", "zenith_up_factor", "Zenith Up")
1149             factor_but(col, "use_map_zenith_down", "zenith_down_factor", "Zenith Down")
1150         elif isinstance(idblock, ParticleSettings):
1151             split = layout.split()
1152
1153             col = split.column()
1154             col.label(text="General:")
1155             factor_but(col, "use_map_time", "time_factor", "Time")
1156             factor_but(col, "use_map_life", "life_factor", "Lifetime")
1157             factor_but(col, "use_map_density", "density_factor", "Density")
1158             factor_but(col, "use_map_size", "size_factor", "Size")
1159
1160             col = split.column()
1161             col.label(text="Physics:")
1162             factor_but(col, "use_map_velocity", "velocity_factor", "Velocity")
1163             factor_but(col, "use_map_damp", "damp_factor", "Damp")
1164             factor_but(col, "use_map_gravity", "gravity_factor", "Gravity")
1165             factor_but(col, "use_map_field", "field_factor", "Force Fields")
1166
1167             layout.label(text="Hair:")
1168
1169             split = layout.split()
1170
1171             col = split.column()
1172             factor_but(col, "use_map_length", "length_factor", "Length")
1173             factor_but(col, "use_map_clump", "clump_factor", "Clump")
1174
1175             col = split.column()
1176             factor_but(col, "use_map_kink_amp", "kink_amp_factor", "Kink Amplitude")
1177             factor_but(col, "use_map_kink_freq", "kink_freq_factor", "Kink Frequency")
1178             factor_but(col, "use_map_rough", "rough_factor", "Rough")
1179
1180         elif isinstance(idblock, FreestyleLineStyle):
1181             split = layout.split()
1182
1183             col = split.column()
1184             factor_but(col, "use_map_color_diffuse", "diffuse_color_factor", "Color")
1185             col = split.column()
1186             factor_but(col, "use_map_alpha", "alpha_factor", "Alpha")
1187
1188         layout.separator()
1189
1190         if not isinstance(idblock, ParticleSettings):
1191             split = layout.split()
1192
1193             col = split.column()
1194             col.prop(tex, "blend_type", text="Blend")
1195             col.prop(tex, "use_rgb_to_intensity")
1196             # color is used on gray-scale textures even when use_rgb_to_intensity is disabled.
1197             col.prop(tex, "color", text="")
1198
1199             col = split.column()
1200             col.prop(tex, "invert", text="Negative")
1201             col.prop(tex, "use_stencil")
1202
1203         if isinstance(idblock, Material) or isinstance(idblock, World):
1204             col.prop(tex, "default_value", text="DVar", slider=True)
1205
1206         if isinstance(idblock, Material):
1207             layout.label(text="Bump Mapping:")
1208
1209             # only show bump settings if activated but not for normal-map images
1210             row = layout.row()
1211
1212             sub = row.row()
1213             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))
1214             sub.prop(tex, "bump_method", text="Method")
1215
1216             # the space setting is supported for: derivative-maps + bump-maps (DEFAULT,BEST_QUALITY), not for normal-maps
1217             sub = row.row()
1218             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))
1219             sub.prop(tex, "bump_objectspace", text="Space")
1220
1221
1222 class TEXTURE_PT_custom_props(TextureButtonsPanel, PropertyPanel, Panel):
1223     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
1224     _context_path = "texture"
1225     _property_type = Texture
1226
1227
1228 classes = (
1229     TEXTURE_MT_specials,
1230     TEXTURE_MT_envmap_specials,
1231     TEXTURE_UL_texslots,
1232     TEXTURE_PT_context_texture,
1233     TEXTURE_PT_preview,
1234     TEXTURE_PT_colors,
1235     TEXTURE_PT_clouds,
1236     TEXTURE_PT_wood,
1237     TEXTURE_PT_marble,
1238     TEXTURE_PT_magic,
1239     TEXTURE_PT_blend,
1240     TEXTURE_PT_stucci,
1241     TEXTURE_PT_image,
1242     TEXTURE_PT_image_sampling,
1243     TEXTURE_PT_image_mapping,
1244     TEXTURE_PT_envmap,
1245     TEXTURE_PT_envmap_sampling,
1246     TEXTURE_PT_musgrave,
1247     TEXTURE_PT_voronoi,
1248     TEXTURE_PT_distortednoise,
1249     TEXTURE_PT_voxeldata,
1250     TEXTURE_PT_pointdensity,
1251     TEXTURE_PT_pointdensity_turbulence,
1252     TEXTURE_PT_ocean,
1253     TEXTURE_PT_mapping,
1254     TEXTURE_PT_influence,
1255     TEXTURE_PT_custom_props,
1256 )
1257
1258 if __name__ == "__main__":  # only for live edit.
1259     from bpy.utils import register_class
1260     for cls in classes:
1261         register_class(cls)