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