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