80ae503ee6a086031f30bdbb1f10110d6df75276
[blender.git] / release / ui / buttons_texture.py
1
2 import bpy
3
4 class TextureButtonsPanel(bpy.types.Panel):
5         __space_type__ = "BUTTONS_WINDOW"
6         __region_type__ = "WINDOW"
7         __context__ = "texture"
8         
9         def poll(self, context):
10                 return (context.texture != None and context.texture.type != 'NONE')
11                 
12 class TEXTURE_PT_preview(TextureButtonsPanel):
13         __idname__= "TEXTURE_PT_preview"
14         __label__ = "Preview"
15
16         def draw(self, context):
17                 layout = self.layout
18                 tex = context.texture
19                 ma = context.material
20                 la = context.lamp
21                 wo = context.world
22                 br = context.brush
23                 
24                 if ma:
25                         layout.template_preview(tex, parent=ma)
26                 elif la:
27                         layout.template_preview(tex, parent=la)
28                 elif wo:
29                         layout.template_preview(tex, parent=wo)
30                 elif br:
31                         layout.template_preview(tex, parent=br)
32                 else:
33                         layout.template_preview(tex)
34
35 class TEXTURE_PT_context_texture(TextureButtonsPanel):
36         __idname__= "TEXTURE_PT_context_texture"
37         __no_header__ = True
38
39         def poll(self, context):
40                 return (context.material or context.world or context.lamp or context.brush or context.texture)
41
42         def draw(self, context):
43                 layout = self.layout
44
45                 tex = context.texture
46                 ma = context.material
47                 la = context.lamp
48                 wo = context.world
49                 br = context.brush
50                 space = context.space_data
51                 slot = context.texture_slot
52
53                 if ma or la or wo or br:
54                         row = layout.row()
55                         if ma:
56                                 row.template_list(ma, "textures", ma, "active_texture_index", type="ICONS")
57                         elif la:
58                                 row.template_list(la, "textures", la, "active_texture_index", type="ICONS")
59                         elif wo:
60                                 row.template_list(wo, "textures", wo, "active_texture_index", type="ICONS")
61                         elif br:
62                                 row.template_list(br, "textures", br, "active_texture_index", type="ICONS")
63
64                 split = layout.split(percentage=0.65)
65
66                 if ma or la or wo or br:
67                         if slot:
68                                 split.template_ID(slot, "texture", new="texture.new")
69                         else:
70                                 split.itemS()
71                 elif tex:
72                         split.template_ID(space, "pin_id")
73
74                 if not space.pin_id and \
75                    (context.sculpt_object or context.vertex_paint_object or \
76                    context.weight_paint_object or context.texture_paint_object):
77                         split.itemR(space, "brush_texture", text="Brush", toggle=True)
78                 else:
79                         split.itemS()
80                 
81                 layout.itemS()
82
83                 if tex:
84                         split = layout.split(percentage=0.2)
85                 
86                         col = split.column()
87                         col.itemL(text="Type:")
88                         col = split.column()
89                         col.itemR(tex, "type", text="")
90
91 class TEXTURE_PT_mapping(TextureButtonsPanel):
92         __idname__= "TEXTURE_PT_mapping"
93         __label__ = "Mapping"
94         
95         def poll(self, context):
96                 return (context.texture_slot and context.texture and context.texture.type != 'NONE')
97
98         def draw(self, context):
99                 layout = self.layout
100                 ma = context.material
101                 la = context.lamp
102                 wo = context.world
103                 br = context.brush
104                 tex = context.texture_slot
105                 textype = context.texture
106
107                 if not br:
108                         split = layout.split(percentage=0.3)
109                         col = split.column()
110                         col.itemL(text="Coordinates:")
111                         col = split.column()
112                         col.itemR(tex, "texture_coordinates", text="")
113
114                         if tex.texture_coordinates == 'ORCO':
115                                 """
116                                 ob = context.object
117                                 if ob and ob.type == 'MESH':
118                                         split = layout.split(percentage=0.3)
119                                         split.itemL(text="Mesh:")
120                                         split.itemR(ob.data, "texco_mesh", text="")
121                                 """
122                         elif tex.texture_coordinates == 'UV':
123                                 split = layout.split(percentage=0.3)
124                                 split.itemL(text="Layer:")
125                                 split.itemR(tex, "uv_layer", text="")
126                         elif tex.texture_coordinates == 'OBJECT':
127                                 split = layout.split(percentage=0.3)
128                                 split.itemL(text="Object:")
129                                 split.itemR(tex, "object", text="")
130                         
131                 if ma:
132                         split = layout.split(percentage=0.3)
133                         col = split.column()
134                         col.itemL(text="Projection:")
135                         col = split.column()
136                         col.itemR(tex, "mapping", text="")
137
138                         split = layout.split()
139                         
140                         col = split.column()
141                         if tex.texture_coordinates in ('ORCO', 'UV'):
142                                 col.itemR(tex, "from_dupli")
143                         elif tex.texture_coordinates == 'OBJECT':
144                                 col.itemR(tex, "from_original")
145                         else:
146                                 col.itemL()
147                         
148                         col = split.column()
149                         row = col.row()
150                         row.itemR(tex, "x_mapping", text="")
151                         row.itemR(tex, "y_mapping", text="")
152                         row.itemR(tex, "z_mapping", text="")
153
154                 row = layout.row()
155                 row.column().itemR(tex, "offset")
156                 row.column().itemR(tex, "size")
157
158 class TEXTURE_PT_influence(TextureButtonsPanel):
159         __idname__= "TEXTURE_PT_influence"
160         __label__ = "Influence"
161         
162         def poll(self, context):
163                 return (context.texture_slot and context.texture and context.texture.type != 'NONE' and (not context.brush))
164
165         def draw(self, context):
166                 layout = self.layout
167                 
168                 ma = context.material
169                 la = context.lamp
170                 wo = context.world
171                 br = context.brush
172                 textype = context.texture
173                 tex = context.texture_slot
174
175                 def factor_but(layout, active, toggle, factor, name):
176                         row = layout.row(align=True)
177                         row.itemR(tex, toggle, text="")
178                         sub = row.row()
179                         sub.active = active
180                         sub.itemR(tex, factor, text=name, slider=True)
181                 
182                 if ma:
183                         split = layout.split()
184                         
185                         col = split.column()
186
187                         col.itemL(text="Diffuse:")
188                         factor_but(col, tex.map_diffuse, "map_diffuse", "diffuse_factor", "Intensity")
189                         factor_but(col, tex.map_colordiff, "map_colordiff", "colordiff_factor", "Color")
190                         factor_but(col, tex.map_alpha, "map_alpha", "alpha_factor", "Alpha")
191                         factor_but(col, tex.map_translucency, "map_translucency", "translucency_factor", "Translucency")
192
193                         col.itemL(text="Specular:")
194                         factor_but(col, tex.map_specular, "map_specular", "specular_factor", "Intensity")
195                         factor_but(col, tex.map_colorspec, "map_colorspec", "colorspec_factor", "Color")
196                         factor_but(col, tex.map_hardness, "map_hardness", "hardness_factor", "Hardness")
197
198                         col = split.column()
199                         col.itemL(text="Shading:")
200                         factor_but(col, tex.map_ambient, "map_ambient", "ambient_factor", "Ambient")
201                         factor_but(col, tex.map_emit, "map_emit", "emit_factor", "Emit")
202                         factor_but(col, tex.map_mirror, "map_mirror", "mirror_factor", "Mirror")
203                         factor_but(col, tex.map_raymir, "map_raymir", "raymir_factor", "Ray Mirror")
204
205                         col.itemL(text="Geometry:")
206                         factor_but(col, tex.map_normal, "map_normal", "normal_factor", "Normal")
207                         factor_but(col, tex.map_warp, "map_warp", "warp_factor", "Warp")
208                         factor_but(col, tex.map_displacement, "map_displacement", "displacement_factor", "Displace")
209
210                         #colsub = col.column()
211                         #colsub.active = tex.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
212                         #colsub.itemR(tex, "default_value", text="Amount", slider=True)
213                 elif la:
214                         row = layout.row()
215                         factor_but(row, tex.map_color, "map_color", "color_factor", "Color")
216                         factor_but(row, tex.map_shadow, "map_shadow", "shadow_factor", "Shadow")
217                 elif wo:
218                         split = layout.split()
219                         col = split.column()
220                         factor_but(col, tex.map_blend, "map_blend", "blend_factor", "Blend")
221                         factor_but(col, tex.map_horizon, "map_horizon", "horizon_factor", "Horizon")
222
223                         col = split.column()
224                         factor_but(col, tex.map_zenith_up, "map_zenith_up", "zenith_up_factor", "Zenith Up")
225                         factor_but(col, tex.map_zenith_down, "map_zenith_down", "zenith_down_factor", "Zenith Down")
226
227                 layout.itemS()
228                 split = layout.split()
229
230                 col = split.column()
231
232                 col.itemR(tex, "blend_type", text="Blend")
233                 col.itemR(tex, "rgb_to_intensity")
234                 colsub = col.column()
235                 colsub.active = tex.rgb_to_intensity
236                 colsub.itemR(tex, "color", text="")
237
238                 col = split.column()
239                 col.itemR(tex, "negate", text="Negative")
240                 col.itemR(tex, "stencil")
241                 if ma or wo:
242                         col.itemR(tex, "default_value", text="DVar", slider=True)
243
244 class TEXTURE_PT_colors(TextureButtonsPanel):
245         __idname__= "TEXTURE_PT_colors"
246         __label__ = "Colors"
247         __default_closed__ = True
248
249         def draw(self, context):
250                 layout = self.layout
251                 tex = context.texture
252
253                 layout.itemR(tex, "use_color_ramp", text="Ramp")
254                 if tex.use_color_ramp:
255                         layout.template_color_ramp(tex.color_ramp, expand=True)
256
257                 split = layout.split()
258                 col = split.column()
259                 col.itemR(tex, "rgb_factor", text="Multiply RGB")
260
261                 col = split.column()
262                 col.itemL(text="Adjust:")
263                 col.itemR(tex, "brightness")
264                 col.itemR(tex, "contrast")
265
266 class TEXTURE_PT_clouds(TextureButtonsPanel):
267         __idname__= "TEXTURE_PT_clouds"
268         __label__ = "Clouds"
269         
270         def poll(self, context):
271                 tex = context.texture
272                 return (tex and tex.type == 'CLOUDS')
273
274         def draw(self, context):
275                 layout = self.layout
276                 tex = context.texture
277                 
278                 layout.itemR(tex, "stype", expand=True)
279                 layout.itemL(text="Noise:")
280                 layout.itemR(tex, "noise_type", text="Type", expand=True)
281                 layout.itemR(tex, "noise_basis", text="Basis")
282                 
283                 col = layout.column_flow()
284                 col.itemR(tex, "noise_size", text="Size")
285                 col.itemR(tex, "noise_depth", text="Depth")
286                 col.itemR(tex, "nabla", text="Nabla")
287
288 class TEXTURE_PT_wood(TextureButtonsPanel):
289         __idname__= "TEXTURE_PT_wood"
290         __label__ = "Wood"
291         
292         def poll(self, context):
293                 tex = context.texture
294                 return (tex and tex.type == 'WOOD')
295
296         def draw(self, context):
297                 layout = self.layout
298                 tex = context.texture
299                 
300                 layout.itemR(tex, "noisebasis2", expand=True)
301                 layout.itemR(tex, "stype", expand=True)
302                 
303                 col = layout.column()
304                 col.active = tex.stype in ('RINGNOISE', 'BANDNOISE')
305                 col.itemL(text="Noise:")
306                 col.row().itemR(tex, "noise_type", text="Type", expand=True)
307                 col.itemR(tex, "noise_basis", text="Basis")
308                 
309                 col = layout.column_flow()
310                 col.active = tex.stype in ('RINGNOISE', 'BANDNOISE')
311                 col.itemR(tex, "noise_size", text="Size")
312                 col.itemR(tex, "turbulence")
313                 col.itemR(tex, "nabla")
314                 
315 class TEXTURE_PT_marble(TextureButtonsPanel):
316         __idname__= "TEXTURE_PT_marble"
317         __label__ = "Marble"
318         
319         def poll(self, context):
320                 tex = context.texture
321                 return (tex and tex.type == 'MARBLE')
322
323         def draw(self, context):
324                 layout = self.layout
325                 tex = context.texture
326                 
327                 layout.itemR(tex, "stype", expand=True)
328                 layout.itemR(tex, "noisebasis2", expand=True)
329                 layout.itemL(text="Noise:")
330                 layout.itemR(tex, "noise_type", text="Type", expand=True)
331                 layout.itemR(tex, "noise_basis", text="Basis")
332                 
333                 col = layout.column_flow()      
334                 col.itemR(tex, "noise_size", text="Size")
335                 col.itemR(tex, "noise_depth", text="Depth")
336                 col.itemR(tex, "turbulence")
337                 col.itemR(tex, "nabla")
338
339 class TEXTURE_PT_magic(TextureButtonsPanel):
340         __idname__= "TEXTURE_PT_magic"
341         __label__ = "Magic"
342         
343         def poll(self, context):
344                 tex = context.texture
345                 return (tex and tex.type == 'MAGIC')
346
347         def draw(self, context):
348                 layout = self.layout
349                 tex = context.texture
350                         
351                 row = layout.row()
352                 row.itemR(tex, "noise_depth", text="Depth")
353                 row.itemR(tex, "turbulence")
354
355 class TEXTURE_PT_blend(TextureButtonsPanel):
356         __idname__= "TEXTURE_PT_blend"
357         __label__ = "Blend"
358         
359         def poll(self, context):
360                 tex = context.texture
361                 return (tex and tex.type == 'BLEND')
362
363         def draw(self, context):
364                 layout = self.layout
365                 tex = context.texture
366
367                 layout.itemR(tex, "progression")
368                 layout.itemR(tex, "flip_axis")
369                         
370 class TEXTURE_PT_stucci(TextureButtonsPanel):
371         __idname__= "TEXTURE_PT_stucci"
372         __label__ = "Stucci"
373         
374         def poll(self, context):
375                 tex = context.texture
376                 return (tex and tex.type == 'STUCCI')
377
378         def draw(self, context):
379                 layout = self.layout
380                 tex = context.texture
381                 
382                 layout.itemR(tex, "stype", expand=True)
383                 layout.itemL(text="Noise:")
384                 layout.itemR(tex, "noise_type", text="Type", expand=True)
385                 layout.itemR(tex, "noise_basis", text="Basis")
386                 
387                 row = layout.row()
388                 row.itemR(tex, "noise_size", text="Size")
389                 row.itemR(tex, "turbulence")
390                 
391 class TEXTURE_PT_image(TextureButtonsPanel):
392         __idname__= "TEXTURE_PT_image"
393         __label__ = "Image"
394         
395         def poll(self, context):
396                 tex = context.texture
397                 return (tex and tex.type == 'IMAGE')
398
399         def draw(self, context):
400                 layout = self.layout
401                 tex = context.texture
402
403                 layout.template_texture_image(tex)
404
405 class TEXTURE_PT_image_sampling(TextureButtonsPanel):
406         __idname__= "TEXTURE_PT_image_sampling"
407         __label__ = "Image Sampling"
408         __default_closed__ = True
409         
410         def poll(self, context):
411                 tex = context.texture
412                 return (tex and tex.type == 'IMAGE')
413
414         def draw(self, context):
415                 layout = self.layout
416                 tex = context.texture
417                 slot = context.texture_slot
418                 
419                 split = layout.split()
420                 
421                 """
422                 sub = split.column()            
423                 sub.itemR(tex, "flip_axis")
424                 sub.itemR(tex, "normal_map")
425                 if slot:
426                         row = sub.row()
427                         row.active = tex.normal_map
428                         row.itemR(slot, "normal_map_space", text="")
429                 """
430
431                 sub = split.column()
432
433                 sub.itemL(text="Alpha:")
434                 sub.itemR(tex, "use_alpha", text="Use")
435                 sub.itemR(tex, "calculate_alpha", text="Calculate")
436                 sub.itemR(tex, "invert_alpha", text="Invert")
437
438                 sub.itemL(text="Flip:")
439                 sub.itemR(tex, "flip_axis", text="X/Y Axis")
440
441                 sub = split.column() 
442                 sub.itemL(text="Filter:")
443                 sub.itemR(tex, "filter", text="")
444                 sub.itemR(tex, "mipmap")
445                 row = sub.row()
446                 row.itemR(tex, "mipmap_gauss", text="Gauss")
447                 row.active = tex.mipmap
448                 sub.itemR(tex, "interpolation")
449                 if tex.mipmap and tex.filter != 'DEFAULT':
450                         if tex.filter == 'FELINE':
451                                 sub.itemR(tex, "filter_probes", text="Probes")
452                         else:
453                                 sub.itemR(tex, "filter_eccentricity", text="Eccentricity")
454
455 class TEXTURE_PT_image_mapping(TextureButtonsPanel):
456         __idname__= "TEXTURE_PT_image_mapping"
457         __label__ = "Image Mapping"
458         __default_closed__ = True
459         
460         def poll(self, context):
461                 tex = context.texture
462                 return (tex and tex.type == 'IMAGE')
463
464         def draw(self, context):
465                 layout = self.layout
466                 tex = context.texture
467                 
468                 layout.itemR(tex, "extension")
469                 
470                 split = layout.split()
471                 
472                 if tex.extension == 'REPEAT': 
473                         sub = split.column(align=True)
474                         sub.itemL(text="Repeat:")
475                         sub.itemR(tex, "repeat_x", text="X")
476                         sub.itemR(tex, "repeat_y", text="Y")
477                         sub = split.column(align=True)
478                         sub.itemL(text="Mirror:")
479                         sub.itemR(tex, "mirror_x", text="X")
480                         sub.itemR(tex, "mirror_y", text="Y")
481                 elif tex.extension == 'CHECKER': 
482                         sub = split.column(align=True)
483                         row = sub.row()
484                         row.itemR(tex, "checker_even", text="Even")
485                         row.itemR(tex, "checker_odd", text="Odd")
486                         sub = split.column()
487                         sub.itemR(tex, "checker_distance", text="Distance")
488
489                 layout.itemS()
490
491                 split = layout.split()
492                 
493                 sub = split.column(align=True)
494                 #sub.itemR(tex, "crop_rectangle")
495                 sub.itemL(text="Crop Minimum:")
496                 sub.itemR(tex, "crop_min_x", text="X")
497                 sub.itemR(tex, "crop_min_y", text="Y")
498                 sub = split.column(align=True)
499                 sub.itemL(text="Crop Maximum:")
500                 sub.itemR(tex, "crop_max_x", text="X")
501                 sub.itemR(tex, "crop_max_y", text="Y")
502         
503 class TEXTURE_PT_plugin(TextureButtonsPanel):
504         __idname__= "TEXTURE_PT_plugin"
505         __label__ = "Plugin"
506         
507         def poll(self, context):
508                 tex = context.texture
509                 return (tex and tex.type == 'PLUGIN')
510
511         def draw(self, context):
512                 layout = self.layout
513                 tex = context.texture
514                 
515                 layout.itemL(text="Nothing yet")
516                 
517 class TEXTURE_PT_envmap(TextureButtonsPanel):
518         __idname__= "TEXTURE_PT_envmap"
519         __label__ = "Environment Map"
520         
521         def poll(self, context):
522                 tex = context.texture
523                 return (tex and tex.type == 'ENVIRONMENT_MAP')
524
525         def draw(self, context):
526                 layout = self.layout
527                 tex = context.texture
528                 
529                 layout.itemL(text="Nothing yet")
530                 
531 class TEXTURE_PT_musgrave(TextureButtonsPanel):
532         __idname__= "TEXTURE_PT_musgrave"
533         __label__ = "Musgrave"
534         
535         def poll(self, context):
536                 tex = context.texture
537                 return (tex and tex.type == 'MUSGRAVE')
538
539         def draw(self, context):
540                 layout = self.layout
541                 tex = context.texture
542                 
543                 layout.itemR(tex, "musgrave_type")      
544                 
545                 split = layout.split()
546                 
547                 sub = split.column()
548                 sub.itemR(tex, "highest_dimension", text="Dimension")
549                 sub.itemR(tex, "lacunarity")
550                 sub.itemR(tex, "octaves")
551                 sub = split.column() 
552                 if (tex.musgrave_type in ('HETERO_TERRAIN', 'RIDGED_MULTIFRACTAL', 'HYBRID_MULTIFRACTAL')):
553                         sub.itemR(tex, "offset")
554                 if (tex.musgrave_type in ('RIDGED_MULTIFRACTAL', 'HYBRID_MULTIFRACTAL')):
555                         sub.itemR(tex, "gain")
556                         sub.itemR(tex, "noise_intensity", text="Intensity")
557                 
558                 layout.itemL(text="Noise:")
559                 
560                 layout.itemR(tex, "noise_basis", text="Basis")
561                 
562                 row = layout.row()
563                 row.itemR(tex, "noise_size", text="Size")
564                 row.itemR(tex, "nabla")
565
566 class TEXTURE_PT_voronoi(TextureButtonsPanel):
567         __idname__= "TEXTURE_PT_voronoi"
568         __label__ = "Voronoi"
569         
570         def poll(self, context):
571                 tex = context.texture
572                 return (tex and tex.type == 'VORONOI')
573
574         def draw(self, context):
575                 layout = self.layout
576                 tex = context.texture
577         
578                 layout.itemR(tex, "distance_metric")
579                 layout.itemR(tex, "coloring")
580                 
581                 split = layout.split()
582                 
583                 sub = split.column()   
584                 
585                 sub.itemR(tex, "noise_intensity", text="Intensity")
586                 if tex.distance_metric == 'MINKOVSKY':
587                         sub.itemR(tex, "minkovsky_exponent", text="Exponent")
588                 sub = split.column()
589                 sub.itemR(tex, "feature_weights", slider=True)
590                 
591                 layout.itemL(text="Noise:")
592                 
593                 row = layout.row()
594                 row.itemR(tex, "noise_size", text="Size")
595                 row.itemR(tex, "nabla")
596                         
597 class TEXTURE_PT_distortednoise(TextureButtonsPanel):
598         __idname__= "TEXTURE_PT_distortednoise"
599         __label__ = "Distorted Noise"
600         
601         def poll(self, context):
602                 tex = context.texture
603                 return (tex and tex.type == 'DISTORTED_NOISE')
604
605         def draw(self, context):
606                 layout = self.layout
607                 tex = context.texture
608
609                 layout.itemR(tex, "noise_distortion")
610                 layout.itemR(tex, "noise_basis", text="Basis")
611                 
612                 split = layout.split()
613                 
614                 sub = split.column()
615                 sub.itemR(tex, "distortion_amount", text="Distortion")
616                 sub.itemR(tex, "noise_size", text="Size")
617                 
618                 sub = split.column()
619                 sub.itemR(tex, "nabla") 
620
621 bpy.types.register(TEXTURE_PT_context_texture)
622 bpy.types.register(TEXTURE_PT_preview)
623 bpy.types.register(TEXTURE_PT_clouds)
624 bpy.types.register(TEXTURE_PT_wood)
625 bpy.types.register(TEXTURE_PT_marble)
626 bpy.types.register(TEXTURE_PT_magic)
627 bpy.types.register(TEXTURE_PT_blend)
628 bpy.types.register(TEXTURE_PT_stucci)
629 bpy.types.register(TEXTURE_PT_image)
630 bpy.types.register(TEXTURE_PT_image_sampling)
631 bpy.types.register(TEXTURE_PT_image_mapping)
632 bpy.types.register(TEXTURE_PT_plugin)
633 bpy.types.register(TEXTURE_PT_envmap)
634 bpy.types.register(TEXTURE_PT_musgrave)
635 bpy.types.register(TEXTURE_PT_voronoi)
636 bpy.types.register(TEXTURE_PT_distortednoise)
637 bpy.types.register(TEXTURE_PT_colors)
638 bpy.types.register(TEXTURE_PT_mapping)
639 bpy.types.register(TEXTURE_PT_influence)
640