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