svn merge -r 21041:21301 https://svn.blender.org/svnroot/bf-blender/branches/blender2...
[blender.git] / release / ui / buttons_material.py
1         
2 import bpy
3
4 class MaterialButtonsPanel(bpy.types.Panel):
5         __space_type__ = "BUTTONS_WINDOW"
6         __region_type__ = "WINDOW"
7         __context__ = "material"
8
9         def poll(self, context):
10                 return (context.material != None)
11
12 class MATERIAL_PT_preview(MaterialButtonsPanel):
13         __idname__= "MATERIAL_PT_preview"
14         __label__ = "Preview"
15
16         def poll(self, context):
17                 return (context.material or context.material_slot)
18
19         def draw(self, context):
20                 layout = self.layout
21                 mat = context.material
22                 
23                 layout.template_preview(mat)
24         
25 class MATERIAL_PT_material(MaterialButtonsPanel):
26         __idname__= "MATERIAL_PT_material"
27         __label__ = "Material"
28
29         def poll(self, context):
30                 return (context.material or context.material_slot)
31
32         def draw(self, context):
33                 layout = self.layout
34                 
35                 mat = context.material
36                 ob = context.object
37                 slot = context.material_slot
38                 space = context.space_data
39
40                 split = layout.split(percentage=0.65)
41
42                 if ob and slot:
43                         split.template_ID(slot, "material", new="MATERIAL_OT_new")
44                         split.itemR(ob, "active_material_index", text="Active")
45                 elif mat:
46                         split.template_ID(space, "pin_id")
47                         split.itemS()
48
49                 if mat:
50                         layout.itemS()
51                 
52                         layout.itemR(mat, "type", expand=True)
53                         
54                         layout.itemR(mat, "alpha", slider=True)
55
56                         row = layout.row()
57                         row.active = mat.type in ('SURFACE', 'VOLUME')
58                         row.itemR(mat, "shadeless")     
59                         row.itemR(mat, "wireframe")
60                         rowsub = row.row()
61                         rowsub.active = mat.shadeless== False
62                         rowsub.itemR(mat, "tangent_shading")
63                         
64 class MATERIAL_PT_strand(MaterialButtonsPanel):
65         __idname__= "MATERIAL_PT_strand"
66         __label__ = "Strand"
67         __default_closed__ = True
68         
69         def draw(self, context):
70                 layout = self.layout
71                 tan = context.material.strand
72                 mat = context.material
73                 
74                 split = layout.split()
75                 
76                 sub = split.column()
77                 sub.itemL(text="Size:")
78                 sub.itemR(tan, "start_size", text="Root")
79                 sub.itemR(tan, "end_size", text="Tip")
80                 sub.itemR(tan, "min_size", text="Minimum")
81                 sub.itemR(tan, "blender_units")
82                 colsub = sub.column()
83                 colsub.active = mat.shadeless== False
84                 colsub.itemR(tan, "tangent_shading")
85                 
86                 sub = split.column()
87                 sub.itemR(tan, "shape")
88                 sub.itemR(tan, "width_fade")
89                 sub.itemR(tan, "uv_layer")
90                 colsub = sub.column()
91                 colsub.active = mat.shadeless== False
92                 colsub.itemR(tan, "surface_diffuse")
93                 colsubsub = colsub.column()
94                 colsubsub.active = tan.surface_diffuse
95                 colsubsub.itemR(tan, "blend_distance", text="Distance")
96                 
97 class MATERIAL_PT_options(MaterialButtonsPanel):
98         __idname__= "MATERIAL_PT_options"
99         __label__ = "Options"
100
101         def draw(self, context):
102                 layout = self.layout
103                 mat = context.material
104                 
105                 split = layout.split()
106                 
107                 sub = split.column()
108                 sub.itemR(mat, "traceable")
109                 sub.itemR(mat, "full_oversampling")
110                 sub.itemR(mat, "sky")
111                 sub.itemR(mat, "exclude_mist")
112                 sub.itemR(mat, "face_texture")
113                 colsub = sub.column()
114                 colsub.active = mat.face_texture
115                 colsub.itemR(mat, "face_texture_alpha")
116                 sub.itemR(mat, "invert_z")
117                 sub.itemR(mat, "light_group")
118                 sub.itemR(mat, "light_group_exclusive")
119                 
120                 sub = split.column()
121                 sub.itemL(text="Shadows:")
122                 sub.itemR(mat, "shadows", text="Recieve")
123                 sub.itemR(mat, "transparent_shadows", text="Recieve Transparent")
124                 sub.itemR(mat, "only_shadow", text="Shadows Only")
125                 sub.itemR(mat, "cast_shadows_only", text="Cast Only")
126                 sub.itemR(mat, "shadow_casting_alpha", text="Casting Alpha", slider=True)
127                 
128                 sub.itemR(mat, "ray_shadow_bias")
129                 colsub = sub.column()
130                 colsub.active = mat.ray_shadow_bias
131                 colsub.itemR(mat, "shadow_ray_bias", text="Raytracing Bias")
132                 sub.itemR(mat, "cast_buffer_shadows")
133                 colsub = sub.column()
134                 colsub.active = mat.cast_buffer_shadows
135                 colsub.itemR(mat, "shadow_buffer_bias", text="Buffer Bias")
136
137 class MATERIAL_PT_diffuse(MaterialButtonsPanel):
138         __idname__= "MATERIAL_PT_diffuse"
139         __label__ = "Diffuse"
140
141         def poll(self, context):
142                 mat = context.material
143                 return (mat and mat.type != "HALO")
144
145         def draw(self, context):
146                 layout = self.layout
147                 mat = context.material  
148                 
149                 split = layout.split()
150                 
151                 sub = split.column()
152                 sub.itemR(mat, "diffuse_color", text="")
153                 sub.itemR(mat, "object_color")
154                 colsub = sub.column()
155                 colsub.active = mat.shadeless== False
156                 colsub.itemR(mat, "ambient", slider=True)
157                 colsub.itemR(mat, "emit")
158                 sub.itemR(mat, "translucency", slider=True)
159                 
160                 sub = split.column()
161                 sub.active = mat.shadeless== False
162                 sub.itemR(mat, "diffuse_reflection", text="Intensity", slider=True)
163                 sub.itemR(mat, "vertex_color_light")
164                 sub.itemR(mat, "vertex_color_paint")
165                 sub.itemR(mat, "cubic")
166                 
167                 row = layout.row()
168                 row.active = mat.shadeless== False
169                 row.itemR(mat, "diffuse_shader", text="Shader")
170                 
171                 split = layout.split()
172                 split.active = mat.shadeless== False
173                 sub = split.column()
174                 if mat.diffuse_shader == 'OREN_NAYAR':
175                                 sub.itemR(mat, "roughness")
176                                 sub = split.column()
177                 if mat.diffuse_shader == 'MINNAERT':
178                         sub.itemR(mat, "darkness")
179                         sub = split.column()
180                 if mat.diffuse_shader == 'TOON':
181                         sub.itemR(mat, "diffuse_toon_size", text="Size")
182                         sub = split.column()
183                         sub.itemR(mat, "diffuse_toon_smooth", text="Smooth")
184                 if mat.diffuse_shader == 'FRESNEL':
185                         sub.itemR(mat, "diffuse_fresnel", text="Fresnel")
186                         sub = split.column()
187                         sub.itemR(mat, "diffuse_fresnel_factor", text="Factor")
188                 
189                 layout.itemR(mat, "diffuse_ramp", text="Ramp")
190
191 class MATERIAL_PT_specular(MaterialButtonsPanel):
192         __idname__= "MATERIAL_PT_specular"
193         __label__ = "Specular"
194
195         def poll(self, context):
196                 mat = context.material
197                 return (mat and mat.type != "HALO")
198
199         def draw(self, context):
200                 layout = self.layout
201                 mat = context.material
202                 
203                 layout.active = mat.shadeless== False
204                 
205                 split = layout.split()
206                 
207                 sub = split.column()
208                 sub.itemR(mat, "specular_color", text="")
209                 sub = split.column()
210                 sub.itemR(mat, "specular_reflection", text="Intensity", slider=True)
211                 
212                 layout.itemR(mat, "spec_shader", text="Shader")
213                 
214                 split = layout.split()
215                 
216                 sub = split.column()
217                 if mat.spec_shader in ('COOKTORR', 'PHONG'):
218                         sub.itemR(mat, "specular_hardness", text="Hardness")
219                         sub = split.column()
220                 if mat.spec_shader == 'BLINN':
221                         sub.itemR(mat, "specular_hardness", text="Hardness")
222                         sub = split.column()
223                         sub.itemR(mat, "specular_ior", text="IOR")
224                 if mat.spec_shader == 'WARDISO':
225                         sub.itemR(mat, "specular_slope", text="Slope")
226                         sub.itemR(mat, "specular_hardness", text="Hardness")
227                 if mat.spec_shader == 'TOON':
228                         sub.itemR(mat, "specular_toon_size", text="Size")
229                         sub = split.column()
230                         sub.itemR(mat, "specular_toon_smooth", text="Smooth")
231                 
232                 layout.itemR(mat, "specular_ramp", text="Ramp")
233
234 class MATERIAL_PT_sss(MaterialButtonsPanel):
235         __idname__= "MATERIAL_PT_sss"
236         __label__ = "Subsurface Scattering"
237         __default_closed__ = True
238         
239         def poll(self, context):
240                 mat = context.material
241                 return (mat and mat.type == "SURFACE")
242
243         def draw_header(self, context):
244                 layout = self.layout
245                 sss = context.material.subsurface_scattering
246
247                 layout.itemR(sss, "enabled", text="")
248         
249         def draw(self, context):
250                 layout = self.layout
251                 sss = context.material.subsurface_scattering
252                 mat = context.material
253                 layout.active = sss.enabled     
254                 
255                 split = layout.split()
256                 split.active = mat.shadeless== False
257                 
258                 sub = split.column()
259                 sub.itemR(sss, "color", text="")
260                 sub.itemL(text="Blend:")
261                 sub.itemR(sss, "color_factor", slider=True)
262                 sub.itemR(sss, "texture_factor", slider=True)
263                 sub.itemL(text="Scattering Weight:")
264                 sub.itemR(sss, "front")
265                 sub.itemR(sss, "back")
266                 
267                 sub = split.column()
268                 sub.itemR(sss, "ior")
269                 sub.itemR(sss, "scale")
270                 sub.itemR(sss, "radius", text="RGB Radius")
271                 sub.itemR(sss, "error_tolerance")
272
273 class MATERIAL_PT_raymir(MaterialButtonsPanel):
274         __idname__= "MATERIAL_PT_raymir"
275         __label__ = "Ray Mirror"
276         __default_closed__ = True
277         
278         def poll(self, context):
279                 mat = context.material
280                 return (mat and mat.type == "SURFACE")
281         
282         def draw_header(self, context):
283                 layout = self.layout
284                 raym = context.material.raytrace_mirror
285
286                 layout.itemR(raym, "enabled", text="")
287         
288         def draw(self, context):
289                 layout = self.layout
290                 raym = context.material.raytrace_mirror
291                 mat = context.material
292                 
293                 layout.active = raym.enabled
294                 
295                 split = layout.split()
296                 
297                 sub = split.column()
298                 sub.itemR(raym, "reflect", text="Reflectivity", slider=True)
299                 sub.itemR(mat, "mirror_color", text="")
300                 sub.itemR(raym, "fresnel")
301                 sub.itemR(raym, "fresnel_fac", text="Fac", slider=True)
302                 
303                 sub = split.column()
304                 sub.itemR(raym, "gloss", slider=True)
305                 colsub = sub.column()
306                 colsub.active = raym.gloss < 1
307                 colsub.itemR(raym, "gloss_threshold", slider=True, text="Threshold")
308                 colsub.itemR(raym, "gloss_samples", text="Samples")
309                 colsub.itemR(raym, "gloss_anisotropic", slider=True, text="Anisotropic")
310                 
311                 row = layout.row()
312                 row.itemR(raym, "distance", text="Max Dist")
313                 row.itemR(raym, "depth")
314                 
315                 layout.itemR(raym, "fade_to")
316                 
317 class MATERIAL_PT_raytransp(MaterialButtonsPanel):
318         __idname__= "MATERIAL_PT_raytransp"
319         __label__= "Ray Transparency"
320         __default_closed__ = True
321                 
322         def poll(self, context):
323                 mat = context.material
324                 return (mat and mat.type == "SURFACE")
325
326         def draw_header(self, context):
327                 layout = self.layout
328                 rayt = context.material.raytrace_transparency
329
330                 layout.itemR(rayt, "enabled", text="")
331
332         def draw(self, context):
333                 layout = self.layout
334                 rayt = context.material.raytrace_transparency
335                 mat = context.material
336                 
337                 layout.active = rayt.enabled    
338                 
339                 split = layout.split()
340                 split.active = mat.shadeless== False
341                 
342                 sub = split.column()
343                 sub.itemR(rayt, "ior")
344                 sub.itemR(rayt, "fresnel")
345                 sub.itemR(rayt, "fresnel_fac", text="Fac", slider=True)
346                 
347                 sub = split.column()
348                 sub.itemR(rayt, "gloss", slider=True)
349                 colsub = sub.column()
350                 colsub.active = rayt.gloss < 1
351                 colsub.itemR(rayt, "gloss_threshold", slider=True, text="Threshold")
352                 colsub.itemR(rayt, "gloss_samples", text="Samples")
353                 
354                 flow = layout.column_flow()
355                 flow.active = mat.shadeless== False
356                 flow.itemR(rayt, "filter", slider=True)
357                 flow.itemR(rayt, "limit")
358                 flow.itemR(rayt, "falloff")
359                 flow.itemR(rayt, "specular_opacity", slider=True, text="Spec Opacity")
360                 flow.itemR(rayt, "depth")
361                 
362 class MATERIAL_PT_halo(MaterialButtonsPanel):
363         __idname__= "MATERIAL_PT_halo"
364         __label__= "Halo"
365         
366         def poll(self, context):
367                 mat = context.material
368                 return (mat and mat.type == "HALO")
369         
370         def draw(self, context):
371                 layout = self.layout
372                 
373                 mat = context.material
374                 halo = mat.halo
375
376                 split = layout.split()
377                 
378                 col = split.column()
379                 col.itemR(mat, "diffuse_color", text="")
380                 col.itemR(halo, "size")
381                 col.itemR(halo, "hardness")
382                 col.itemR(halo, "add", slider=True)
383                 
384                 col.itemL(text="Options:")
385                 col.itemR(halo, "use_texture", text="Texture")
386                 col.itemR(halo, "use_vertex_normal", text="Vertex Normal")
387                 col.itemR(halo, "xalpha")
388                 col.itemR(halo, "shaded")
389                 col.itemR(halo, "soft")
390
391                 col = split.column()
392                 col = col.column()
393                 col.itemR(halo, "ring")
394                 colsub = col.column()
395                 colsub.active = halo.ring
396                 colsub.itemR(halo, "rings")
397                 colsub.itemR(mat, "mirror_color", text="")
398                 col.itemR(halo, "lines")
399                 colsub = col.column()
400                 colsub.active = halo.lines
401                 colsub.itemR(halo, "line_number", text="Lines")
402                 colsub.itemR(mat, "specular_color", text="")
403                 col.itemR(halo, "star")
404                 colsub = col.column()
405                 colsub.active = halo.star
406                 colsub.itemR(halo, "star_tips")
407                 col.itemR(halo, "flare_mode")
408                 colsub = col.column()
409                 colsub.active = halo.flare_mode
410                 colsub.itemR(halo, "flare_size", text="Size")
411                 colsub.itemR(halo, "flare_subsize", text="Subsize")
412                 colsub.itemR(halo, "flare_boost", text="Boost")
413                 colsub.itemR(halo, "flare_seed", text="Seed")
414                 colsub.itemR(halo, "flares_sub", text="Sub")
415
416 bpy.types.register(MATERIAL_PT_preview)
417 bpy.types.register(MATERIAL_PT_material)
418 bpy.types.register(MATERIAL_PT_diffuse)
419 bpy.types.register(MATERIAL_PT_specular)
420 bpy.types.register(MATERIAL_PT_raymir)
421 bpy.types.register(MATERIAL_PT_raytransp)
422 bpy.types.register(MATERIAL_PT_sss)
423 bpy.types.register(MATERIAL_PT_halo)
424 bpy.types.register(MATERIAL_PT_strand)
425 bpy.types.register(MATERIAL_PT_options)