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