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