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