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