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