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