2.5 Mesh Draw Options: [WIP]
[blender.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 = (not mat.shadeless)
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 = (not mat.shadeless)
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.itemS()
174                 col.itemR(mat, "vertex_color_paint")
175                 col.itemR(mat, "vertex_color_light")
176                 col.itemR(mat, "object_color")
177
178 class MATERIAL_PT_shadows(MaterialButtonsPanel):
179         __label__ = "Shadows"
180         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
181
182         def draw(self, context):
183                 layout = self.layout
184                 
185                 mat = context.material
186                 
187                 split = layout.split()
188                 
189                 col = split.column()
190                 col.itemR(mat, "shadows", text="Receive")
191                 col.itemR(mat, "transparent_shadows", text="Receive Transparent")
192                 col.itemR(mat, "only_shadow", text="Shadows Only")
193                 col.itemR(mat, "cast_shadows_only", text="Cast Only")
194                 col.itemR(mat, "shadow_casting_alpha", text="Casting Alpha", slider=True)
195                 
196                 col = split.column()
197                 col.itemR(mat, "ray_shadow_bias", text="Auto Ray Bias")
198                 sub = col.column()
199                 subsub = sub.column()
200                 subsub.active = (not mat.ray_shadow_bias)
201                 subsub.itemR(mat, "shadow_ray_bias", text="Ray Shadow Bias")
202                 sub.itemR(mat, "cast_buffer_shadows")
203                 sub.itemR(mat, "shadow_buffer_bias", text="Buffer Bias")
204
205 class MATERIAL_PT_diffuse(MaterialButtonsPanel):
206         __label__ = "Diffuse"
207         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
208
209         def poll(self, context):
210                 return (context.material.type != 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
211
212         def draw(self, context):
213                 layout = self.layout
214                 
215                 mat = context.material  
216                 
217                 split = layout.split()
218                 
219                 col = split.column()
220                 col.itemR(mat, "diffuse_color", text="")
221                 sub = col.column()
222                 sub.active = (not mat.shadeless)
223                 sub.itemR(mat, "diffuse_reflection", text="Intensity", slider=True)
224                 
225                 col = split.column()
226                 col.active = (not mat.shadeless)
227                 col.itemR(mat, "diffuse_shader", text="")
228                 col.itemR(mat, "use_diffuse_ramp", text="Ramp")
229                 
230                 col = layout.column()
231                 col.active = (not mat.shadeless)
232                 if mat.diffuse_shader == 'OREN_NAYAR':
233                         col.itemR(mat, "roughness")
234                 elif mat.diffuse_shader == 'MINNAERT':
235                         col.itemR(mat, "darkness")
236                 elif mat.diffuse_shader == 'TOON':
237                         row = col.row()
238                         row.itemR(mat, "diffuse_toon_size", text="Size")
239                         row.itemR(mat, "diffuse_toon_smooth", text="Smooth", slider=True)
240                 elif mat.diffuse_shader == 'FRESNEL':
241                         row = col.row()
242                         row.itemR(mat, "diffuse_fresnel", text="Fresnel")
243                         row.itemR(mat, "diffuse_fresnel_factor", text="Factor")
244                         
245                 if mat.use_diffuse_ramp:
246                         layout.itemS()
247                         layout.template_color_ramp(mat.diffuse_ramp, expand=True)
248                         layout.itemS()
249                         row = layout.row()
250                         split = row.split(percentage=0.3)
251                         split.itemL(text="Input:")
252                         split.itemR(mat, "diffuse_ramp_input", text="")
253                         split = row.split(percentage=0.3)
254                         split.itemL(text="Blend:")
255                         split.itemR(mat, "diffuse_ramp_blend", text="")
256                         
257                 
258 class MATERIAL_PT_specular(MaterialButtonsPanel):
259         __label__ = "Specular"
260         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
261
262         def poll(self, context):
263                 return (context.material.type != 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
264
265         def draw(self, context):
266                 layout = self.layout
267                 
268                 mat = context.material
269                 
270                 layout.active = (not mat.shadeless)
271                 
272                 split = layout.split()
273                 
274                 col = split.column()
275                 col.itemR(mat, "specular_color", text="")
276                 col.itemR(mat, "specular_reflection", text="Intensity", slider=True)
277
278                 col = split.column()
279                 col.itemR(mat, "specular_shader", text="")
280                 col.itemR(mat, "use_specular_ramp", text="Ramp")
281
282                 col = layout.column()
283                 if mat.specular_shader in ('COOKTORR', 'PHONG'):
284                         col.itemR(mat, "specular_hardness", text="Hardness")
285                 elif mat.specular_shader == 'BLINN':
286                         row = col.row()
287                         row.itemR(mat, "specular_hardness", text="Hardness")
288                         row.itemR(mat, "specular_ior", text="IOR")
289                 elif mat.specular_shader == 'WARDISO':
290                         col.itemR(mat, "specular_slope", text="Slope")
291                 elif mat.specular_shader == 'TOON':
292                         row = col.row()
293                         row.itemR(mat, "specular_toon_size", text="Size")
294                         row.itemR(mat, "specular_toon_smooth", text="Smooth", slider=True)
295                 
296                 if mat.use_specular_ramp:
297                         layout.itemS()
298                         layout.template_color_ramp(mat.specular_ramp, expand=True)
299                         layout.itemS()
300                         row = layout.row()
301                         split = row.split(percentage=0.3)
302                         split.itemL(text="Input:")
303                         split.itemR(mat, "specular_ramp_input", text="")
304                         split = row.split(percentage=0.3)
305                         split.itemL(text="Blend:")
306                         split.itemR(mat, "specular_ramp_blend", text="")
307                 
308 class MATERIAL_PT_sss(MaterialButtonsPanel):
309         __label__ = "Subsurface Scattering"
310         __default_closed__ = True
311         COMPAT_ENGINES = set(['BLENDER_RENDER'])
312         
313         def poll(self, context):
314                 return (context.material.type in ('SURFACE', 'WIRE')) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
315
316         def draw_header(self, context):
317                 layout = self.layout
318                 sss = context.material.subsurface_scattering
319
320                 layout.itemR(sss, "enabled", text="")
321         
322         def draw(self, context):
323                 layout = self.layout
324                 
325                 mat = context.material
326                 sss = context.material.subsurface_scattering
327
328                 layout.active = sss.enabled     
329                 
330                 split = layout.split()
331                 split.active = (not mat.shadeless)
332                 
333                 col = split.column(align=True)
334                 col.itemR(sss, "color", text="")
335                 col.itemL(text="Blend:")
336                 col.itemR(sss, "color_factor", text="Color", slider=True)
337                 col.itemR(sss, "texture_factor", text="Texture", slider=True)
338                 col.itemL(text="Scattering Weight:")
339                 col.itemR(sss, "front")
340                 col.itemR(sss, "back")
341                 
342                 col = split.column()
343                 sub = col.column(align=True)
344                 sub.itemR(sss, "ior")
345                 sub.itemR(sss, "scale")
346                 col.itemR(sss, "radius", text="RGB Radius")
347                 col.itemR(sss, "error_tolerance")
348
349 class MATERIAL_PT_raymir(MaterialButtonsPanel):
350         __label__ = "Ray Mirror"
351         __default_closed__ = True
352         COMPAT_ENGINES = set(['BLENDER_RENDER'])
353         
354         def poll(self, context):
355                 return (context.material.type in 'SURFACE', 'WIRE') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
356         
357         def draw_header(self, context):
358                 layout = self.layout
359                 
360                 raym = context.material.raytrace_mirror
361
362                 layout.itemR(raym, "enabled", text="")
363         
364         def draw(self, context):
365                 layout = self.layout
366                 
367                 mat = context.material
368                 raym = context.material.raytrace_mirror
369                 
370                 layout.active = raym.enabled
371                 
372                 split = layout.split()
373                 
374                 col = split.column()
375                 col.itemR(raym, "reflect", text="Reflectivity", slider=True)
376                 col.itemR(mat, "mirror_color", text="")
377                 col.itemL(text="Fresnel:")
378                 col.itemR(raym, "fresnel", text="Amount")
379                 sub = col.column()
380                 sub.active = raym.fresnel > 0
381                 sub.itemR(raym, "fresnel_fac", text="Blend", slider=True)
382                 col.itemS()
383                 col.itemS()
384                 sub = col.split(percentage=0.4)
385                 sub.itemL(text="Fade To:")
386                 sub.itemR(raym, "fade_to", text="")
387                 
388                 col = split.column()
389                 col.itemR(raym, "depth")
390                 col.itemR(raym, "distance", text="Max Dist")
391                 col.itemL(text="Gloss:")
392                 col.itemR(raym, "gloss", text="Amount", slider=True)
393                 sub = col.column()
394                 sub.active = raym.gloss < 1
395                 sub.itemR(raym, "gloss_threshold", slider=True, text="Threshold")
396                 sub.itemR(raym, "gloss_samples", text="Samples")
397                 sub.itemR(raym, "gloss_anisotropic", slider=True, text="Anisotropic")
398                 
399                 
400 class MATERIAL_PT_raytransp(MaterialButtonsPanel):
401         __label__= "Ray Transparency"
402         __default_closed__ = True
403         COMPAT_ENGINES = set(['BLENDER_RENDER'])
404                 
405         def poll(self, context):
406                 return (context.material.type in 'SURFACE', 'WIRE') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
407
408         def draw_header(self, context):
409                 layout = self.layout
410                 
411                 rayt = context.material.raytrace_transparency
412
413                 layout.itemR(rayt, "enabled", text="")
414
415         def draw(self, context):
416                 layout = self.layout
417                 
418                 mat = context.material
419                 rayt = context.material.raytrace_transparency
420                 
421                 layout.active = rayt.enabled and (not mat.shadeless)
422                 
423                 split = layout.split()
424                 
425                 col = split.column()
426                 col.itemR(rayt, "ior")
427                 col.itemR(rayt, "falloff")
428                 col.itemR(rayt, "limit")
429                 
430                 col = split.column()
431                 col.itemR(rayt, "depth")
432                 col.itemR(rayt, "filter", slider=True)
433                 col.itemR(rayt, "specular_opacity", slider=True, text="Spec Opacity")
434                 
435                 split = layout.split()
436                 
437                 col = split.column()
438                 col.itemL(text="Fresnel:")
439                 col.itemR(rayt, "fresnel", text="Amount")
440                 sub = col.column()
441                 sub.active = rayt.fresnel > 0
442                 sub.itemR(rayt, "fresnel_fac", text="Blend", slider=True)
443                 
444                 col = split.column()
445                 col.itemL(text="Gloss:")
446                 col.itemR(rayt, "gloss", text="Amount", slider=True)
447                 sub = col.column()
448                 sub.active = rayt.gloss < 1
449                 sub.itemR(rayt, "gloss_threshold", slider=True, text="Threshold")
450                 sub.itemR(rayt, "gloss_samples", text="Samples")
451                 
452 class MATERIAL_PT_halo(MaterialButtonsPanel):
453         __label__= "Halo"
454         COMPAT_ENGINES = set(['BLENDER_RENDER'])
455         
456         def poll(self, context):
457                 return (context.material.type == 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
458         
459         def draw(self, context):
460                 layout = self.layout
461                 
462                 mat = context.material
463                 halo = mat.halo
464
465                 split = layout.split()
466                 
467                 col = split.column()
468                 col.itemR(mat, "diffuse_color", text="")
469                 col.itemR(halo, "size")
470                 col.itemR(halo, "hardness")
471                 col.itemR(halo, "add", slider=True)
472                 col.itemL(text="Options:")
473                 col.itemR(halo, "use_texture", text="Texture")
474                 col.itemR(halo, "use_vertex_normal", text="Vertex Normal")
475                 col.itemR(halo, "xalpha")
476                 col.itemR(halo, "shaded")
477                 col.itemR(halo, "soft")
478
479                 col = split.column()
480                 col.itemR(halo, "ring")
481                 sub = col.column()
482                 sub.active = halo.ring
483                 sub.itemR(halo, "rings")
484                 sub.itemR(mat, "mirror_color", text="")
485                 col.itemR(halo, "lines")
486                 sub = col.column()
487                 sub.active = halo.lines
488                 sub.itemR(halo, "line_number", text="Lines")
489                 sub.itemR(mat, "specular_color", text="")
490                 col.itemR(halo, "star")
491                 sub = col.column()
492                 sub.active = halo.star
493                 sub.itemR(halo, "star_tips")
494                 col.itemR(halo, "flare_mode")
495                 sub = col.column()
496                 sub.active = halo.flare_mode
497                 sub.itemR(halo, "flare_size", text="Size")
498                 sub.itemR(halo, "flare_subsize", text="Subsize")
499                 sub.itemR(halo, "flare_boost", text="Boost")
500                 sub.itemR(halo, "flare_seed", text="Seed")
501                 sub.itemR(halo, "flares_sub", text="Sub")
502
503 bpy.types.register(MATERIAL_PT_context_material)
504 bpy.types.register(MATERIAL_PT_preview)
505 bpy.types.register(MATERIAL_PT_material)
506 bpy.types.register(MATERIAL_PT_diffuse)
507 bpy.types.register(MATERIAL_PT_specular)
508 bpy.types.register(MATERIAL_PT_raymir)
509 bpy.types.register(MATERIAL_PT_raytransp)
510 bpy.types.register(MATERIAL_PT_sss)
511 bpy.types.register(MATERIAL_PT_halo)
512 bpy.types.register(MATERIAL_PT_strand)
513 bpy.types.register(MATERIAL_PT_options)
514 bpy.types.register(MATERIAL_PT_shadows)