=== Blender Python API ===
[blender.git] / source / blender / python / api2_2x / Material.c
1 /* 
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA        02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * This is a new part of Blender.
24  *
25  * Contributor(s): Willian P. Germano, Michel Selten, Alex Mole,
26  * Alexander Szakaly, Campbell Barton, Ken Hughes
27  *
28  * ***** END GPL LICENSE BLOCK *****
29 */
30
31 #include "Material.h" /*This must come first*/
32
33 #include "DNA_space_types.h"
34 #include "DNA_material_types.h"
35 #include "DNA_userdef_types.h"
36 #include "BKE_main.h"
37 #include "BKE_global.h"
38 #include "BKE_library.h"
39 #include "BKE_material.h"
40 #include "BKE_texture.h"
41 #include "BKE_node.h"
42 #include "BKE_idprop.h"
43 #include "BKE_utildefines.h" /* for CLAMP */
44 #include "MEM_guardedalloc.h"
45 #include "BLI_blenlib.h"
46 #include "BSE_editipo.h"
47 #include "BIF_keyframing.h"
48 #include "BIF_space.h"
49 #include "mydevice.h"
50 #include "constant.h"
51 #include "MTex.h"
52 #include "Texture.h"
53 #include "Ipo.h"
54 #include "Group.h"
55 #include "gen_utils.h"
56 #include "gen_library.h"
57 #include "IDProp.h"
58
59 /*****************************************************************************/
60 /* Python BPy_Material defaults: */
61 /*****************************************************************************/
62 /* Material MIN, MAX values */
63 #define EXPP_MAT_ADD_MIN                         0.0f
64 #define EXPP_MAT_ADD_MAX                         1.0f
65 #define EXPP_MAT_ALPHA_MIN         0.0f
66 #define EXPP_MAT_ALPHA_MAX               1.0f
67 #define EXPP_MAT_AMB_MIN                         0.0f
68 #define EXPP_MAT_AMB_MAX                         1.0f
69 #define EXPP_MAT_COL_MIN                         0.0f /* min/max for all ... */
70 #define EXPP_MAT_COL_MAX                         1.0f /* ... color triplets  */
71 #define EXPP_MAT_EMIT_MIN                        0.0f
72 #define EXPP_MAT_EMIT_MAX                        1.0f
73 #define EXPP_MAT_REF_MIN                         0.0f
74 #define EXPP_MAT_REF_MAX                         1.0f
75 #define EXPP_MAT_SPEC_MIN                        0.0f
76 #define EXPP_MAT_SPEC_MAX                        2.0f
77 #define EXPP_MAT_SPECTRA_MIN     0.0f
78 #define EXPP_MAT_SPECTRA_MAX     1.0f
79
80 /* Shader specific settings */
81
82 #define EXPP_MAT_ROUGHNESS_MIN                   0.0f
83 #define EXPP_MAT_ROUGHNESS_MAX                   3.140f
84 #define EXPP_MAT_SPECSIZE_MIN                    0.0f
85 #define EXPP_MAT_SPECSIZE_MAX                    1.530f
86 #define EXPP_MAT_DIFFUSESIZE_MIN                 0.0f
87 #define EXPP_MAT_DIFFUSESIZE_MAX                         3.140f
88 #define EXPP_MAT_SPECSMOOTH_MIN                  0.0f
89 #define EXPP_MAT_SPECSMOOTH_MAX                  1.0f
90 #define EXPP_MAT_DIFFUSESMOOTH_MIN                       0.0f
91 #define EXPP_MAT_DIFFUSESMOOTH_MAX                       1.0f
92 #define EXPP_MAT_DIFFUSE_DARKNESS_MIN                    0.0f
93 #define EXPP_MAT_DIFFUSE_DARKNESS_MAX                    2.0f
94 #define EXPP_MAT_REFRACINDEX_MIN                         1.0f
95 #define EXPP_MAT_REFRACINDEX_MAX                         10.0f
96 #define EXPP_MAT_RMS_MIN                         0.0f
97 #define EXPP_MAT_RMS_MAX                         0.4f
98 /* End shader settings */
99
100 #define EXPP_MAT_ZOFFS_MIN                       0.0
101 #define EXPP_MAT_ZOFFS_MAX                      10.0
102 #define EXPP_MAT_HALOSIZE_MIN                    0.0
103 #define EXPP_MAT_HALOSIZE_MAX            100.0
104 #define EXPP_MAT_FLARESIZE_MIN           0.1f
105 #define EXPP_MAT_FLARESIZE_MAX          25.0
106 #define EXPP_MAT_FLAREBOOST_MIN          0.1f
107 #define EXPP_MAT_FLAREBOOST_MAX         10.0
108 #define EXPP_MAT_SUBSIZE_MIN                     0.1f
109 #define EXPP_MAT_SUBSIZE_MAX                    25.0
110
111 #define EXPP_MAT_HARD_MIN                                1
112 #define EXPP_MAT_HARD_MAX                511    /* 127 with MODE HALO ON */
113 #define EXPP_MAT_HALOSEED_MIN            0
114 #define EXPP_MAT_HALOSEED_MAX    255
115 #define EXPP_MAT_NFLARES_MIN             1
116 #define EXPP_MAT_NFLARES_MAX            32
117 #define EXPP_MAT_FLARESEED_MIN   0
118 #define EXPP_MAT_FLARESEED_MAX 255
119 #define EXPP_MAT_NSTARS_MIN                      3
120 #define EXPP_MAT_NSTARS_MAX                     50
121 #define EXPP_MAT_NLINES_MIN                      0
122 #define EXPP_MAT_NLINES_MAX              250
123 #define EXPP_MAT_NRINGS_MIN                      0
124 #define EXPP_MAT_NRINGS_MAX                     24
125
126 #define EXPP_MAT_RAYMIRR_MIN                     0.0
127 #define EXPP_MAT_RAYMIRR_MAX                     1.0
128 #define EXPP_MAT_MIRRDEPTH_MIN                   0
129 #define EXPP_MAT_MIRRDEPTH_MAX                   10
130 #define EXPP_MAT_FRESNELMIRR_MIN                        0.0
131 #define EXPP_MAT_FRESNELMIRR_MAX                        5.0
132 #define EXPP_MAT_FRESNELMIRRFAC_MIN                     1.0
133 #define EXPP_MAT_FRESNELMIRRFAC_MAX                     5.0
134 #define EXPP_MAT_RAYMIRRGLOSS_MIN                        0.0
135 #define EXPP_MAT_RAYMIRRGLOSS_MAX                        1.0
136 #define EXPP_MAT_RAYMIRRGLOSSSAMPLES_MIN         0
137 #define EXPP_MAT_RAYMIRRGLOSSSAMPLES_MAX         1024
138 #define EXPP_MAT_RAYTRANSPGLOSS_MIN                      0.0
139 #define EXPP_MAT_RAYTRANSPGLOSS_MAX                      1.0
140 #define EXPP_MAT_RAYTRANSPGLOSSSAMPLES_MIN       0
141 #define EXPP_MAT_RAYTRANSPGLOSSSAMPLES_MAX       1024
142 #define EXPP_MAT_FILTER_MIN                     0.0
143 #define EXPP_MAT_FILTER_MAX                     1.0
144 #define EXPP_MAT_TRANSLUCENCY_MIN                       0.0
145 #define EXPP_MAT_TRANSLUCENCY_MAX                       1.0
146 #define EXPP_MAT_ZOFFS_MIN                              0.0
147 #define EXPP_MAT_ZOFFS_MAX                              10.0
148 #define EXPP_MAT_IOR_MIN                                1.0
149 #define EXPP_MAT_IOR_MAX                                3.0
150 #define EXPP_MAT_TRANSDEPTH_MIN                         0
151 #define EXPP_MAT_TRANSDEPTH_MAX                         10
152 #define EXPP_MAT_FRESNELTRANS_MIN                       0.0
153 #define EXPP_MAT_FRESNELTRANS_MAX                       5.0
154 #define EXPP_MAT_FRESNELTRANSFAC_MIN                    1.0
155 #define EXPP_MAT_FRESNELTRANSFAC_MAX                    5.0
156 #define EXPP_MAT_SPECTRANS_MIN                          0.0
157 #define EXPP_MAT_SPECTRANS_MAX                          1.0
158 #define EXPP_MAT_MIRRTRANSADD_MIN                       0.0
159 #define EXPP_MAT_MIRRTRANSADD_MAX                       1.0
160 #define EXPP_MAT_COLORBAND_FACTOR_MIN           0.0
161 #define EXPP_MAT_COLORBAND_FACTOR_MAX           1.0
162
163 /* closure values for getColorComponent()/setColorComponent() */
164
165 #define EXPP_MAT_COMP_R         0
166 #define EXPP_MAT_COMP_G         1
167 #define EXPP_MAT_COMP_B         2
168 #define EXPP_MAT_COMP_SPECR     3
169 #define EXPP_MAT_COMP_SPECG     4
170 #define EXPP_MAT_COMP_SPECB     5
171 #define EXPP_MAT_COMP_MIRR      6
172 #define EXPP_MAT_COMP_MIRG      7
173 #define EXPP_MAT_COMP_MIRB      8
174 #define EXPP_MAT_COMP_SSSR      9
175 #define EXPP_MAT_COMP_SSSG      10
176 #define EXPP_MAT_COMP_SSSB      11
177
178
179 #define IPOKEY_RGB          0
180 #define IPOKEY_ALPHA        1 
181 #define IPOKEY_HALOSIZE     2 
182 #define IPOKEY_MODE         3
183 #define IPOKEY_ALLCOLOR     10
184 #define IPOKEY_ALLMIRROR    14
185 #define IPOKEY_OFS          12
186 #define IPOKEY_SIZE         13
187 #define IPOKEY_ALLMAPPING   11
188
189 /* SSS Settings */
190 #define EXPP_MAT_SSS_SCALE_MIN                  0.001
191 #define EXPP_MAT_SSS_SCALE_MAX                  1000.0
192 #define EXPP_MAT_SSS_RADIUS_MIN                 0.0
193 #define EXPP_MAT_SSS_RADIUS_MAX                 10000.0
194 #define EXPP_MAT_SSS_IOR_MIN                    0.1
195 #define EXPP_MAT_SSS_IOR_MAX                    2.0
196 #define EXPP_MAT_SSS_ERROR_MIN                  0.0
197 #define EXPP_MAT_SSS_ERROR_MAX                  1.0
198 #define EXPP_MAT_SSS_FRONT_MIN                  0.0
199 #define EXPP_MAT_SSS_FRONT_MAX                  2.0
200 #define EXPP_MAT_SSS_BACK_MIN                   0.0
201 #define EXPP_MAT_SSS_BACK_MAX                   10.0
202
203
204 /*****************************************************************************/
205 /* Python API function prototypes for the Material module.                   */
206 /*****************************************************************************/
207 static PyObject *M_Material_New( PyObject * self, PyObject * args,
208                                  PyObject * keywords );
209 static PyObject *M_Material_Get( PyObject * self, PyObject * args );
210
211 /*****************************************************************************/
212 /* The following string definitions are used for documentation strings.  In  */
213 /* Python these will be written to the console when doing a                  */
214 /* Blender.Material.__doc__                                                  */
215 /*****************************************************************************/
216 static char M_Material_doc[] = "The Blender Material module";
217
218 static char M_Material_New_doc[] =
219         "(name) - return a new material called 'name'\n\
220 () - return a new material called 'Mat'";
221
222 static char M_Material_Get_doc[] =
223         "(name) - return the material called 'name', None if not found.\n\
224 () - return a list of all materials in the current scene.";
225
226 /*****************************************************************************/
227 /* Python method structure definition for Blender.Material module:           */
228 /*****************************************************************************/
229 struct PyMethodDef M_Material_methods[] = {
230         {"New", ( PyCFunction ) M_Material_New, METH_VARARGS | METH_KEYWORDS,
231          M_Material_New_doc},
232         {"Get", M_Material_Get, METH_VARARGS, M_Material_Get_doc},
233         {"get", M_Material_Get, METH_VARARGS, M_Material_Get_doc},
234         {NULL, NULL, 0, NULL}
235 };
236
237 /*****************************************************************************/
238 /* Function:    M_Material_New                                               */
239 /* Python equivalent:           Blender.Material.New                             */
240 /*****************************************************************************/
241 static PyObject *M_Material_New( PyObject * self, PyObject * args,
242                                  PyObject * keywords )
243 {
244         char *name = "Mat";
245         static char *kwlist[] = { "name", NULL };
246         BPy_Material *pymat; /* for Material Data object wrapper in Python */
247         Material *blmat; /* for actual Material Data we create in Blender */
248         char buf[21];
249
250         if( !PyArg_ParseTupleAndKeywords
251             ( args, keywords, "|s", kwlist, &name ) )
252                 return ( EXPP_ReturnPyObjError
253                          ( PyExc_AttributeError,
254                            "expected string or nothing as argument" ) );
255
256         if( strcmp( name, "Mat" ) != 0 )        /* use gave us a name ? */
257                 PyOS_snprintf( buf, sizeof( buf ), "%s", name );
258
259         blmat = add_material( name );   /* first create the Material Data in Blender */
260
261         if( blmat )             /* now create the wrapper obj in Python */
262                 pymat = ( BPy_Material * ) Material_CreatePyObject( blmat );
263         else
264                 return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
265                                                 "couldn't create Material Data in Blender" ) );
266
267         blmat->id.us = 0;       /* was incref'ed by add_material() above */
268
269         if( pymat == NULL )
270                 return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
271                                                 "couldn't create Material Data object" ) );
272
273         return ( PyObject * ) pymat;
274 }
275
276 /*****************************************************************************/
277 /* Function:    M_Material_Get   */
278 /* Python equivalent:   Blender.Material.Get */
279 /* Description:         Receives a string and returns the material whose */
280 /*                      name matches the string.        If no argument is */
281 /*                      passed in, a list with all materials in the      */
282 /*                      current scene is returned.                       */
283 /*****************************************************************************/
284 static PyObject *M_Material_Get( PyObject * self, PyObject * args )
285 {
286         char *name = NULL;
287         Material *mat_iter;
288
289         if( !PyArg_ParseTuple( args, "|s", &name ) )
290                 return ( EXPP_ReturnPyObjError( PyExc_TypeError,
291                                                 "expected string argument (or nothing)" ) );
292
293         if( name ) {            /* (name) - Search material by name */
294
295                 mat_iter = ( Material * ) GetIdFromList( &( G.main->mat ), name );
296
297                 if( mat_iter == NULL ) { /* Requested material doesn't exist */
298                         char error_msg[64];
299                         PyOS_snprintf( error_msg, sizeof( error_msg ),
300                                        "Material \"%s\" not found", name );
301                         return EXPP_ReturnPyObjError( PyExc_NameError,
302                                                       error_msg );
303                 }
304
305                 return Material_CreatePyObject( mat_iter );
306         }
307
308         else {                  /* () - return a list with all materials in the scene */
309                 int index = 0;
310                 PyObject *matlist, *pyobj;
311         
312                 matlist = PyList_New( BLI_countlist( &( G.main->mat ) ) );
313
314                 if( !matlist )
315                         return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
316                                                         "couldn't create PyList" ) );
317                 
318                 mat_iter = G.main->mat.first;
319                 while( mat_iter ) {
320                         pyobj = Material_CreatePyObject( mat_iter );
321
322                         if( !pyobj ) {
323                                 Py_DECREF(matlist);
324                                 return ( EXPP_ReturnPyObjError
325                                          ( PyExc_MemoryError,
326                                            "couldn't create PyObject" ) );
327                         }
328                         PyList_SET_ITEM( matlist, index, pyobj );
329
330                         mat_iter = mat_iter->id.next;
331                         index++;
332                 }
333
334                 return matlist;
335         }
336 }
337
338 static PyObject *Material_ModesDict( void )
339 {
340         PyObject *Modes = PyConstant_New(  );
341
342         if( Modes ) {
343                 BPy_constant *c = ( BPy_constant * ) Modes;
344
345                 PyConstant_Insert(c, "TRACEABLE", PyInt_FromLong(MA_TRACEBLE));
346                 PyConstant_Insert(c, "SHADOW", PyInt_FromLong(MA_SHADOW));
347                 PyConstant_Insert(c, "SHADOWBUF", PyInt_FromLong(MA_SHADBUF));
348                 PyConstant_Insert(c, "TANGENTSTR", PyInt_FromLong(MA_TANGENT_STR));
349                 PyConstant_Insert(c, "FULLOSA", PyInt_FromLong(MA_FULL_OSA));
350                 PyConstant_Insert(c, "RAYBIAS", PyInt_FromLong(MA_RAYBIAS));
351                 PyConstant_Insert(c, "TRANSPSHADOW", PyInt_FromLong(MA_SHADOW_TRA));
352                 PyConstant_Insert(c, "RAMPCOL", PyInt_FromLong(MA_RAMP_COL));
353                 PyConstant_Insert(c, "RAMPSPEC", PyInt_FromLong(MA_RAMP_SPEC));
354                 PyConstant_Insert(c, "SHADELESS", PyInt_FromLong(MA_SHLESS));
355                 PyConstant_Insert(c, "WIRE", PyInt_FromLong(MA_WIRE));
356                 PyConstant_Insert(c, "VCOL_LIGHT", PyInt_FromLong(MA_VERTEXCOL));
357                 PyConstant_Insert(c, "HALO", PyInt_FromLong(MA_HALO));
358                 PyConstant_Insert(c, "ZTRANSP", PyInt_FromLong(MA_ZTRA));
359                 PyConstant_Insert(c, "VCOL_PAINT", PyInt_FromLong(MA_VERTEXCOLP));
360                 PyConstant_Insert(c, "ZINVERT", PyInt_FromLong(MA_ZINV));
361                 PyConstant_Insert(c, "HALORINGS", PyInt_FromLong(MA_HALO_RINGS));
362                 PyConstant_Insert(c, "ENV", PyInt_FromLong(MA_ENV));
363                 PyConstant_Insert(c, "HALOLINES", PyInt_FromLong(MA_HALO_LINES));
364                 PyConstant_Insert(c, "ONLYSHADOW", PyInt_FromLong(MA_ONLYSHADOW));
365                 PyConstant_Insert(c, "HALOXALPHA", PyInt_FromLong(MA_HALO_XALPHA));
366                 PyConstant_Insert(c, "HALOSTAR", PyInt_FromLong(MA_STAR));
367                 PyConstant_Insert(c, "TEXFACE", PyInt_FromLong(MA_FACETEXTURE));
368                 PyConstant_Insert(c, "HALOTEX", PyInt_FromLong(MA_HALOTEX));
369                 PyConstant_Insert(c, "HALOPUNO", PyInt_FromLong(MA_HALOPUNO));
370                 PyConstant_Insert(c, "NOMIST", PyInt_FromLong(MA_NOMIST));
371                 PyConstant_Insert(c, "HALOSHADE", PyInt_FromLong(MA_HALO_SHADE));
372                 PyConstant_Insert(c, "HALOFLARE", PyInt_FromLong(MA_HALO_FLARE));
373                 PyConstant_Insert(c, "RADIO", PyInt_FromLong(MA_RADIO));
374                 PyConstant_Insert(c, "RAYMIRROR", PyInt_FromLong(MA_RAYMIRROR));
375                 PyConstant_Insert(c, "ZTRA", PyInt_FromLong(MA_ZTRA));
376                 PyConstant_Insert(c, "RAYTRANSP", PyInt_FromLong(MA_RAYTRANSP));
377                 PyConstant_Insert(c, "TANGENT_V", PyInt_FromLong(MA_TANGENT_V));
378                 PyConstant_Insert(c, "NMAP_TS", PyInt_FromLong(MA_NORMAP_TANG));
379                 PyConstant_Insert(c, "GROUP_EXCLUSIVE", PyInt_FromLong(MA_GROUP_NOLAY));
380                 PyConstant_Insert(c, "TEXFACE_ALPHA", PyInt_FromLong(MA_FACETEXTURE_ALPHA));
381                 
382         }
383
384         return Modes;
385 }
386
387
388 static PyObject *Material_ShadersDict( void )
389 {
390         PyObject *Shaders = PyConstant_New(  );
391
392         if( Shaders ) {
393                 BPy_constant *c = ( BPy_constant * ) Shaders;
394
395                 PyConstant_Insert(c, "DIFFUSE_LAMBERT", PyInt_FromLong(MA_DIFF_LAMBERT));
396                 PyConstant_Insert(c, "DIFFUSE_ORENNAYAR", PyInt_FromLong(MA_DIFF_ORENNAYAR));
397                 PyConstant_Insert(c, "DIFFUSE_TOON", PyInt_FromLong(MA_DIFF_TOON));
398                 PyConstant_Insert(c, "DIFFUSE_MINNAERT", PyInt_FromLong(MA_DIFF_MINNAERT));
399                 PyConstant_Insert(c, "SPEC_COOKTORR", PyInt_FromLong(MA_SPEC_COOKTORR));
400                 PyConstant_Insert(c, "SPEC_PHONG", PyInt_FromLong(MA_SPEC_PHONG));
401                 PyConstant_Insert(c, "SPEC_BLINN", PyInt_FromLong(MA_SPEC_BLINN));
402                 PyConstant_Insert(c, "SPEC_TOON", PyInt_FromLong(MA_SPEC_TOON));
403                 PyConstant_Insert(c, "SPEC_WARDISO", PyInt_FromLong(MA_SPEC_WARDISO));
404
405         }
406
407         return Shaders;
408 }
409
410 static PyObject *Material_ColorRampMethodsDict( void )
411 {
412         PyObject *Methods = PyConstant_New(  );
413         if( Methods ) {
414                 BPy_constant *c = (BPy_constant * ) Methods;
415
416                 PyConstant_Insert(c, "BLEND", PyInt_FromLong(MA_RAMP_BLEND));
417                 PyConstant_Insert(c, "MIX", PyInt_FromLong(MA_RAMP_BLEND)); /* This one is added to solve confusion between Blend-Mix name. */
418                 PyConstant_Insert(c, "ADD", PyInt_FromLong(MA_RAMP_ADD));
419                 PyConstant_Insert(c, "MULT", PyInt_FromLong(MA_RAMP_MULT));
420                 PyConstant_Insert(c, "SUB", PyInt_FromLong(MA_RAMP_SUB));
421                 PyConstant_Insert(c, "SCREEN", PyInt_FromLong(MA_RAMP_SCREEN));
422                 PyConstant_Insert(c, "DIV", PyInt_FromLong(MA_RAMP_DIV));
423                 PyConstant_Insert(c, "DIFF", PyInt_FromLong(MA_RAMP_DIFF));
424                 PyConstant_Insert(c, "DARK", PyInt_FromLong(MA_RAMP_DARK));
425                 PyConstant_Insert(c, "LIGHT", PyInt_FromLong(MA_RAMP_LIGHT));
426                 PyConstant_Insert(c, "OVERLAY", PyInt_FromLong(MA_RAMP_OVERLAY));
427                 PyConstant_Insert(c, "DODGE", PyInt_FromLong(MA_RAMP_DODGE));
428                 PyConstant_Insert(c, "BURN", PyInt_FromLong(MA_RAMP_BURN));
429                 PyConstant_Insert(c, "HUE", PyInt_FromLong(MA_RAMP_HUE));
430                 PyConstant_Insert(c, "SAT", PyInt_FromLong(MA_RAMP_SAT));
431                 PyConstant_Insert(c, "VAL", PyInt_FromLong(MA_RAMP_VAL));
432                 PyConstant_Insert(c, "COLOR", PyInt_FromLong(MA_RAMP_COLOR));
433
434         }
435         return Methods;
436 }
437
438 static PyObject *Material_ColorRampInputDict( void )
439 {
440         PyObject *Inputs = PyConstant_New(  );
441         if( Inputs ) {
442                 BPy_constant *c = (BPy_constant * ) Inputs;
443
444                 PyConstant_Insert(c, "SHADER", PyInt_FromLong(MA_RAMP_IN_SHADER));
445                 PyConstant_Insert(c, "ENERGY", PyInt_FromLong(MA_RAMP_IN_ENERGY));
446                 PyConstant_Insert(c, "NORMAL", PyInt_FromLong(MA_RAMP_IN_NOR));
447                 PyConstant_Insert(c, "RESULT", PyInt_FromLong(MA_RAMP_IN_RESULT));
448         }
449         return Inputs;
450 }
451
452 /*****************************************************************************/
453 /* Function:    Material_Init */
454 /*****************************************************************************/
455 PyObject *Material_Init( void )
456 {
457         PyObject *submodule, *Modes, *Shaders, *ColorbandInput, *ColorbandMethod;
458
459         if( PyType_Ready( &Material_Type ) < 0)
460                 return NULL;
461
462         Modes = Material_ModesDict(  );
463         Shaders = Material_ShadersDict(  );
464         ColorbandMethod = Material_ColorRampMethodsDict(  );
465         ColorbandInput = Material_ColorRampInputDict(  );
466
467         submodule = Py_InitModule3( "Blender.Material",
468                                     M_Material_methods, M_Material_doc );
469
470         if( Modes )
471                 PyModule_AddObject( submodule, "Modes", Modes );
472         if( Shaders )
473                 PyModule_AddObject( submodule, "Shaders", Shaders );
474         if( ColorbandMethod )
475                 PyModule_AddObject( submodule, "ColorbandMethod", ColorbandMethod );
476         if( ColorbandInput )
477                 PyModule_AddObject( submodule, "ColorbandInput", ColorbandInput );
478         
479         PyModule_AddIntConstant( submodule, "RGB", IPOKEY_RGB );
480         PyModule_AddIntConstant( submodule, "ALPHA", IPOKEY_ALPHA );
481         PyModule_AddIntConstant( submodule, "HALOSIZE", IPOKEY_HALOSIZE );
482         PyModule_AddIntConstant( submodule, "MODE", IPOKEY_MODE );
483         PyModule_AddIntConstant( submodule, "ALLCOLOR", IPOKEY_ALLCOLOR );
484         PyModule_AddIntConstant( submodule, "ALLMIRROR", IPOKEY_ALLMIRROR );
485         PyModule_AddIntConstant( submodule, "OFS", IPOKEY_OFS );
486         PyModule_AddIntConstant( submodule, "SIZE", IPOKEY_SIZE );
487         PyModule_AddIntConstant( submodule, "ALLMAPPING", IPOKEY_ALLMAPPING );
488
489         return ( submodule );
490 }
491
492 /***************************/
493 /*** The Material PyType ***/
494 /***************************/
495
496 static PyObject *Matr_oldsetAdd( BPy_Material * self, PyObject * args );
497 static PyObject *Matr_oldsetAlpha( BPy_Material * self, PyObject * args );
498 static PyObject *Matr_oldsetAmb( BPy_Material * self, PyObject * args );
499 static PyObject *Matr_oldsetEmit( BPy_Material * self, PyObject * args );
500 static PyObject *Matr_oldsetFilter( BPy_Material * self, PyObject * args );
501 static PyObject *Matr_oldsetFlareBoost( BPy_Material * self, PyObject * args );
502 static PyObject *Matr_oldsetFlareSeed( BPy_Material * self, PyObject * args );
503 static PyObject *Matr_oldsetFlareSize( BPy_Material * self, PyObject * args );
504 static PyObject *Matr_oldsetFresnelMirr( BPy_Material * self, PyObject * args );
505 static PyObject *Matr_oldsetFresnelMirrFac( BPy_Material * self, PyObject * args );
506 static PyObject *Matr_oldsetFresnelTrans( BPy_Material * self, PyObject * args );
507 static PyObject *Matr_oldsetFresnelTransFac( BPy_Material * self, PyObject * args );
508 static PyObject *Matr_oldsetHaloSeed( BPy_Material * self, PyObject * args );
509 static PyObject *Matr_oldsetHaloSize( BPy_Material * self, PyObject * args );
510 static PyObject *Matr_oldsetHardness( BPy_Material * self, PyObject * args );
511 static PyObject *Matr_oldsetIOR( BPy_Material * self, PyObject * args );
512 static PyObject *Matr_oldsetNFlares( BPy_Material * self, PyObject * args );
513 static PyObject *Matr_oldsetNLines( BPy_Material * self, PyObject * args );
514 static PyObject *Matr_oldsetNRings( BPy_Material * self, PyObject * args );
515 static PyObject *Matr_oldsetNStars( BPy_Material * self, PyObject * args );
516 static PyObject *Matr_oldsetRayMirr( BPy_Material * self, PyObject * args );
517 static PyObject *Matr_oldsetMirrDepth( BPy_Material * self, PyObject * args );
518 static PyObject *Matr_oldsetRef( BPy_Material * self, PyObject * args );
519 static PyObject *Matr_oldsetSpec( BPy_Material * self, PyObject * args );
520 static PyObject *Matr_oldsetSpecTransp( BPy_Material * self, PyObject * args );
521 static PyObject *Matr_oldsetSubSize( BPy_Material * self, PyObject * args );
522 static PyObject *Matr_oldsetTransDepth( BPy_Material * self, PyObject * args );
523 static PyObject *Matr_oldsetZOffset( BPy_Material * self, PyObject * args );
524 static PyObject *Matr_oldsetMode( BPy_Material * self, PyObject * args );
525 static PyObject *Matr_oldsetIpo( BPy_Material * self, PyObject * args );
526 static PyObject *Matr_oldsetRGBCol( BPy_Material * self, PyObject * args );
527 static PyObject *Matr_oldsetSpecCol( BPy_Material * self, PyObject * args );
528 static PyObject *Matr_oldsetSpecShader( BPy_Material * self, PyObject * args );
529 static PyObject *Matr_oldsetMirCol( BPy_Material * self, PyObject * args );
530 static PyObject *Matr_oldsetDiffuseShader( BPy_Material * self, PyObject * args );
531 static PyObject *Matr_oldsetRoughness( BPy_Material * self, PyObject * args );
532 static PyObject *Matr_oldsetSpecSize( BPy_Material * self, PyObject * args );
533 static PyObject *Matr_oldsetDiffuseSize( BPy_Material * self, PyObject * args );
534 static PyObject *Matr_oldsetSpecSmooth( BPy_Material * self, PyObject * args );
535 static PyObject *Matr_oldsetDiffuseSmooth( BPy_Material * self, PyObject * args );
536 static PyObject *Matr_oldsetDiffuseDarkness( BPy_Material * self, PyObject * args );
537 static PyObject *Matr_oldsetRefracIndex( BPy_Material * self, PyObject * args );
538 static PyObject *Matr_oldsetRms( BPy_Material * self, PyObject * args );
539 static PyObject *Matr_oldsetTranslucency( BPy_Material * self, PyObject * args );
540
541 static int Material_setIpo( BPy_Material * self, PyObject * value );
542
543 static int Material_setMode( BPy_Material * self, PyObject * value );
544 static int Material_setRGBCol( BPy_Material * self, PyObject * value );
545 static int Material_setSpecCol( BPy_Material * self, PyObject * value );
546 static int Material_setMirCol( BPy_Material * self, PyObject * value );
547 static int Material_setSssCol( BPy_Material * self, PyObject * value );
548 static int Material_setColorComponent( BPy_Material * self, PyObject * value,
549                                                         void * closure );
550 static int Material_setAmb( BPy_Material * self, PyObject * value );
551 static int Material_setEmit( BPy_Material * self, PyObject * value );
552 static int Material_setSpecTransp( BPy_Material * self, PyObject * value );
553 static int Material_setAlpha( BPy_Material * self, PyObject * value );
554 static int Material_setShadAlpha( BPy_Material * self, PyObject * value );
555 static int Material_setRef( BPy_Material * self, PyObject * value );
556 static int Material_setSpec( BPy_Material * self, PyObject * value );
557 static int Material_setZOffset( BPy_Material * self, PyObject * value );
558 static int Material_setLightGroup( BPy_Material * self, PyObject * value );
559 static int Material_setAdd( BPy_Material * self, PyObject * value );
560 static int Material_setHaloSize( BPy_Material * self, PyObject * value );
561 static int Material_setFlareSize( BPy_Material * self, PyObject * value );
562 static int Material_setFlareBoost( BPy_Material * self, PyObject * value );
563 static int Material_setSubSize( BPy_Material * self, PyObject * value );
564 static int Material_setHaloSeed( BPy_Material * self, PyObject * value );
565 static int Material_setFlareSeed( BPy_Material * self, PyObject * value );
566 static int Material_setHardness( BPy_Material * self, PyObject * value );
567 static int Material_setNFlares( BPy_Material * self, PyObject * value );
568 static int Material_setNStars( BPy_Material * self, PyObject * value );
569 static int Material_setNLines( BPy_Material * self, PyObject * value );
570 static int Material_setNRings( BPy_Material * self, PyObject * value );
571 static int Material_setRayMirr( BPy_Material * self, PyObject * value );
572 static int Material_setMirrDepth( BPy_Material * self, PyObject * value );
573 static int Material_setFresnelMirr( BPy_Material * self, PyObject * value );
574 static int Material_setFresnelMirrFac( BPy_Material * self, PyObject * value );
575 static int Material_setIOR( BPy_Material * self, PyObject * value );
576 static int Material_setTransDepth( BPy_Material * self, PyObject * value );
577 static int Material_setFresnelTrans( BPy_Material * self, PyObject * value );
578 static int Material_setFresnelTransFac( BPy_Material * self, PyObject * value );
579 static int Material_setGlossMirr( BPy_Material * self, PyObject * value );
580 static int Material_setGlossMirrSamples( BPy_Material * self, PyObject * value );
581 static int Material_setGlossTrans( BPy_Material * self, PyObject * value );
582 static int Material_setGlossTransSamples( BPy_Material * self, PyObject * value );
583 static int Material_setRigidBodyFriction( BPy_Material * self, PyObject * value );
584 static int Material_setRigidBodyRestitution( BPy_Material * self, PyObject * value );
585
586 static int Material_setSpecShader( BPy_Material * self, PyObject * value );
587 static int Material_setDiffuseShader( BPy_Material * self, PyObject * value );
588 static int Material_setRoughness( BPy_Material * self, PyObject * value );
589 static int Material_setSpecSize( BPy_Material * self, PyObject * value );
590 static int Material_setDiffuseSize( BPy_Material * self, PyObject * value );
591 static int Material_setSpecSmooth( BPy_Material * self, PyObject * value );
592 static int Material_setDiffuseSmooth( BPy_Material * self, PyObject * value );
593 static int Material_setDiffuseDarkness( BPy_Material * self, PyObject * value );
594 static int Material_setRefracIndex( BPy_Material * self, PyObject * value );
595 static int Material_setRms( BPy_Material * self, PyObject * value );
596 static int Material_setFilter( BPy_Material * self, PyObject * value );
597 static int Material_setTranslucency( BPy_Material * self, PyObject * value );
598
599 static int Material_setSssEnable( BPy_Material * self, PyObject * value );
600 static int Material_setSssScale( BPy_Material * self, PyObject * value );
601 static int Material_setSssRadius( BPy_Material * self, PyObject * value, void * type );
602 static int Material_setSssIOR( BPy_Material * self, PyObject * value );
603 static int Material_setSssError( BPy_Material * self, PyObject * value );
604 static int Material_setSssColorBlend( BPy_Material * self, PyObject * value );
605 static int Material_setSssTexScatter( BPy_Material * self, PyObject * value );
606 static int Material_setSssFront( BPy_Material * self, PyObject * value );
607 static int Material_setSssBack( BPy_Material * self, PyObject * value );
608 static int Material_setSssBack( BPy_Material * self, PyObject * value );
609 static int Material_setTexChannel( BPy_Material * self, PyObject * value );
610 static int Material_setTextures( BPy_Material * self, PyObject * value );
611
612 static PyObject *Material_getColorComponent( BPy_Material * self,
613                                                         void * closure );
614
615 /*static int Material_setSeptex( BPy_Material * self, PyObject * value );
616   static PyObject *Material_getSeptex( BPy_Material * self );*/
617
618 /*****************************************************************************/
619 /* Python BPy_Material methods declarations: */
620 /*****************************************************************************/
621 static PyObject *Material_getIpo( BPy_Material * self );
622 static PyObject *Material_getMode( BPy_Material * self );
623 static PyObject *Material_getRGBCol( BPy_Material * self );
624 /*static PyObject *Material_getAmbCol(BPy_Material *self);*/
625 static PyObject *Material_getSpecCol( BPy_Material * self );
626 static PyObject *Material_getMirCol( BPy_Material * self );
627 static PyObject *Material_getSssCol( BPy_Material * self );
628 static PyObject *Material_getAmb( BPy_Material * self );
629 static PyObject *Material_getEmit( BPy_Material * self );
630 static PyObject *Material_getAlpha( BPy_Material * self );
631 static PyObject *Material_getShadAlpha( BPy_Material * self );
632 static PyObject *Material_getRef( BPy_Material * self );
633 static PyObject *Material_getSpec( BPy_Material * self );
634 static PyObject *Material_getSpecTransp( BPy_Material * self );
635 static PyObject *Material_getAdd( BPy_Material * self );
636 static PyObject *Material_getZOffset( BPy_Material * self );
637 static PyObject *Material_getLightGroup( BPy_Material * self );
638 static PyObject *Material_getHaloSize( BPy_Material * self );
639 static PyObject *Material_getHaloSeed( BPy_Material * self );
640 static PyObject *Material_getFlareSize( BPy_Material * self );
641 static PyObject *Material_getFlareSeed( BPy_Material * self );
642 static PyObject *Material_getFlareBoost( BPy_Material * self );
643 static PyObject *Material_getSubSize( BPy_Material * self );
644 static PyObject *Material_getHardness( BPy_Material * self );
645 static PyObject *Material_getNFlares( BPy_Material * self );
646 static PyObject *Material_getNStars( BPy_Material * self );
647 static PyObject *Material_getNLines( BPy_Material * self );
648 static PyObject *Material_getNRings( BPy_Material * self );
649 /* Shader settings */
650 static PyObject *Material_getSpecShader( BPy_Material * self );
651 static PyObject *Material_getDiffuseShader( BPy_Material * self );
652 static PyObject *Material_getRoughness( BPy_Material * self );
653 static PyObject *Material_getSpecSize( BPy_Material * self );
654 static PyObject *Material_getDiffuseSize( BPy_Material * self );
655 static PyObject *Material_getSpecSmooth( BPy_Material * self );
656 static PyObject *Material_getDiffuseSmooth( BPy_Material * self );
657 static PyObject *Material_getDiffuseDarkness( BPy_Material * self );
658 static PyObject *Material_getRefracIndex( BPy_Material * self );
659 static PyObject *Material_getRms( BPy_Material * self );
660
661 static PyObject *Material_getRayMirr( BPy_Material * self );
662 static PyObject *Material_getMirrDepth( BPy_Material * self );
663 static PyObject *Material_getFresnelMirr( BPy_Material * self );
664 static PyObject *Material_getFresnelMirrFac( BPy_Material * self );
665 static PyObject *Material_getIOR( BPy_Material * self );
666 static PyObject *Material_getTransDepth( BPy_Material * self );
667 static PyObject *Material_getFresnelTrans( BPy_Material * self );
668 static PyObject *Material_getFresnelTransFac( BPy_Material * self );
669 static PyObject *Material_getGlossMirr( BPy_Material * self );
670 static PyObject *Material_getGlossMirrSamples( BPy_Material * self );
671 static PyObject *Material_getGlossTrans( BPy_Material * self );
672 static PyObject *Material_getGlossTransSamples( BPy_Material * self );
673 static PyObject *Material_getRigidBodyFriction( BPy_Material * self );
674 static PyObject *Material_getRigidBodyRestitution( BPy_Material * self );
675
676 static PyObject *Material_getSssEnable( BPy_Material * self );
677 static PyObject *Material_getSssScale( BPy_Material * self );
678 static PyObject *Material_getSssRadius( BPy_Material * self, void * type );
679 static PyObject *Material_getSssIOR( BPy_Material * self );
680 static PyObject *Material_getSssError( BPy_Material * self );
681 static PyObject *Material_getSssColorBlend( BPy_Material * self );
682 static PyObject *Material_getSssTexScatter( BPy_Material * self );
683 static PyObject *Material_getSssFront( BPy_Material * self );
684 static PyObject *Material_getSssBack( BPy_Material * self );
685 static PyObject *Material_getSssBack( BPy_Material * self );
686
687 static PyObject *Material_getFilter( BPy_Material * self );
688 static PyObject *Material_getTranslucency( BPy_Material * self );
689 static PyObject *Material_getTextures( BPy_Material * self );
690 static PyObject *Material_getTexChannel( BPy_Material * self );
691 static PyObject *Material_clearIpo( BPy_Material * self );
692
693 static PyObject *Material_setTexture( BPy_Material * self, PyObject * args );
694 static PyObject *Material_clearTexture( BPy_Material * self, PyObject * value );
695
696 static PyObject *Material_getScriptLinks(BPy_Material *self, PyObject * value );
697 static PyObject *Material_addScriptLink(BPy_Material * self, PyObject * args );
698 static PyObject *Material_clearScriptLinks(BPy_Material *self, PyObject *args);
699
700 static PyObject *Material_insertIpoKey( BPy_Material * self, PyObject * args );
701 static PyObject *Material_getColorband( BPy_Material * self, void * type);
702 static int Material_setColorband( BPy_Material * self, PyObject * value, void * type);
703 static PyObject *Material_copy( BPy_Material * self );
704 static PyObject *Material_freeNodes( BPy_Material * self );
705
706 static PyObject *Material_getColorbandDiffuseFactor( BPy_Material * self );
707 static PyObject *Material_getColorbandSpecularFactor( BPy_Material * self );
708 static int Material_setColorbandDiffuseFactor ( BPy_Material * self, PyObject * value );
709 static int Material_setColorbandSpecularFactor ( BPy_Material * self, PyObject * value );
710 static PyObject *Material_getColorbandDiffuseMethod( BPy_Material * self );
711 static PyObject *Material_getColorbandSpecularMethod ( BPy_Material * self );
712 static int Material_setColorbandDiffuseMethod ( BPy_Material * self, PyObject * value);
713 static int Material_setColorbandSpecularMethod ( BPy_Material * self, PyObject * value);
714 static PyObject *Material_getColorbandDiffuseInput( BPy_Material * self );
715 static PyObject *Material_getColorbandSpecularInput( BPy_Material * self );
716 static int Material_setColorbandDiffuseInput ( BPy_Material * self, PyObject * value);
717 static int Material_setColorbandSpecularInput ( BPy_Material * self, PyObject * value);
718
719
720
721 /*****************************************************************************/
722 /* Python BPy_Material methods table: */
723 /*****************************************************************************/
724 static PyMethodDef BPy_Material_methods[] = {
725         /* name, method, flags, doc */
726         {"getName", ( PyCFunction ) GenericLib_getName, METH_NOARGS,
727          "() - Return Material's name"},
728         {"getIpo", ( PyCFunction ) Material_getIpo, METH_NOARGS,
729          "() - Return Material's ipo or None if not found"},
730         {"getMode", ( PyCFunction ) Material_getMode, METH_NOARGS,
731          "() - Return Material's mode flags"},
732         {"getRGBCol", ( PyCFunction ) Material_getRGBCol, METH_NOARGS,
733          "() - Return Material's rgb color triplet"},
734 /*      {"getAmbCol", (PyCFunction)Material_getAmbCol, METH_NOARGS,
735                         "() - Return Material's ambient color"},*/
736         {"getSpecCol", ( PyCFunction ) Material_getSpecCol, METH_NOARGS,
737          "() - Return Material's specular color"},
738         {"getMirCol", ( PyCFunction ) Material_getMirCol, METH_NOARGS,
739          "() - Return Material's mirror color"},
740         {"getAmb", ( PyCFunction ) Material_getAmb, METH_NOARGS,
741          "() - Return Material's ambient color blend factor"},
742         {"getEmit", ( PyCFunction ) Material_getEmit, METH_NOARGS,
743          "() - Return Material's emitting light intensity"},
744         {"getAlpha", ( PyCFunction ) Material_getAlpha, METH_NOARGS,
745          "() - Return Material's alpha (transparency) value"},
746         {"getRef", ( PyCFunction ) Material_getRef, METH_NOARGS,
747          "() - Return Material's reflectivity"},
748         {"getSpec", ( PyCFunction ) Material_getSpec, METH_NOARGS,
749          "() - Return Material's specularity"},
750         /* Shader specific settings */
751         {"getSpecShader", ( PyCFunction ) Material_getSpecShader, METH_NOARGS,
752          "() - Returns Material's specular shader" },
753         {"getDiffuseShader", ( PyCFunction ) Material_getDiffuseShader, METH_NOARGS,
754          "() - Returns Material's diffuse shader" },
755          {"getRoughness", ( PyCFunction ) Material_getRoughness, METH_NOARGS,
756          "() - Returns Material's Roughness (applies to the \"Oren Nayar\" Diffuse Shader only)" },
757         {"getSpecSize", ( PyCFunction ) Material_getSpecSize, METH_NOARGS,
758          "() - Returns Material's size of specular area (applies to the \"Toon\" Specular Shader only)" },
759         {"getDiffuseSize", ( PyCFunction ) Material_getDiffuseSize, METH_NOARGS,
760          "() - Returns Material's size of diffuse area (applies to the \"Toon\" Diffuse Shader only)" },
761         {"getSpecSmooth", ( PyCFunction ) Material_getSpecSmooth, METH_NOARGS,
762          "() - Returns Material's smoothing of specular area (applies to the \"Toon\" Diffuse Shader only)" },
763         {"getDiffuseSmooth", ( PyCFunction ) Material_getDiffuseSmooth, METH_NOARGS,
764          "() - Returns Material's smoothing of diffuse area (applies to the \"Toon\" Diffuse Shader only)" },
765         {"getDiffuseDarkness", ( PyCFunction ) Material_getDiffuseDarkness, METH_NOARGS,
766          "() - Returns Material's diffuse darkness (applies to the \"Minnaert\" Diffuse Shader only)" },
767         {"getRefracIndex", ( PyCFunction ) Material_getRefracIndex, METH_NOARGS,
768          "() - Returns Material's Index of Refraction (applies to the \"Blinn\" Specular Shader only)" },        
769         {"getRms", ( PyCFunction ) Material_getRms, METH_NOARGS,
770          "() - Returns Material's standard deviation of surface slope (applies to the \"WardIso\" Specular Shader only)" },
771         /* End shader settings */
772         {"getSpecTransp", ( PyCFunction ) Material_getSpecTransp, METH_NOARGS,
773          "() - Return Material's specular transparency"},
774         {"getAdd", ( PyCFunction ) Material_getAdd, METH_NOARGS,
775          "() - Return Material's glow factor"},
776         {"getZOffset", ( PyCFunction ) Material_getZOffset, METH_NOARGS,
777          "() - Return Material's artificial offset for faces"},
778         {"getHaloSize", ( PyCFunction ) Material_getHaloSize, METH_NOARGS,
779          "() - Return Material's halo size"},
780         {"getHaloSeed", ( PyCFunction ) Material_getHaloSeed, METH_NOARGS,
781          "() - Return Material's seed for random ring dimension and line "
782          "location in halos"},
783         {"getFlareSize", ( PyCFunction ) Material_getFlareSize, METH_NOARGS,
784          "() - Return Material's (flare size)/(halo size) factor"},
785         {"getFlareSeed", ( PyCFunction ) Material_getFlareSeed, METH_NOARGS,
786          "() - Return Material's flare offset in the seed table"},
787         {"getFlareBoost", ( PyCFunction ) Material_getFlareBoost, METH_NOARGS,
788          "() - Return Material's flare boost"},
789         {"getSubSize", ( PyCFunction ) Material_getSubSize, METH_NOARGS,
790          "() - Return Material's dimension of subflare, dots and circles"},
791         {"getHardness", ( PyCFunction ) Material_getHardness, METH_NOARGS,
792          "() - Return Material's specular hardness"},
793         {"getNFlares", ( PyCFunction ) Material_getNFlares, METH_NOARGS,
794          "() - Return Material's number of flares in halo"},
795         {"getNStars", ( PyCFunction ) Material_getNStars, METH_NOARGS,
796          "() - Return Material's number of points in the halo stars"},
797         {"getNLines", ( PyCFunction ) Material_getNLines, METH_NOARGS,
798          "() - Return Material's number of lines in halo"},
799         {"getNRings", ( PyCFunction ) Material_getNRings, METH_NOARGS,
800          "() - Return Material's number of rings in halo"},
801         {"getRayMirr", ( PyCFunction ) Material_getRayMirr, METH_NOARGS,
802          "() - Return mount mirror"},
803         {"getMirrDepth", ( PyCFunction ) Material_getMirrDepth, METH_NOARGS,
804          "() - Return amount mirror depth"},
805         {"getFresnelMirr", ( PyCFunction ) Material_getFresnelMirr, METH_NOARGS,
806          "() - Return fresnel power for refractions"},
807         {"getFresnelMirrFac", ( PyCFunction ) Material_getFresnelMirrFac, METH_NOARGS,
808          "() - Return fresnel power for refractions factor"},
809         {"getRayTransGloss", ( PyCFunction ) Material_getGlossTrans, METH_NOARGS,
810          "() - Return amount refraction glossiness"},
811         {"getRayTransGlossSamples", ( PyCFunction ) Material_getGlossTransSamples, METH_NOARGS,
812          "() - Return number of sampels for transparent glossiness"},
813         {"getRayMirrGlossSamples", ( PyCFunction ) Material_getGlossMirrSamples, METH_NOARGS,
814          "() - Return number of sampels for mirror glossiness"},
815         {"getFilter", ( PyCFunction ) Material_getFilter, METH_NOARGS,
816          "() - Return the amount of filtering when transparent raytrace is enabled"},
817         {"getTranslucency", ( PyCFunction ) Material_getTranslucency, METH_NOARGS,
818          "() - Return the Translucency, the amount of diffuse shading of the back side"},
819         {"getIOR", ( PyCFunction ) Material_getIOR, METH_NOARGS,
820          "() - Return IOR"},
821         {"getTransDepth", ( PyCFunction ) Material_getTransDepth, METH_NOARGS,
822          "() - Return amount inter-refractions"},
823         {"getFresnelTrans", ( PyCFunction ) Material_getFresnelTrans, METH_NOARGS,
824          "() - Return fresnel power for refractions"},
825         {"getFresnelTransFac", ( PyCFunction ) Material_getFresnelTransFac, METH_NOARGS,
826          "() - Return fresnel power for refractions factor"},
827
828         {"getTextures", ( PyCFunction ) Material_getTextures, METH_NOARGS,
829          "() - Return Material's texture list as a tuple"},
830         {"setName", ( PyCFunction ) GenericLib_setName_with_method, METH_VARARGS,
831          "(s) - Change Material's name"},
832         {"setIpo", ( PyCFunction ) Matr_oldsetIpo, METH_VARARGS,
833          "(Blender Ipo) - Change Material's Ipo"},
834         {"clearIpo", ( PyCFunction ) Material_clearIpo, METH_NOARGS,
835          "(Blender Ipo) - Unlink Ipo from this Material"},
836         {"insertIpoKey", ( PyCFunction ) Material_insertIpoKey, METH_VARARGS,
837          "(Material Ipo Constant) - Insert IPO Key at current frame"},   
838         {"setMode", ( PyCFunction ) Matr_oldsetMode, METH_VARARGS,
839          "([s[,s]]) - Set Material's mode flag(s)"},
840         {"setRGBCol", ( PyCFunction ) Matr_oldsetRGBCol, METH_VARARGS,
841          "(f,f,f or [f,f,f]) - Set Material's rgb color triplet"},
842 /*      {"setAmbCol", (PyCFunction)Matr_oldsetAmbCol, METH_VARARGS,
843                         "(f,f,f or [f,f,f]) - Set Material's ambient color"},*/
844         {"setSpecCol", ( PyCFunction ) Matr_oldsetSpecCol, METH_VARARGS,
845          "(f,f,f or [f,f,f]) - Set Material's specular color"},
846          
847         /* Shader spesific settings */
848         {"setSpecShader", ( PyCFunction ) Matr_oldsetSpecShader, METH_VARARGS,
849          "(i) - Set the Material's specular shader" },
850         {"setDiffuseShader", ( PyCFunction ) Matr_oldsetDiffuseShader, METH_VARARGS,
851          "(i) - Set the Material's diffuse shader" },
852          {"setRoughness", ( PyCFunction ) Matr_oldsetRoughness, METH_VARARGS,
853          "(f) - Set the Material's Roughness (applies to the \"Oren Nayar\" Diffuse Shader only)" },
854         {"setSpecSize", ( PyCFunction ) Matr_oldsetSpecSize, METH_VARARGS,
855          "(f) - Set the Material's size of specular area (applies to the \"Toon\" Specular Shader only)" },
856         {"setDiffuseSize", ( PyCFunction ) Matr_oldsetDiffuseSize, METH_VARARGS,
857          "(f) - Set the Material's size of diffuse area (applies to the \"Toon\" Diffuse Shader only)" },
858         {"setSpecSmooth", ( PyCFunction ) Matr_oldsetSpecSmooth, METH_VARARGS,
859          "(f) - Set the Material's smoothing of specular area (applies to the \"Toon\" Specular Shader only)" },
860         {"setDiffuseSmooth", ( PyCFunction ) Matr_oldsetDiffuseSmooth, METH_VARARGS,
861          "(f) - Set the Material's smoothing of diffuse area (applies to the \"Toon\" Diffuse Shader only)" },
862         {"setDiffuseDarkness", ( PyCFunction ) Matr_oldsetDiffuseDarkness, METH_VARARGS,
863          "(f) - Set the Material's diffuse darkness (applies to the \"Minnaert\" Diffuse Shader only)" },
864         {"setRefracIndex", ( PyCFunction ) Matr_oldsetRefracIndex, METH_VARARGS,
865          "(f) - Set the Material's Index of Refraction (applies to the \"Blinn\" Specular Shader only)" },       
866         {"setRms", ( PyCFunction ) Matr_oldsetRms, METH_VARARGS,
867          "(f) - Set the Material's standard deviation of surface slope (applies to the \"WardIso\" Specular Shader only)" },
868         /* End shader settings */
869          
870         {"setMirCol", ( PyCFunction ) Matr_oldsetMirCol, METH_VARARGS,
871          "(f,f,f or [f,f,f]) - Set Material's mirror color"},
872         {"setAmb", ( PyCFunction ) Matr_oldsetAmb, METH_VARARGS,
873          "(f) - Set how much the Material's color is affected"
874          " by \nthe global ambient colors - [0.0, 1.0]"},
875         {"setEmit", ( PyCFunction ) Matr_oldsetEmit, METH_VARARGS,
876          "(f) - Set Material's emitting light intensity - [0.0, 1.0]"},
877         {"setAlpha", ( PyCFunction ) Matr_oldsetAlpha, METH_VARARGS,
878          "(f) - Set Material's alpha (transparency) - [0.0, 1.0]"},
879         {"setRef", ( PyCFunction ) Matr_oldsetRef, METH_VARARGS,
880          "(f) - Set Material's reflectivity - [0.0, 1.0]"},
881         {"setSpec", ( PyCFunction ) Matr_oldsetSpec, METH_VARARGS,
882          "(f) - Set Material's specularity - [0.0, 2.0]"},
883         {"setSpecTransp", ( PyCFunction ) Matr_oldsetSpecTransp, METH_VARARGS,
884          "(f) - Set Material's specular transparency - [0.0, 1.0]"},
885         {"setAdd", ( PyCFunction ) Matr_oldsetAdd, METH_VARARGS,
886          "(f) - Set Material's glow factor - [0.0, 1.0]"},
887         {"setZOffset", ( PyCFunction ) Matr_oldsetZOffset, METH_VARARGS,
888          "(f) - Set Material's artificial offset - [0.0, 10.0]"},
889         {"setHaloSize", ( PyCFunction ) Matr_oldsetHaloSize, METH_VARARGS,
890          "(f) - Set Material's halo size - [0.0, 100.0]"},
891         {"setHaloSeed", ( PyCFunction ) Matr_oldsetHaloSeed, METH_VARARGS,
892          "(i) - Set Material's halo seed - [0, 255]"},
893         {"setFlareSize", ( PyCFunction ) Matr_oldsetFlareSize, METH_VARARGS,
894          "(f) - Set Material's factor: (flare size)/(halo size) - [0.1, 25.0]"},
895         {"setFlareSeed", ( PyCFunction ) Matr_oldsetFlareSeed, METH_VARARGS,
896          "(i) - Set Material's flare seed - [0, 255]"},
897         {"setFlareBoost", ( PyCFunction ) Matr_oldsetFlareBoost, METH_VARARGS,
898          "(f) - Set Material's flare boost - [0.1, 10.0]"},
899         {"setSubSize", ( PyCFunction ) Matr_oldsetSubSize, METH_VARARGS,
900          "(f) - Set Material's dimension of subflare,"
901          " dots and circles - [0.1, 25.0]"},
902         {"setHardness", ( PyCFunction ) Matr_oldsetHardness, METH_VARARGS,
903          "(i) - Set Material's hardness - [1, 255 (127 if halo mode is ON)]"},
904         {"setNFlares", ( PyCFunction ) Matr_oldsetNFlares, METH_VARARGS,
905          "(i) - Set Material's number of flares in halo - [1, 32]"},
906         {"setNStars", ( PyCFunction ) Matr_oldsetNStars, METH_VARARGS,
907          "(i) - Set Material's number of stars in halo - [3, 50]"},
908         {"setNLines", ( PyCFunction ) Matr_oldsetNLines, METH_VARARGS,
909          "(i) - Set Material's number of lines in halo - [0, 250]"},
910         {"setNRings", ( PyCFunction ) Matr_oldsetNRings, METH_VARARGS,
911          "(i) - Set Material's number of rings in halo - [0, 24]"},
912         {"setRayMirr", ( PyCFunction ) Matr_oldsetRayMirr, METH_VARARGS,
913          "(f) - Set amount mirror - [0.0, 1.0]"},
914         {"setMirrDepth", ( PyCFunction ) Matr_oldsetMirrDepth, METH_VARARGS,
915          "(i) - Set amount inter-reflections - [0, 10]"},
916         {"setFresnelMirr", ( PyCFunction ) Matr_oldsetFresnelMirr, METH_VARARGS,
917          "(f) - Set fresnel power for mirror - [0.0, 5.0]"},
918         {"setFresnelMirrFac", ( PyCFunction ) Matr_oldsetFresnelMirrFac, METH_VARARGS,
919          "(f) - Set blend fac for mirror fresnel - [1.0, 5.0]"},
920         {"setRayTransGloss", ( PyCFunction ) Material_setGlossTrans, METH_VARARGS,
921          "(f) - Set amount refraction glossiness - [0.0, 1.0]"},
922         {"setRayTransGlossSamples", ( PyCFunction ) Material_setGlossTransSamples, METH_VARARGS,
923          "(i) - Set number transparent gloss samples - [1, 1024]"},
924         {"setRayMirrGlossSamples", ( PyCFunction ) Material_setGlossMirrSamples, METH_VARARGS,
925          "(i) - Set number mirror gloss samples - [1, 1024]"},
926         {"setFilter", ( PyCFunction ) Matr_oldsetFilter, METH_VARARGS,
927          "(f) - Set the amount of filtering when transparent raytrace is enabled"},
928         {"setTranslucency", ( PyCFunction ) Matr_oldsetTranslucency, METH_VARARGS,
929          "(f) - Set the Translucency, the amount of diffuse shading of the back side"},
930         {"setIOR", ( PyCFunction ) Matr_oldsetIOR, METH_VARARGS,
931          "(f) - Set IOR - [1.0, 3.0]"},
932         {"setTransDepth", ( PyCFunction ) Matr_oldsetTransDepth, METH_VARARGS,
933          "(i) - Set amount inter-refractions - [0, 10]"},
934         {"setFresnelTrans", ( PyCFunction ) Matr_oldsetFresnelTrans, METH_VARARGS,
935          "(f) - Set fresnel power for refractions - [0.0, 5.0]"},
936         {"setFresnelTransFac", ( PyCFunction ) Matr_oldsetFresnelTransFac, METH_VARARGS,
937          "(f) - Set fresnel power for refractions factor- [0.0, 5.0]"},
938         {"setTexture", ( PyCFunction ) Material_setTexture, METH_VARARGS,
939          "(n,tex,texco=0,mapto=0) - Set numbered texture to tex"},
940         {"clearTexture", ( PyCFunction ) Material_clearTexture, METH_O,
941          "(n) - Remove texture from numbered slot"},
942         {"getScriptLinks", ( PyCFunction ) Material_getScriptLinks, METH_O,
943          "(eventname) - Get a list of this material's scriptlinks (Text names) "
944          "of the given type\n"
945          "(eventname) - string: FrameChanged, Redraw or Render."},
946         {"addScriptLink", ( PyCFunction ) Material_addScriptLink, METH_VARARGS,
947          "(text, evt) - Add a new material scriptlink.\n"
948          "(text) - string: an existing Blender Text name;\n"
949          "(evt) string: FrameChanged, Redraw or Render."},
950         {"clearScriptLinks", ( PyCFunction ) Material_clearScriptLinks, METH_VARARGS,
951          "() - Delete all scriptlinks from this material.\n"
952          "([s1<,s2,s3...>]) - Delete specified scriptlinks from this material."},
953         {"__copy__", ( PyCFunction ) Material_copy, METH_NOARGS,
954          "() - Return a copy of the material."},
955         {"copy", ( PyCFunction ) Material_copy, METH_NOARGS,
956          "() - Return a copy of the material."},
957         {"freeNodes", ( PyCFunction ) Material_freeNodes, METH_NOARGS,
958          "() - Free this materials nodes."},
959         {NULL, NULL, 0, NULL}
960 };
961
962 /*****************************************************************************/
963 /* Python attributes get/set structure:                                      */
964 /*****************************************************************************/
965
966 static PyGetSetDef BPy_Material_getseters[] = {
967         GENERIC_LIB_GETSETATTR,
968         {"add",
969          (getter)Material_getAdd, (setter)Material_setAdd,
970          "Strength of the add effect",
971          NULL},
972         {"alpha",
973          (getter)Material_getAlpha, (setter)Material_setAlpha,
974          "Alpha setting ",
975          NULL},
976         {"shadAlpha",
977          (getter)Material_getShadAlpha, (setter)Material_setShadAlpha,
978          "Shadow Alpha setting",
979          NULL},
980         {"amb",
981          (getter)Material_getAmb, (setter)Material_setAmb,
982          "Amount of global ambient color material receives",
983          NULL},
984         {"diffuseDarkness",
985          (getter)Material_getDiffuseDarkness, (setter)Material_setDiffuseDarkness,
986          "Material's diffuse darkness (\"Minnaert\" diffuse shader only)",
987          NULL},
988         {"diffuseShader",
989          (getter)Material_getDiffuseShader, (setter)Material_setDiffuseShader,
990          "Diffuse shader type",
991          NULL},
992         {"diffuseSize",
993          (getter)Material_getDiffuseSize, (setter)Material_setDiffuseSize,
994          "Material's diffuse area size (\"Toon\" diffuse shader only)",
995          NULL},
996         {"diffuseSmooth",
997          (getter)Material_getDiffuseSmooth, (setter)Material_setDiffuseSmooth,
998          "Material's diffuse area smoothing (\"Toon\" diffuse shader only)",
999          NULL},
1000         {"emit",
1001          (getter)Material_getEmit, (setter)Material_setEmit,
1002          "Amount of light the material emits",
1003          NULL},
1004         {"filter",
1005          (getter)Material_getFilter, (setter)Material_setFilter,
1006          "Amount of filtering when transparent raytrace is enabled",
1007          NULL},
1008         {"flareBoost",
1009          (getter)Material_getFlareBoost, (setter)Material_setFlareBoost,
1010          "Flare's extra strength",
1011          NULL},
1012         {"flareSeed",
1013          (getter)Material_getFlareSeed, (setter)Material_setFlareSeed,
1014          "Offset in the flare seed table",
1015          NULL},
1016         {"flareSize",
1017          (getter)Material_getFlareSize, (setter)Material_setFlareSize,
1018          "Ratio of flare size to halo size",
1019          NULL},
1020         {"fresnelDepth",
1021          (getter)Material_getFresnelMirr, (setter)Material_setFresnelMirr,
1022          "Power of Fresnel for mirror reflection",
1023          NULL},
1024         {"fresnelDepthFac",
1025          (getter)Material_getFresnelMirrFac, (setter)Material_setFresnelMirrFac,
1026          "Blending factor for Fresnel mirror",
1027          NULL},
1028         {"fresnelTrans",
1029          (getter)Material_getFresnelTrans, (setter)Material_setFresnelTrans,
1030          "Power of Fresnel for transparency",
1031          NULL},
1032         {"fresnelTransFac",
1033          (getter)Material_getFresnelTransFac, (setter)Material_setFresnelTransFac,
1034          "Blending factor for Fresnel transparency",
1035          NULL},
1036          {"rbFriction",
1037          (getter)Material_getRigidBodyFriction, (setter)Material_setRigidBodyFriction,
1038          "Rigid Body Friction coefficient",
1039          NULL},
1040          {"rbRestitution",
1041          (getter)Material_getRigidBodyRestitution, (setter)Material_setRigidBodyRestitution,
1042          "Rigid Body Restitution coefficient",
1043          NULL},
1044
1045         {"haloSeed",
1046          (getter)Material_getHaloSeed, (setter)Material_setHaloSeed,
1047          "Randomizes halo ring dimension and line location",
1048          NULL},
1049         {"haloSize",
1050          (getter)Material_getHaloSize, (setter)Material_setHaloSize,
1051          "Dimension of the halo",
1052          NULL},
1053         {"hard",
1054          (getter)Material_getHardness, (setter)Material_setHardness,
1055          "Specularity hardness",
1056          NULL},
1057         {"IOR",
1058          (getter)Material_getIOR, (setter)Material_setIOR,
1059          "Angular index of refraction for raytrace",
1060          NULL},
1061         {"ipo",
1062          (getter)Material_getIpo, (setter)Material_setIpo,
1063          "Material Ipo data",
1064          NULL},
1065         {"mirCol",
1066          (getter)Material_getMirCol, (setter)Material_setMirCol,
1067          "Mirror RGB color triplet",
1068          NULL},
1069         {"mirR",
1070          (getter)Material_getColorComponent, (setter)Material_setColorComponent,
1071          "Mirror color red component",
1072          (void *) EXPP_MAT_COMP_MIRR },
1073         {"mirG",
1074          (getter)Material_getColorComponent, (setter)Material_setColorComponent,
1075          "Mirror color green component",
1076          (void *) EXPP_MAT_COMP_MIRG },
1077         {"mirB",
1078          (getter)Material_getColorComponent, (setter)Material_setColorComponent,
1079          "Mirror color blue component",
1080          (void *) EXPP_MAT_COMP_MIRB },
1081         {"sssCol",
1082          (getter)Material_getSssCol, (setter)Material_setSssCol,
1083          "Sss RGB color triplet",
1084          NULL},
1085         {"sssR",
1086          (getter)Material_getColorComponent, (setter)Material_setColorComponent,
1087          "SSS color red component",
1088          (void *) EXPP_MAT_COMP_SSSR },
1089         {"sssG",
1090          (getter)Material_getColorComponent, (setter)Material_setColorComponent,
1091          "SSS color green component",
1092          (void *) EXPP_MAT_COMP_SSSG },
1093         {"sssB",
1094          (getter)Material_getColorComponent, (setter)Material_setColorComponent,
1095          "SSS color blue component",
1096          (void *) EXPP_MAT_COMP_SSSB },
1097         {"mode",
1098          (getter)Material_getMode, (setter)Material_setMode,
1099          "Material mode bitmask",
1100          NULL},
1101         {"nFlares",
1102          (getter)Material_getNFlares, (setter)Material_setNFlares,
1103          "Number of subflares with halo",
1104          NULL},
1105         {"nLines",
1106          (getter)Material_getNLines, (setter)Material_setNLines,
1107          "Number of star-shaped lines with halo",
1108          NULL},
1109         {"nRings",
1110          (getter)Material_getNRings, (setter)Material_setNRings,
1111          "Number of rings with halo",
1112          NULL},
1113         {"nStars",
1114          (getter)Material_getNStars, (setter)Material_setNStars,
1115          "Number of star points with halo",
1116          NULL},
1117         {"rayMirr",
1118          (getter)Material_getRayMirr, (setter)Material_setRayMirr,
1119          "Mirror reflection amount for raytrace",
1120          NULL},
1121         {"rayMirrDepth",
1122          (getter)Material_getMirrDepth, (setter)Material_setMirrDepth,
1123          "Amount of raytrace inter-reflections",
1124          NULL},
1125         {"ref",
1126          (getter)Material_getRef, (setter)Material_setRef,
1127          "Amount of reflections (for shader)",
1128          NULL},
1129         {"refracIndex",
1130          (getter)Material_getRefracIndex, (setter)Material_setRefracIndex,
1131          "Material's Index of Refraction (applies to the \"Blinn\" Specular Shader only",
1132          NULL},
1133         {"glossMir",
1134          (getter)Material_getGlossMirr, (setter)Material_setGlossMirr,
1135          "Reflection glossiness",
1136          NULL},
1137         {"sampGlossMir",
1138          (getter)Material_getGlossMirrSamples, (setter)Material_setGlossMirrSamples,
1139          "Reflection glossiness",
1140          NULL},
1141         {"glossTra",
1142          (getter)Material_getGlossTrans, (setter)Material_setGlossTrans,
1143          "Refraction glossiness",
1144          NULL},
1145         {"sampGlossTra",
1146          (getter)Material_getGlossMirrSamples, (setter)Material_setGlossMirrSamples,
1147          "Refraction glossiness",
1148          NULL},
1149         {"rgbCol",
1150          (getter)Material_getRGBCol, (setter)Material_setRGBCol,
1151          "Diffuse RGB color triplet",
1152          NULL},
1153         {"rms",
1154          (getter)Material_getRms, (setter)Material_setRms,
1155          "Material's surface slope standard deviation (\"WardIso\" specular shader only)",
1156          NULL},
1157         {"roughness",
1158          (getter)Material_getRoughness, (setter)Material_setRoughness,
1159          "Material's roughness (\"Oren Nayar\" diffuse shader only)",
1160          NULL},
1161         {"spec",
1162          (getter)Material_getSpec, (setter)Material_setSpec,
1163          "Degree of specularity",
1164          NULL},
1165         {"specCol",
1166          (getter)Material_getSpecCol, (setter)Material_setSpecCol,
1167          "Specular RGB color triplet",
1168          NULL},
1169         {"specR",
1170          (getter)Material_getColorComponent, (setter)Material_setColorComponent,
1171          "Specular color red component",
1172          (void *) EXPP_MAT_COMP_SPECR },
1173         {"specG",
1174          (getter)Material_getColorComponent, (setter)Material_setColorComponent,
1175          "Specular color green component",
1176          (void *) EXPP_MAT_COMP_SPECG },
1177         {"specB",
1178          (getter)Material_getColorComponent, (setter)Material_setColorComponent,
1179          "Specular color blue component",
1180          (void *) EXPP_MAT_COMP_SPECB },
1181         {"specTransp",
1182          (getter)Material_getSpecTransp, (setter)Material_setSpecTransp,
1183          "Makes specular areas opaque on transparent materials",
1184          NULL},
1185         {"specShader",
1186          (getter)Material_getSpecShader, (setter)Material_setSpecShader,
1187          "Specular shader type",
1188          NULL},
1189         {"specSize",
1190          (getter)Material_getSpecSize, (setter)Material_setSpecSize,
1191          "Material's specular area size (\"Toon\" specular shader only)",
1192          NULL},
1193         {"specSmooth",
1194          (getter)Material_getSpecSmooth, (setter)Material_setSpecSmooth,
1195          "Sets the smoothness of specular toon area",
1196          NULL},
1197         {"subSize",
1198          (getter)Material_getSubSize, (setter)Material_setSubSize,
1199          "Dimension of subflares, dots and circles",
1200          NULL},
1201         {"transDepth",
1202          (getter)Material_getTransDepth, (setter)Material_setTransDepth,
1203          "Amount of refractions for raytrace",
1204          NULL},
1205         {"translucency",
1206          (getter)Material_getTranslucency, (setter)Material_setTranslucency,
1207          "Amount of diffuse shading of the back side",
1208          NULL},
1209         {"zOffset",
1210          (getter)Material_getZOffset, (setter)Material_setZOffset,
1211          "Artificial offset in the Z buffer (for Ztransp option)",
1212          NULL},
1213         {"lightGroup",
1214          (getter)Material_getLightGroup, (setter)Material_setLightGroup,
1215          "The light group for this material",
1216          NULL},
1217         {"enabledTextures",
1218          (getter)Material_getTexChannel, (setter)Material_setTexChannel,
1219          "Enabled texture channels for this material",
1220          NULL},
1221         {"R",
1222          (getter)Material_getColorComponent, (setter)Material_setColorComponent,
1223          "Diffuse color red component",
1224          (void *) EXPP_MAT_COMP_R },
1225         {"G",
1226          (getter)Material_getColorComponent, (setter)Material_setColorComponent,
1227          "Diffuse color green component",
1228          (void *) EXPP_MAT_COMP_G },
1229         {"B",
1230          (getter)Material_getColorComponent, (setter)Material_setColorComponent,
1231          "Diffuse color blue component",
1232          (void *) EXPP_MAT_COMP_B },
1233         {"colorbandDiffuse",
1234          (getter)Material_getColorband, (setter)Material_setColorband,
1235          "The diffuse colorband for this material",
1236          (void *) 0},
1237         {"colorbandSpecular",
1238          (getter)Material_getColorband, (setter)Material_setColorband,
1239          "The specular colorband for this material",
1240          (void *) 1},
1241         {"textures",
1242          (getter)Material_getTextures, (setter)Material_setTextures,
1243          "The Material's texture list as a tuple",
1244          NULL},
1245         {"colorbandSpecularFactor",
1246          (getter)Material_getColorbandSpecularFactor, (setter)Material_setColorbandSpecularFactor,
1247          "The specular colorband factor for this material",
1248          NULL},
1249         {"colorbandSpecularMethod",
1250          (getter)Material_getColorbandSpecularMethod, (setter)Material_setColorbandSpecularMethod,
1251          "The specular colorband method for this material",
1252          NULL},
1253         {"colorbandSpecularInput",
1254          (getter)Material_getColorbandSpecularInput, (setter)Material_setColorbandSpecularInput,
1255          "The specular colorband input for this material",
1256          NULL},
1257         {"colorbandDiffuseFactor",
1258          (getter)Material_getColorbandDiffuseFactor, (setter)Material_setColorbandDiffuseFactor,
1259          "The diffuse colorband factor for this material",
1260          NULL},
1261         {"colorbandDiffuseMethod",
1262          (getter)Material_getColorbandDiffuseMethod, (setter)Material_setColorbandDiffuseMethod,
1263          "The diffuse colorband method for this material",
1264          NULL},
1265         {"colorbandDiffuseInput",
1266          (getter)Material_getColorbandDiffuseInput, (setter)Material_setColorbandDiffuseInput,
1267          "The diffuse colorband input for this material",
1268          NULL},
1269
1270         /* SSS settings */
1271         {"enableSSS",
1272          (getter)Material_getSssEnable, (setter)Material_setSssEnable,
1273          "if true, SSS will be rendered for this material",
1274          NULL},
1275         {"sssScale",
1276          (getter)Material_getSssScale, (setter)Material_setSssScale,
1277          "object scale for sss",
1278          NULL},
1279         {"sssRadiusRed",
1280          (getter)Material_getSssRadius, (setter)Material_setSssRadius,
1281          "Mean red scattering path length",
1282          (void *) 0},
1283         {"sssRadiusGreen",
1284          (getter)Material_getSssRadius, (setter)Material_setSssRadius,
1285          "Mean red scattering path length",
1286          (void *) 1},
1287         {"sssRadiusBlue",
1288          (getter)Material_getSssRadius, (setter)Material_setSssRadius,
1289          "Mean red scattering path length",
1290          (void *) 2},
1291         {"sssIOR",
1292          (getter)Material_getSssIOR, (setter)Material_setSssIOR,
1293          "index of refraction",
1294          NULL},
1295         {"sssError",
1296          (getter)Material_getSssError, (setter)Material_setSssError,
1297          "Error",
1298          NULL},
1299         {"sssColorBlend",
1300          (getter)Material_getSssColorBlend, (setter)Material_setSssColorBlend,
1301          "Blend factor for SSS Colors",
1302          NULL},
1303         {"sssTextureScatter",
1304          (getter)Material_getSssTexScatter, (setter)Material_setSssTexScatter,
1305          "Texture scattering factor",
1306          NULL},
1307         {"sssFront",
1308          (getter)Material_getSssFront, (setter)Material_setSssFront,
1309          "Front scattering weight",
1310          NULL},
1311         {"sssBack",
1312          (getter)Material_getSssBack, (setter)Material_setSssBack,
1313          "Back scattering weight",
1314          NULL},
1315         {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
1316 };
1317
1318 /*****************************************************************************/
1319 /* Python Material_Type callback function prototypes: */
1320 /*****************************************************************************/
1321 static void Material_dealloc( BPy_Material * self );
1322 static int Material_compare( BPy_Material * a, BPy_Material * b);
1323 static PyObject *Material_repr( BPy_Material * self );
1324
1325 /*****************************************************************************/
1326 /* Python Material_Type structure definition:                                */
1327 /*****************************************************************************/
1328 PyTypeObject Material_Type = {
1329         PyObject_HEAD_INIT( NULL )  /* required py macro */
1330         0,                          /* ob_size */
1331         /*  For printing, in format "<module>.<name>" */
1332         "Blender Material",         /* char *tp_name; */
1333         sizeof( BPy_Material ),     /* int tp_basicsize; */
1334         0,                          /* tp_itemsize;  For allocation */
1335
1336         /* Methods to implement standard operations */
1337
1338         ( destructor ) Material_dealloc,/* destructor tp_dealloc; */
1339         NULL,                       /* printfunc tp_print; */
1340         NULL,                       /* getattrfunc tp_getattr; */
1341         NULL,                       /* setattrfunc tp_setattr; */
1342         ( cmpfunc ) Material_compare,/* cmpfunc tp_compare; */
1343         ( reprfunc ) Material_repr, /* reprfunc tp_repr; */
1344
1345         /* Method suites for standard classes */
1346
1347         NULL,                       /* PyNumberMethods *tp_as_number; */
1348         NULL,                       /* PySequenceMethods *tp_as_sequence; */
1349         NULL,                       /* PyMappingMethods *tp_as_mapping; */
1350
1351         /* More standard operations (here for binary compatibility) */
1352
1353         ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
1354         NULL,                       /* ternaryfunc tp_call; */
1355         NULL,                       /* reprfunc tp_str; */
1356         NULL,                       /* getattrofunc tp_getattro; */
1357         NULL,                       /* setattrofunc tp_setattro; */
1358
1359         /* Functions to access object as input/output buffer */
1360         NULL,                       /* PyBufferProcs *tp_as_buffer; */
1361
1362   /*** Flags to define presence of optional/expanded features ***/
1363         Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
1364
1365         NULL,                       /*  char *tp_doc;  Documentation string */
1366   /*** Assigned meaning in release 2.0 ***/
1367         /* call function for all accessible objects */
1368         NULL,                       /* traverseproc tp_traverse; */
1369
1370         /* delete references to contained objects */
1371         NULL,                       /* inquiry tp_clear; */
1372
1373   /***  Assigned meaning in release 2.1 ***/
1374   /*** rich comparisons ***/
1375         NULL,                       /* richcmpfunc tp_richcompare; */
1376
1377   /***  weak reference enabler ***/
1378         0,                          /* long tp_weaklistoffset; */
1379
1380   /*** Added in release 2.2 ***/
1381         /*   Iterators */
1382         NULL,                       /* getiterfunc tp_iter; */
1383         NULL,                       /* iternextfunc tp_iternext; */
1384
1385   /*** Attribute descriptor and subclassing stuff ***/
1386         BPy_Material_methods,       /* struct PyMethodDef *tp_methods; */
1387         NULL,                       /* struct PyMemberDef *tp_members; */
1388         BPy_Material_getseters,     /* struct PyGetSetDef *tp_getset; */
1389         NULL,                       /* struct _typeobject *tp_base; */
1390         NULL,                       /* PyObject *tp_dict; */
1391         NULL,                       /* descrgetfunc tp_descr_get; */
1392         NULL,                       /* descrsetfunc tp_descr_set; */
1393         0,                          /* long tp_dictoffset; */
1394         NULL,                       /* initproc tp_init; */
1395         NULL,                       /* allocfunc tp_alloc; */
1396         NULL,                       /* newfunc tp_new; */
1397         /*  Low-level free-memory routine */
1398         NULL,                       /* freefunc tp_free;  */
1399         /* For PyObject_IS_GC */
1400         NULL,                       /* inquiry tp_is_gc;  */
1401         NULL,                       /* PyObject *tp_bases; */
1402         /* method resolution order */
1403         NULL,                       /* PyObject *tp_mro;  */
1404         NULL,                       /* PyObject *tp_cache; */
1405         NULL,                       /* PyObject *tp_subclasses; */
1406         NULL,                       /* PyObject *tp_weaklist; */
1407         NULL
1408 };
1409
1410 /*****************************************************************************/
1411 /* Function:    Material_dealloc          */
1412 /* Description: This is a callback function for the BPy_Material type. It is */
1413 /*              the destructor function.                                 */
1414 /*****************************************************************************/
1415 static void Material_dealloc( BPy_Material * self )
1416 {
1417         Py_DECREF( self->col );
1418         Py_DECREF( self->amb );
1419         Py_DECREF( self->spec );
1420         Py_DECREF( self->mir );
1421         Py_DECREF( self->sss );
1422         PyObject_DEL( self );
1423 }
1424
1425 /*****************************************************************************/
1426 /* Function:    Material_CreatePyObject         */
1427 /* Description: Create a new BPy_Material from an  existing */
1428 /*               Blender material structure.     */
1429 /*****************************************************************************/
1430 PyObject *Material_CreatePyObject( struct Material *mat )
1431 {
1432         BPy_Material *pymat;
1433         float *col[3], *amb[3], *spec[3], *mir[3], *sss[3];
1434
1435         pymat = ( BPy_Material * ) PyObject_NEW( BPy_Material,
1436                                                  &Material_Type );
1437
1438         if( !pymat )
1439                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
1440                                               "couldn't create BPy_Material object" );
1441
1442         pymat->material = mat;
1443
1444         col[0] = &mat->r;
1445         col[1] = &mat->g;
1446         col[2] = &mat->b;
1447
1448         amb[0] = &mat->ambr;
1449         amb[1] = &mat->ambg;
1450         amb[2] = &mat->ambb;
1451
1452         spec[0] = &mat->specr;
1453         spec[1] = &mat->specg;
1454         spec[2] = &mat->specb;
1455
1456         mir[0] = &mat->mirr;
1457         mir[1] = &mat->mirg;
1458         mir[2] = &mat->mirb;
1459         
1460         sss[0] = &mat->sss_col[0];
1461         sss[1] = &mat->sss_col[1];
1462         sss[2] = &mat->sss_col[2];
1463
1464         pymat->col = ( BPy_rgbTuple * ) rgbTuple_New( col );
1465         pymat->amb = ( BPy_rgbTuple * ) rgbTuple_New( amb );
1466         pymat->spec = ( BPy_rgbTuple * ) rgbTuple_New( spec );
1467         pymat->mir = ( BPy_rgbTuple * ) rgbTuple_New( mir );
1468         pymat->sss = ( BPy_rgbTuple * ) rgbTuple_New( sss );
1469
1470         return ( PyObject * ) pymat;
1471 }
1472
1473 /*****************************************************************************/
1474 /* Function:            Material_FromPyObject    */
1475 /* Description: This function returns the Blender material from the given */
1476 /*              PyObject.        */
1477 /*****************************************************************************/
1478 Material *Material_FromPyObject( PyObject * pyobj )
1479 {
1480         return ( ( BPy_Material * ) pyobj )->material;
1481 }
1482
1483 static PyObject *Material_getIpo( BPy_Material * self )
1484 {
1485         Ipo *ipo = self->material->ipo;
1486
1487         if( !ipo )
1488                 Py_RETURN_NONE;
1489
1490         return Ipo_CreatePyObject( ipo );
1491 }
1492
1493 static PyObject *Material_getMode( BPy_Material * self )
1494 {
1495         return PyInt_FromLong( ( long ) self->material->mode );
1496 }
1497
1498 static PyObject *Material_getRGBCol( BPy_Material * self )
1499 {
1500         return rgbTuple_getCol( self->col );
1501 }
1502
1503 /*
1504 static PyObject *Material_getAmbCol(BPy_Material *self)
1505 {
1506         return rgbTuple_getCol(self->amb);
1507 }
1508 */
1509 static PyObject *Material_getSpecCol( BPy_Material * self )
1510 {
1511         return rgbTuple_getCol( self->spec );
1512 }
1513
1514 static PyObject *Material_getMirCol( BPy_Material * self )
1515 {
1516         return rgbTuple_getCol( self->mir );
1517 }
1518
1519 static PyObject *Material_getSssCol( BPy_Material * self )
1520 {
1521         return rgbTuple_getCol( self->sss );
1522 }
1523
1524 static PyObject *Material_getSpecShader( BPy_Material * self )
1525 {
1526         return PyInt_FromLong( ( long ) self->material->spec_shader );
1527 }
1528
1529 static PyObject *Material_getDiffuseShader( BPy_Material * self )
1530 {
1531         return PyInt_FromLong( ( long ) self->material->diff_shader );
1532 }
1533
1534 static PyObject *Material_getRoughness( BPy_Material * self )
1535 {
1536         return PyFloat_FromDouble( ( double ) self->material->roughness );
1537 }
1538
1539 static PyObject *Material_getSpecSize( BPy_Material * self )
1540 {
1541         return PyFloat_FromDouble( ( double ) self->material->param[2] );
1542 }
1543
1544 static PyObject *Material_getDiffuseSize( BPy_Material * self )
1545 {
1546         return PyFloat_FromDouble( ( double ) self->material->param[0] );
1547 }
1548
1549 static PyObject *Material_getSpecSmooth( BPy_Material * self )
1550 {
1551         return PyFloat_FromDouble( ( double ) self->material->param[3] );
1552 }
1553
1554 static PyObject *Material_getDiffuseSmooth( BPy_Material * self )
1555 {
1556         return PyFloat_FromDouble( ( double ) self->material->param[1] );
1557 }
1558
1559 static PyObject *Material_getDiffuseDarkness( BPy_Material * self )
1560 {
1561         return PyFloat_FromDouble( ( double ) self->material->darkness );
1562 }
1563
1564 static PyObject *Material_getRefracIndex( BPy_Material * self )
1565 {
1566         return PyFloat_FromDouble( ( double ) self->material->refrac );
1567 }
1568         
1569 static PyObject *Material_getRms( BPy_Material * self )
1570 {
1571         return PyFloat_FromDouble( ( double ) self->material->rms );
1572 }
1573
1574 static PyObject *Material_getAmb( BPy_Material * self )
1575 {
1576         return PyFloat_FromDouble( ( double ) self->material->amb );
1577 }
1578
1579 static PyObject *Material_getEmit( BPy_Material * self )
1580 {
1581         return PyFloat_FromDouble( ( double ) self->material->emit );
1582 }
1583
1584 static PyObject *Material_getAlpha( BPy_Material * self )
1585 {
1586         return PyFloat_FromDouble( ( double ) self->material->alpha );
1587 }
1588
1589 static PyObject *Material_getShadAlpha( BPy_Material * self )
1590 {
1591         return PyFloat_FromDouble( ( double ) self->material->shad_alpha );
1592 }
1593
1594 static PyObject *Material_getRef( BPy_Material * self )
1595 {
1596         return PyFloat_FromDouble( ( double ) self->material->ref );
1597 }
1598
1599 static PyObject *Material_getSpec( BPy_Material * self )
1600 {
1601         return PyFloat_FromDouble( ( double ) self->material->spec );
1602 }
1603
1604 static PyObject *Material_getSpecTransp( BPy_Material * self )
1605 {
1606         return PyFloat_FromDouble( ( double ) self->material->spectra );
1607 }
1608
1609 static PyObject *Material_getAdd( BPy_Material * self )
1610 {
1611         return PyFloat_FromDouble( ( double ) self->material->add );
1612 }
1613
1614 static PyObject *Material_getZOffset( BPy_Material * self )
1615 {
1616         return PyFloat_FromDouble( ( double ) self->material->zoffs );
1617 }
1618
1619 static PyObject *Material_getLightGroup( BPy_Material * self )
1620 {
1621         return Group_CreatePyObject( self->material->group );
1622 }
1623
1624 static PyObject *Material_getTexChannel( BPy_Material * self )
1625 {
1626         int i;
1627     short mask = 1;
1628         PyObject *list = PyList_New(0);
1629         if( !list )
1630                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
1631                                 "PyList_New() failed" );
1632
1633         for( i = 0, mask = 1; i < MAX_MTEX ; ++i, mask <<= 1 ) {
1634                 if( self->material->mtex[i] && (mask & self->material->septex) == 0 ) {
1635                         PyObject * val = PyInt_FromLong(i);
1636                         if( !val ) {
1637                                 Py_DECREF( list );
1638                                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
1639                                                 "PyInt_FromLong() failed" );
1640                         }
1641                         if( PyList_Append( list, val ) < 0 ) {
1642                                 Py_DECREF( val );
1643                                 Py_DECREF( list );
1644                                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1645                                                 "PyList_Append() failed" );
1646                         }
1647                         Py_DECREF( val );
1648                 }
1649         }
1650
1651         return list;
1652 }
1653
1654 static PyObject *Material_getHaloSize( BPy_Material * self )
1655 {
1656         return PyFloat_FromDouble( ( double ) self->material->hasize );
1657 }
1658
1659 static PyObject *Material_getFlareSize( BPy_Material * self )
1660 {
1661         return PyFloat_FromDouble( ( double ) self->material->flaresize );
1662 }
1663
1664 static PyObject *Material_getFlareBoost( BPy_Material * self )
1665 {
1666         return PyFloat_FromDouble( ( double ) self->material->flareboost );
1667 }
1668
1669 static PyObject *Material_getSubSize( BPy_Material * self )
1670 {
1671         return PyFloat_FromDouble( ( double ) self->material->subsize );
1672 }
1673
1674 static PyObject *Material_getHaloSeed( BPy_Material * self )
1675 {
1676         return PyInt_FromLong( ( long ) self->material->seed1 );
1677 }
1678
1679 static PyObject *Material_getFlareSeed( BPy_Material * self )
1680 {
1681         return PyInt_FromLong( ( long ) self->material->seed2 );
1682 }
1683
1684 static PyObject *Material_getHardness( BPy_Material * self )
1685 {
1686         return PyInt_FromLong( ( long ) self->material->har );
1687 }
1688
1689 static PyObject *Material_getNFlares( BPy_Material * self )
1690 {
1691         return PyInt_FromLong( ( long ) self->material->flarec );
1692 }
1693
1694 static PyObject *Material_getNStars( BPy_Material * self )
1695 {
1696         return PyInt_FromLong( ( long ) self->material->starc );
1697 }
1698
1699 static PyObject *Material_getNLines( BPy_Material * self )
1700 {
1701         return PyInt_FromLong( ( long ) self->material->linec );
1702 }
1703
1704 static PyObject *Material_getNRings( BPy_Material * self )
1705 {
1706         return PyInt_FromLong( ( long ) self->material->ringc );
1707 }
1708
1709 static PyObject *Material_getRayMirr( BPy_Material * self )
1710 {
1711         return PyFloat_FromDouble( ( double ) self->material->ray_mirror );
1712 }
1713
1714 static PyObject *Material_getMirrDepth( BPy_Material * self )
1715 {
1716         return PyInt_FromLong( ( long ) self->material->ray_depth );
1717 }
1718
1719 static PyObject *Material_getFresnelMirr( BPy_Material * self )
1720 {
1721         return PyFloat_FromDouble( ( double ) self->material->fresnel_mir );
1722 }
1723
1724 static PyObject *Material_getFresnelMirrFac( BPy_Material * self )
1725 {
1726         return PyFloat_FromDouble( ( double ) self->material->fresnel_mir_i );
1727 }
1728
1729 static PyObject *Material_getFilter( BPy_Material * self )
1730 {
1731         return PyFloat_FromDouble( ( double ) self->material->filter );
1732 }
1733
1734 static PyObject *Material_getTranslucency( BPy_Material * self )
1735 {
1736         return PyFloat_FromDouble( ( double ) self->material->translucency );
1737 }
1738
1739 static PyObject *Material_getIOR( BPy_Material * self )
1740 {
1741         return PyFloat_FromDouble( ( double ) self->material->ang );
1742 }
1743
1744 static PyObject *Material_getTransDepth( BPy_Material * self )
1745 {
1746         return PyInt_FromLong( ( long ) self->material->ray_depth_tra );
1747 }
1748
1749 static PyObject *Material_getFresnelTrans( BPy_Material * self )
1750 {
1751         return PyFloat_FromDouble( ( double ) self->material->fresnel_tra );
1752 }
1753
1754 static PyObject *Material_getFresnelTransFac( BPy_Material * self )
1755 {
1756         return PyFloat_FromDouble( ( double ) self->material->fresnel_tra_i );
1757 }
1758
1759 static PyObject *Material_getGlossMirr( BPy_Material * self )
1760 {
1761         return PyFloat_FromDouble( ( double ) self->material->gloss_mir );
1762 }
1763
1764 static PyObject *Material_getGlossMirrSamples( BPy_Material * self )
1765 {
1766         return PyInt_FromLong( ( long ) self->material->samp_gloss_mir );
1767 }
1768
1769 static PyObject *Material_getGlossTrans( BPy_Material * self )
1770 {
1771         return PyFloat_FromDouble( ( double ) self->material->gloss_tra );
1772 }
1773
1774 static PyObject *Material_getGlossTransSamples( BPy_Material * self )
1775 {
1776         return PyInt_FromLong( ( long ) self->material->samp_gloss_tra );
1777 }
1778
1779 static PyObject* Material_getRigidBodyFriction( BPy_Material * self )
1780 {
1781         return PyFloat_FromDouble( ( double ) self->material->friction );
1782 }
1783
1784 static PyObject* Material_getRigidBodyRestitution( BPy_Material * self )
1785 {
1786         return PyFloat_FromDouble( ( double ) self->material->reflect );
1787 }
1788
1789 /* SSS */
1790 static PyObject* Material_getSssEnable( BPy_Material * self )
1791 {
1792         return EXPP_getBitfield( &self->material->sss_flag, MA_DIFF_SSS, 'h' );
1793 }
1794
1795 static PyObject* Material_getSssScale( BPy_Material * self )
1796 {
1797         return PyFloat_FromDouble( ( double ) self->material->sss_scale );
1798 }
1799
1800 static PyObject* Material_getSssRadius( BPy_Material * self, void * type )
1801 {
1802         return PyFloat_FromDouble( ( double ) (self->material->sss_radius[GET_INT_FROM_POINTER(type)]) );
1803 }
1804
1805 static PyObject* Material_getSssIOR( BPy_Material * self )
1806 {
1807         return PyFloat_FromDouble( ( double ) self->material->sss_ior);
1808 }
1809
1810 static PyObject* Material_getSssError( BPy_Material * self )
1811 {
1812         return PyFloat_FromDouble( ( double ) self->material->sss_error);
1813 }
1814
1815 static PyObject* Material_getSssColorBlend( BPy_Material * self )
1816 {
1817         return PyFloat_FromDouble( ( double ) self->material->sss_colfac);
1818 }
1819
1820 static PyObject* Material_getSssTexScatter( BPy_Material * self )
1821 {
1822         return PyFloat_FromDouble( ( double ) self->material->sss_texfac);
1823 }
1824
1825 static PyObject* Material_getSssFront( BPy_Material * self )
1826 {
1827         return PyFloat_FromDouble( ( double ) self->material->sss_front);
1828 }
1829
1830 static PyObject* Material_getSssBack( BPy_Material * self )
1831 {
1832         return PyFloat_FromDouble( ( double ) self->material->sss_back);
1833 }
1834
1835 static PyObject *Material_getTextures( BPy_Material * self )
1836 {
1837         int i;
1838         PyObject *tuple;
1839
1840         /* build a texture list */
1841         tuple = PyTuple_New( MAX_MTEX );
1842         if( !tuple )
1843                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
1844                                               "couldn't create PyTuple" );
1845
1846         for( i = 0; i < MAX_MTEX; ++i ) {
1847                 struct MTex *mtex = self->material->mtex[i];
1848                 if( mtex ) {
1849                         PyTuple_SET_ITEM( tuple, i, MTex_CreatePyObject( mtex, ID_MA ) );
1850                 } else {
1851                         Py_INCREF( Py_None );
1852                         PyTuple_SET_ITEM( tuple, i, Py_None );
1853                 }
1854         }
1855
1856         return tuple;
1857 }
1858
1859 /*
1860  * this should accept a Py_None argument and just delete the Ipo link
1861  * (as Lamp_clearIpo() does)
1862  */
1863
1864 static int Material_setIpo( BPy_Material * self, PyObject * value )
1865 {
1866         return GenericLib_assignData(value, (void **) &self->material->ipo, 0, 1, ID_IP, ID_MA);
1867 }
1868
1869
1870 /* 
1871  *  Material_insertIpoKey( key )
1872  *   inserts Material IPO key at current frame
1873  */
1874
1875 static PyObject *Material_insertIpoKey( BPy_Material * self, PyObject * args )
1876 {
1877     int key = 0, flag = 0, map;
1878     
1879         if( !PyArg_ParseTuple( args, "i", &( key ) ) )
1880                 return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
1881                                                 "expected int argument" ) ); 
1882                                 
1883         map = texchannel_to_adrcode(self->material->texact);
1884         
1885         /* flag should be initialised with the 'autokeying' flags like for normal keying */
1886         if (IS_AUTOKEY_FLAG(INSERTNEEDED)) flag |= INSERTKEY_NEEDED;
1887         
1888         if(key==IPOKEY_RGB || key==IPOKEY_ALLCOLOR) {
1889                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_COL_R, flag);
1890                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_COL_G, flag);
1891                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_COL_B, flag);
1892         }
1893         if(key==IPOKEY_ALPHA || key==IPOKEY_ALLCOLOR) {
1894                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_ALPHA, flag);
1895         }
1896         if(key==IPOKEY_HALOSIZE || key==IPOKEY_ALLCOLOR) {
1897                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_HASIZE, flag);
1898         }
1899         if(key==IPOKEY_MODE || key==IPOKEY_ALLCOLOR) {
1900                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_MODE, flag);
1901         }
1902         if(key==IPOKEY_ALLCOLOR) {
1903                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_SPEC_R, flag);
1904                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_SPEC_G, flag);
1905                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_SPEC_B, flag);
1906                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_REF, flag);
1907                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_EMIT, flag);
1908                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_AMB, flag);
1909                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_SPEC, flag);
1910                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_HARD, flag);
1911                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_MODE, flag);
1912                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_TRANSLU, flag);
1913                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_ADD, flag);
1914         }
1915         if(key==IPOKEY_ALLMIRROR) {
1916                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_RAYM, flag);
1917                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_FRESMIR, flag);
1918                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_FRESMIRI, flag);
1919                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_FRESTRA, flag);
1920                 insertkey((ID *)self->material, ID_MA, NULL, NULL, MA_FRESTRAI, flag);
1921         }
1922         if(key==IPOKEY_OFS || key==IPOKEY_ALLMAPPING) {
1923                 insertkey((ID *)self->material, ID_MA, NULL, NULL, map+MAP_OFS_X, flag);
1924                 insertkey((ID *)self->material, ID_MA, NULL, NULL, map+MAP_OFS_Y, flag);
1925                 insertkey((ID *)self->material, ID_MA, NULL, NULL, map+MAP_OFS_Z, flag);
1926         }
1927         if(key==IPOKEY_SIZE || key==IPOKEY_ALLMAPPING) {
1928                 insertkey((ID *)self->material, ID_MA, NULL, NULL, map+MAP_SIZE_X, flag);
1929                 insertkey((ID *)self->material, ID_MA, NULL, NULL, map+MAP_SIZE_Y, flag);
1930                 insertkey((ID *)self->material, ID_MA, NULL, NULL, map+MAP_SIZE_Z, flag);
1931         }
1932         if(key==IPOKEY_ALLMAPPING) {
1933                 insertkey((ID *)self->material, ID_MA, NULL, NULL, map+MAP_R, flag);
1934                 insertkey((ID *)self->material, ID_MA, NULL, NULL, map+MAP_G, flag);
1935                 insertkey((ID *)self->material, ID_MA, NULL, NULL, map+MAP_B, flag);
1936                 insertkey((ID *)self->material, ID_MA, NULL, NULL, map+MAP_DVAR, flag);
1937                 insertkey((ID *)self->material, ID_MA, NULL, NULL, map+MAP_COLF, flag);
1938                 insertkey((ID *)self->material, ID_MA, NULL, NULL, map+MAP_NORF, flag);
1939                 insertkey((ID *)self->material, ID_MA, NULL, NULL, map+MAP_VARF, flag);
1940                 insertkey((ID *)self->material, ID_MA, NULL, NULL, map+MAP_DISP, flag);
1941         }
1942
1943         allspace(REMAKEIPO, 0);
1944         EXPP_allqueue(REDRAWIPO, 0);
1945         EXPP_allqueue(REDRAWVIEW3D, 0);
1946         EXPP_allqueue(REDRAWACTION, 0);
1947         EXPP_allqueue(REDRAWNLA, 0);
1948
1949         Py_RETURN_NONE;
1950 }
1951
1952 static int Material_setMode( BPy_Material * self, PyObject * value )
1953 {
1954         int param;
1955
1956         if( !PyInt_Check( value ) ) {
1957                 char errstr[128];
1958                 sprintf ( errstr , "expected int bitmask of 0x%08x", MA_MODE_MASK );
1959                 return EXPP_ReturnIntError( PyExc_TypeError, errstr );
1960         }
1961         param = PyInt_AS_LONG ( value );
1962
1963         if ( ( param & MA_MODE_MASK ) != param )
1964                 return EXPP_ReturnIntError( PyExc_ValueError,
1965                                                 "invalid bit(s) set in mask" );
1966
1967         self->material->mode &= ( MA_RAMP_COL | MA_RAMP_SPEC );
1968         self->material->mode |= param & ~( MA_RAMP_COL | MA_RAMP_SPEC );
1969
1970         return 0;
1971 }
1972
1973 static int Material_setRGBCol( BPy_Material * self, PyObject * value )
1974 {
1975         return rgbTuple_setCol( self->col, value );
1976 }
1977
1978 /*
1979 static PyObject *Material_setAmbCol (BPy_Material *self, PyObject * value )
1980 {
1981         return rgbTuple_setCol(self->amb, value);
1982 }
1983 */
1984
1985 static int Material_setSpecCol( BPy_Material * self, PyObject * value )
1986 {
1987         return rgbTuple_setCol( self->spec, value );
1988 }
1989
1990 static int Material_setMirCol( BPy_Material * self, PyObject * value )
1991 {
1992         return rgbTuple_setCol( self->mir, value );
1993 }
1994
1995 static int Material_setSssCol( BPy_Material * self, PyObject * value )
1996 {
1997         return rgbTuple_setCol( self->sss, value );
1998 }
1999
2000 static int Material_setColorComponent( BPy_Material * self, PyObject * value,
2001                                                         void * closure )
2002 {
2003         float param;
2004
2005         if( !PyNumber_Check ( value ) )
2006                 return EXPP_ReturnIntError( PyExc_TypeError,
2007                                                 "expected float argument in [0.0,1.0]" );
2008
2009         param = (float)PyFloat_AsDouble( value );
2010         param = EXPP_ClampFloat( param, EXPP_MAT_COL_MIN, EXPP_MAT_COL_MAX );
2011
2012         switch ( GET_INT_FROM_POINTER(closure) ) {
2013         case EXPP_MAT_COMP_R:
2014                 self->material->r = param;
2015                 return 0;
2016         case EXPP_MAT_COMP_G:
2017                 self->material->g = param;
2018                 return 0;
2019         case EXPP_MAT_COMP_B:
2020                 self->material->b = param;
2021                 return 0;
2022         case EXPP_MAT_COMP_SPECR:
2023                 self->material->specr = param;
2024                 return 0;
2025         case EXPP_MAT_COMP_SPECG:
2026                 self->material->specg = param;
2027                 return 0;
2028         case EXPP_MAT_COMP_SPECB:
2029                 self->material->specb = param;
2030                 return 0;
2031         case EXPP_MAT_COMP_MIRR:
2032                 self->material->mirr = param;
2033                 return 0;
2034         case EXPP_MAT_COMP_MIRG:
2035                 self->material->mirg = param;
2036                 return 0;
2037         case EXPP_MAT_COMP_MIRB:
2038                 self->material->mirb = param;
2039                 return 0;
2040         case EXPP_MAT_COMP_SSSR:
2041                 self->material->sss_col[0] = param;
2042                 return 0;
2043         case EXPP_MAT_COMP_SSSG:
2044                 self->material->sss_col[1] = param;
2045                 return 0;
2046         case EXPP_MAT_COMP_SSSB:
2047                 self->material->sss_col[2] = param;
2048                 return 0;
2049         }
2050         return EXPP_ReturnIntError( PyExc_RuntimeError,
2051                                 "unknown color component specified" );
2052 }
2053
2054 /*#define setFloatWrapper(val, min, max) {return EXPP_setFloatClamped ( value, &self->material->#val, #min, #max}*/
2055
2056 static int Material_setAmb( BPy_Material * self, PyObject * value )
2057
2058         return EXPP_setFloatClamped ( value, &self->material->amb,
2059                                                                 EXPP_MAT_AMB_MIN,
2060                                                         EXPP_MAT_AMB_MAX );
2061 }
2062
2063 static int Material_setEmit( BPy_Material * self, PyObject * value )
2064 {
2065         return EXPP_setFloatClamped ( value, &self->material->emit,
2066                                                                 EXPP_MAT_EMIT_MIN,
2067                                                                 EXPP_MAT_EMIT_MAX );
2068 }
2069
2070 static int Material_setSpecTransp( BPy_Material * self, PyObject * value )
2071 {
2072         return EXPP_setFloatClamped ( value, &self->material->spectra,
2073                                                                 EXPP_MAT_SPECTRA_MIN,
2074                                                                 EXPP_MAT_SPECTRA_MAX );
2075 }
2076
2077 static int Material_setAlpha( BPy_Material * self, PyObject * value )
2078 {
2079         return EXPP_setFloatClamped ( value, &self->material->alpha,
2080                                                                 EXPP_MAT_ALPHA_MIN,
2081                                                                 EXPP_MAT_ALPHA_MAX );
2082 }
2083
2084 static int Material_setShadAlpha( BPy_Material * self, PyObject * value )
2085 {
2086         return EXPP_setFloatClamped ( value, &self->material->shad_alpha,
2087                                                                 EXPP_MAT_ALPHA_MIN,
2088                                                                 EXPP_MAT_ALPHA_MAX );
2089 }
2090
2091 static int Material_setRef( BPy_Material * self, PyObject * value )
2092 {
2093         return EXPP_setFloatClamped ( value, &self->material->ref,
2094                                                                 EXPP_MAT_REF_MIN,
2095                                                                 EXPP_MAT_REF_MAX );
2096 }
2097
2098 static int Material_setSpec( BPy_Material * self, PyObject * value )
2099 {
2100         return EXPP_setFloatClamped ( value, &self->material->spec,
2101                                                                 EXPP_MAT_SPEC_MIN,
2102                                                                 EXPP_MAT_SPEC_MAX );
2103 }
2104
2105 static int Material_setZOffset( BPy_Material * self, PyObject * value )
2106 {
2107         return EXPP_setFloatClamped ( value, &self->material->zoffs,
2108                                                                 EXPP_MAT_ZOFFS_MIN,
2109                                                                 EXPP_MAT_ZOFFS_MAX );
2110 }
2111
2112 static int Material_setLightGroup( BPy_Material * self, PyObject * value )
2113 {
2114         return GenericLib_assignData(value, (void **) &self->material->group, NULL, 1, ID_GR, 0);
2115 }
2116
2117 static int Material_setTexChannel( BPy_Material * self, PyObject * value )
2118 {
2119         int i, mask;
2120         short septex = 0;
2121         int result = 1;
2122
2123         /* fail if input is not a standard sequence */
2124         if( !PyList_Check( value ) && !PyTuple_Check( value ) )
2125                 return EXPP_ReturnIntError( PyExc_TypeError,
2126                                                 "expected tuple or list of integers" );
2127
2128         /* get a fast sequence; in Python 2.5, this just return the original
2129          * list or tuple and INCREFs it, so we must DECREF */
2130         value = PySequence_Fast( value, "" );
2131
2132         /* set the disable bit for each existing texture */
2133         for( i= 0, mask= 1; i < MAX_MTEX; ++i, mask <<= 1 )
2134                 if( self->material->mtex[i] != NULL )
2135                         septex |= mask;
2136
2137         /* check the list, and build new septex value */
2138         for( i= PySequence_Size(value)-1; i >= 0; --i ) {
2139                 long ival;
2140                 PyObject *item = PySequence_Fast_GET_ITEM( value, i );
2141                 if( !PyInt_Check( item ) ) {
2142                         PyErr_SetString ( PyExc_TypeError,
2143                                         "expected tuple or list of integers" );
2144                         goto exit;
2145                 }
2146                 ival= PyInt_AsLong( item );
2147                 if(ival < 0 || ival > MAX_MTEX) {
2148                         PyErr_SetString( PyExc_ValueError,
2149                                                         "channel value out of range" );
2150                         goto exit;
2151                 }
2152                 ival&= (1<<MAX_MTEX)-1;
2153                 if( self->material->mtex[(int)ival] == NULL ) {
2154                         PyErr_SetString( PyExc_ValueError,
2155                                                         "channels must have a texture assigned" );
2156                         goto exit;
2157                 }
2158                 septex&= ~(1<<ival);
2159         }
2160         self->material->septex= septex;
2161         result = 0;
2162
2163 exit:
2164         Py_DECREF(value);
2165         return result;
2166 }
2167
2168 static int Material_setAdd( BPy_Material * self, PyObject * value )
2169 {
2170         return EXPP_setFloatClamped ( value, &self->material->add,
2171                                                                 EXPP_MAT_ADD_MIN,
2172                                                                 EXPP_MAT_ADD_MAX );
2173 }
2174
2175 static int Material_setHaloSize( BPy_Material * self, PyObject * value )
2176 {
2177         return EXPP_setFloatClamped ( value, &self->material->hasize,
2178                                                                 EXPP_MAT_HALOSIZE_MIN,
2179                                                                 EXPP_MAT_HALOSIZE_MAX );
2180 }
2181
2182 static int Material_setFlareSize( BPy_Material * self, PyObject * value )
2183 {
2184         return EXPP_setFloatClamped ( value, &self->material->flaresize,
2185                                                                 EXPP_MAT_FLARESIZE_MIN,
2186                                                                 EXPP_MAT_FLARESIZE_MAX );
2187 }
2188
2189 static int Material_setFlareBoost( BPy_Material * self, PyObject * value )
2190 {
2191         return EXPP_setFloatClamped ( value, &self->material->flareboost,
2192                                                                 EXPP_MAT_FLAREBOOST_MIN,
2193                                                                 EXPP_MAT_FLAREBOOST_MAX );
2194 }
2195
2196 static int Material_setSubSize( BPy_Material * self, PyObject * value )
2197 {
2198         return EXPP_setFloatClamped ( value, &self->material->subsize,
2199                                                                 EXPP_MAT_SUBSIZE_MIN,
2200                                                                 EXPP_MAT_SUBSIZE_MAX );
2201 }
2202
2203 static int Material_setHaloSeed( BPy_Material * self, PyObject * value )
2204 {
2205         return EXPP_setIValueClamped ( value, &self->material->seed1,
2206                                                                 EXPP_MAT_HALOSEED_MIN,
2207                                                                 EXPP_MAT_HALOSEED_MAX, 'b' );
2208 }
2209
2210 static int Material_setFlareSeed( BPy_Material * self, PyObject * value )
2211 {
2212         return EXPP_setIValueClamped ( value, &self->material->seed2,
2213                                                                 EXPP_MAT_FLARESEED_MIN,
2214                                                                 EXPP_MAT_FLARESEED_MAX, 'b' );
2215 }
2216
2217 static int Material_setHardness( BPy_Material * self, PyObject * value )
2218 {
2219         return EXPP_setIValueClamped ( value, &self->material->har,
2220                                                                 EXPP_MAT_HARD_MIN,
2221                                                                 EXPP_MAT_HARD_MAX, 'h' );
2222 }
2223
2224 static int Material_setNFlares( BPy_Material * self, PyObject * value )
2225 {
2226         return EXPP_setIValueClamped ( value, &self->material->flarec,
2227                                                                 EXPP_MAT_NFLARES_MIN,
2228                                                                 EXPP_MAT_NFLARES_MAX, 'h' );
2229 }
2230
2231 static int Material_setNStars( BPy_Material * self, PyObject * value )
2232 {
2233         return EXPP_setIValueClamped ( value, &self->material->starc,
2234                                                                 EXPP_MAT_NSTARS_MIN,
2235                                                                 EXPP_MAT_NSTARS_MAX, 'h' );
2236 }
2237
2238 static int Material_setNLines( BPy_Material * self, PyObject * value )
2239 {
2240         return EXPP_setIValueClamped ( value, &self->material->linec,
2241                                                                 EXPP_MAT_NLINES_MIN,
2242                                                                 EXPP_MAT_NLINES_MAX, 'h' );
2243 }
2244
2245 static int Material_setNRings( BPy_Material * self, PyObject * value )
2246 {
2247         return EXPP_setIValueClamped ( value, &self->material->ringc,
2248                                                                 EXPP_MAT_NRINGS_MIN,
2249                                                                 EXPP_MAT_NRINGS_MAX, 'h' );
2250 }
2251
2252 static int Material_setRayMirr( BPy_Material * self, PyObject * value )
2253 {
2254         return EXPP_setFloatClamped ( value, &self->material->ray_mirror,
2255                                                                 EXPP_MAT_RAYMIRR_MIN,
2256                                                                 EXPP_MAT_RAYMIRR_MAX );
2257 }
2258
2259 static int Material_setMirrDepth( BPy_Material * self, PyObject * value )
2260 {
2261         return EXPP_setIValueClamped ( value, &self->material->ray_depth,
2262                                                                 EXPP_MAT_MIRRDEPTH_MIN,
2263                                                                 EXPP_MAT_MIRRDEPTH_MAX, 'h' );
2264 }
2265
2266 static int Material_setFresnelMirr( BPy_Material * self, PyObject * value )
2267 {
2268         return EXPP_setFloatClamped ( value, &self->material->fresnel_mir,
2269                                                                 EXPP_MAT_FRESNELMIRR_MIN,
2270                                                                 EXPP_MAT_FRESNELMIRR_MAX );
2271 }
2272
2273 static int Material_setFresnelMirrFac( BPy_Material * self, PyObject * value )
2274 {
2275         return EXPP_setFloatClamped ( value, &self->material->fresnel_mir_i,
2276                                                                 EXPP_MAT_FRESNELMIRRFAC_MIN,
2277                                                                 EXPP_MAT_FRESNELMIRRFAC_MAX );
2278 }
2279
2280 static int Material_setIOR( BPy_Material * self, PyObject * value )
2281 {
2282         return EXPP_setFloatClamped ( value, &self->material->ang,
2283                                                                 EXPP_MAT_IOR_MIN,
2284                                                                 EXPP_MAT_IOR_MAX );
2285 }
2286
2287 static int Material_setTransDepth( BPy_Material * self, PyObject * value )
2288 {
2289         return EXPP_setIValueClamped ( value, &self->material->ray_depth_tra,
2290                                                                 EXPP_MAT_TRANSDEPTH_MIN,
2291                                                                 EXPP_MAT_TRANSDEPTH_MAX, 'h' );
2292 }
2293
2294 static int Material_setFresnelTrans( BPy_Material * self, PyObject * value )
2295 {
2296         return EXPP_setFloatClamped ( value, &self->material->fresnel_tra,
2297                                                                 EXPP_MAT_FRESNELTRANS_MIN,
2298                                                                 EXPP_MAT_FRESNELTRANS_MAX );
2299 }
2300
2301 static int Material_setFresnelTransFac( BPy_Material * self, PyObject * value )
2302 {
2303         return EXPP_setFloatClamped ( value, &self->material->fresnel_tra_i,
2304                                                                 EXPP_MAT_FRESNELTRANSFAC_MIN,
2305                                                                 EXPP_MAT_FRESNELTRANSFAC_MAX );
2306 }
2307
2308 static int Material_setGlossMirr( BPy_Material * self, PyObject * value )
2309 {
2310         return EXPP_setFloatClamped ( value, &self->material->gloss_mir,
2311                                                                 EXPP_MAT_RAYMIRRGLOSS_MIN,
2312                                                                 EXPP_MAT_RAYMIRRGLOSS_MAX );
2313 }
2314
2315 static int Material_setGlossMirrSamples( BPy_Material * self, PyObject * value )
2316 {
2317         return EXPP_setIValueClamped ( value, &self->material->samp_gloss_mir,
2318                                                                 EXPP_MAT_RAYMIRRGLOSSSAMPLES_MIN,
2319                                                                 EXPP_MAT_RAYMIRRGLOSSSAMPLES_MAX, 'h' );
2320 }
2321
2322 static int Material_setGlossTrans( BPy_Material * self, PyObject * value )
2323 {
2324         return EXPP_setFloatClamped ( value, &self->material->gloss_tra,
2325                                                                 EXPP_MAT_RAYTRANSPGLOSS_MIN,
2326                                                                 EXPP_MAT_RAYTRANSPGLOSS_MAX );
2327 }
2328
2329 static int Material_setGlossTransSamples( BPy_Material * self, PyObject * value )
2330 {
2331         return EXPP_setIValueClamped ( value, &self->material->samp_gloss_tra,
2332                                                                 EXPP_MAT_RAYTRANSPGLOSSSAMPLES_MIN,
2333                                                                 EXPP_MAT_RAYTRANSPGLOSSSAMPLES_MAX, 'h' );
2334 }
2335
2336 static int Material_setRigidBodyFriction( BPy_Material * self, PyObject * value )
2337 {
2338         return EXPP_setFloatClamped ( value, &self->material->friction,
2339                                                                 0.f,
2340                                                                 100.f );
2341 }
2342
2343 static int Material_setRigidBodyRestitution( BPy_Material * self, PyObject * value )
2344 {
2345         return EXPP_setFloatClamped ( value, &self->material->reflect,
2346                                                                 0.f,
2347                                                                 1.f );
2348 }
2349
2350
2351
2352
2353 static int Material_setSpecShader( BPy_Material * self, PyObject * value )
2354 {
2355         return EXPP_setIValueRange( value, &self->material->spec_shader,
2356                                                                 MA_SPEC_COOKTORR,
2357                                                                 MA_SPEC_WARDISO, 'h' );
2358 }
2359
2360 static int Material_setDiffuseShader( BPy_Material * self, PyObject * value )
2361 {
2362         return EXPP_setIValueRange( value, &self->material->diff_shader,
2363                                                                 MA_DIFF_LAMBERT,
2364                                                                 MA_DIFF_MINNAERT, 'h' );
2365 }
2366
2367 static int Material_setRoughness( BPy_Material * self, PyObject * value )
2368 {
2369         return EXPP_setFloatClamped ( value, &self->material->roughness,
2370                                                                 EXPP_MAT_ROUGHNESS_MIN,
2371                                                                 EXPP_MAT_ROUGHNESS_MAX );
2372 }
2373
2374 static int Material_setSpecSize( BPy_Material * self, PyObject * value )
2375 {
2376         return EXPP_setFloatClamped ( value, &self->material->param[2],
2377                                                                 EXPP_MAT_SPECSIZE_MIN,
2378                                                                 EXPP_MAT_SPECSIZE_MAX );
2379 }
2380
2381 static int Material_setDiffuseSize( BPy_Material * self, PyObject * value )
2382 {
2383         return EXPP_setFloatClamped ( value, &self->material->param[0],
2384                                                                 EXPP_MAT_DIFFUSESIZE_MIN,
2385                                                                 EXPP_MAT_DIFFUSESIZE_MAX );
2386 }
2387
2388 static int Material_setSpecSmooth( BPy_Material * self, PyObject * value )
2389 {
2390         return EXPP_setFloatClamped ( value, &self->material->param[3],
2391                                                                 EXPP_MAT_SPECSMOOTH_MIN,
2392                                                                 EXPP_MAT_SPECSMOOTH_MAX );
2393 }
2394
2395 static int Material_setDiffuseSmooth( BPy_Material * self, PyObject * value )
2396 {
2397         return EXPP_setFloatClamped ( value, &self->material->param[1],
2398                                                                 EXPP_MAT_DIFFUSESMOOTH_MIN,
2399                                                                 EXPP_MAT_DIFFUSESMOOTH_MAX );
2400 }
2401
2402 static int Material_setDiffuseDarkness( BPy_Material * self, PyObject * value )
2403 {
2404         return EXPP_setFloatClamped ( value, &self->material->darkness,
2405                                                                 EXPP_MAT_DIFFUSE_DARKNESS_MIN,
2406                                                                 EXPP_MAT_DIFFUSE_DARKNESS_MAX );
2407 }
2408
2409 static int Material_setRefracIndex( BPy_Material * self, PyObject * value )
2410 {
2411         return EXPP_setFloatClamped ( value, &self->material->refrac,
2412                                                                 EXPP_MAT_REFRACINDEX_MIN,
2413                                                                 EXPP_MAT_REFRACINDEX_MAX );
2414 }
2415
2416 static int Material_setRms( BPy_Material * self, PyObject * value )
2417 {
2418         return EXPP_setFloatClamped ( value, &self->material->rms,
2419                                                                 EXPP_MAT_RMS_MIN,
2420                                                                 EXPP_MAT_RMS_MAX );
2421 }
2422
2423 static int Material_setFilter( BPy_Material * self, PyObject * value )
2424 {
2425         return EXPP_setFloatClamped ( value, &self->material->filter,
2426                                                                 EXPP_MAT_FILTER_MIN,
2427                                                                 EXPP_MAT_FILTER_MAX );
2428 }
2429
2430 static int Material_setTranslucency( BPy_Material * self, PyObject * value )
2431 {
2432         return EXPP_setFloatClamped ( value, &self->material->translucency,
2433                                                                 EXPP_MAT_TRANSLUCENCY_MIN,
2434                                                                 EXPP_MAT_TRANSLUCENCY_MAX );
2435 }
2436
2437 /* SSS */
2438 static int Material_setSssEnable( BPy_Material * self, PyObject * value )
2439 {
2440         return EXPP_setBitfield( value, &self->material->sss_flag, MA_DIFF_SSS, 'h' );
2441 }
2442
2443 static int Material_setSssScale( BPy_Material * self, PyObject * value )
2444 {
2445         return EXPP_setFloatClamped ( value, &self->material->sss_scale,
2446                                                                 EXPP_MAT_SSS_SCALE_MIN,
2447                                                                 EXPP_MAT_SSS_SCALE_MAX);
2448 }
2449
2450 static int Material_setSssRadius( BPy_Material * self, PyObject * value, void *type )
2451 {
2452         return EXPP_setFloatClamped ( value, &self->material->sss_radius[GET_INT_FROM_POINTER(type)],
2453                                                                 EXPP_MAT_SSS_RADIUS_MIN,
2454                                                                 EXPP_MAT_SSS_RADIUS_MAX);
2455 }
2456
2457 static int Material_setSssIOR( BPy_Material * self, PyObject * value )
2458 {
2459         return EXPP_setFloatClamped ( value, &self->material->sss_ior,
2460                                                                 EXPP_MAT_SSS_IOR_MIN,
2461                                                                 EXPP_MAT_SSS_IOR_MAX);
2462 }
2463
2464 static int Material_setSssError( BPy_Material * self, PyObject * value )
2465 {
2466         return EXPP_setFloatClamped ( value, &self->material->sss_error,
2467                                                                 EXPP_MAT_SSS_IOR_MIN,
2468                                                                 EXPP_MAT_SSS_IOR_MAX);
2469 }
2470
2471 static int Material_setSssColorBlend( BPy_Material * self, PyObject * value )
2472 {
2473         return EXPP_setFloatClamped ( value, &self->material->sss_colfac,
2474                                                                 0.0,
2475                                                                 1.0);
2476 }
2477
2478 static int Material_setSssTexScatter( BPy_Material * self, PyObject * value )
2479 {
2480         return EXPP_setFloatClamped ( value, &self->material->sss_texfac,
2481                                                                 0.0,
2482                                                                 1.0);
2483 }
2484
2485 static int Material_setSssFront( BPy_Material * self, PyObject * value )
2486 {
2487         return EXPP_setFloatClamped ( value, &self->material->sss_front,
2488                                                                 EXPP_MAT_SSS_FRONT_MIN,
2489                                                                 EXPP_MAT_SSS_FRONT_MAX);
2490 }
2491
2492 static int Material_setSssBack( BPy_Material * self, PyObject * value )
2493 {
2494         return EXPP_setFloatClamped ( value, &self->material->sss_back,
2495                                                                 EXPP_MAT_SSS_BACK_MIN,
2496                                                                 EXPP_MAT_SSS_BACK_MAX);
2497 }
2498
2499 static PyObject *Material_setTexture( BPy_Material * self, PyObject * args )
2500 {
2501         int texnum;
2502         PyObject *pytex;
2503         Tex *bltex;
2504         int texco = TEXCO_ORCO, mapto = MAP_COL;
2505
2506         if( !PyArg_ParseTuple( args, "iO!|ii", &texnum, &Texture_Type, &pytex,
2507                                &texco, &mapto ) )
2508                 return EXPP_ReturnPyObjError( PyExc_TypeError,
2509                                               "expected int in [0,9] and Texture" );
2510         if( ( texnum < 0 ) || ( texnum >= MAX_MTEX ) )
2511                 return EXPP_ReturnPyObjError( PyExc_TypeError,
2512                                               "expected int in [0,9] and Texture" );
2513
2514         bltex = Texture_FromPyObject( pytex );
2515
2516         if( !self->material->mtex[texnum] ) {
2517                 /* there isn't an mtex for this slot so we need to make one */
2518                 self->material->mtex[texnum] = add_mtex(  );
2519         } else {
2520                 /* we already had a texture here so deal with the old one first */
2521                 self->material->mtex[texnum]->tex->id.us--;
2522         }
2523
2524         self->material->mtex[texnum]->tex = bltex;
2525         id_us_plus( &bltex->id );
2526         self->material->mtex[texnum]->texco = (short)texco;
2527         self->material->mtex[texnum]->mapto = (short)mapto;
2528
2529         Py_RETURN_NONE;
2530 }
2531
2532 static int Material_setTextures( BPy_Material * self, PyObject * value )
2533 {
2534         int i;
2535
2536         if( !PyList_Check( value ) && !PyTuple_Check( value ) )
2537                 return EXPP_ReturnIntError( PyExc_TypeError,
2538                                                 "expected tuple or list of integers" );
2539
2540         /* don't allow more than MAX_MTEX items */
2541         if( PySequence_Size(value) > MAX_MTEX )
2542                 return EXPP_ReturnIntError( PyExc_AttributeError,
2543                                                 "size of sequence greater than number of allowed textures" );
2544
2545         /* get a fast sequence; in Python 2.5, this just return the original
2546          * list or tuple and INCREFs it, so we must DECREF */
2547         value = PySequence_Fast( value, "" );
2548
2549         /* check the list for valid entries */
2550         for( i= 0; i < PySequence_Size(value) ; ++i ) {
2551                 PyObject *item = PySequence_Fast_GET_ITEM( value, i );
2552                 if( item == Py_None || ( BPy_MTex_Check( item ) &&
2553                                                 ((BPy_MTex *)item)->type == ID_MA ) ) {
2554                         continue;
2555                 } else {
2556                         Py_DECREF(value);
2557                         return EXPP_ReturnIntError( PyExc_TypeError,
2558                                         "expected tuple or list containing material MTex objects and NONE" );
2559                 }
2560         }
2561
2562         /* for each MTex object, copy to this structure */
2563         for( i= 0; i < PySequence_Size(value) ; ++i ) {
2564                 PyObject *item = PySequence_Fast_GET_ITEM( value, i );
2565                 struct MTex *mtex = self->material->mtex[i];
2566                 if( item != Py_None ) {
2567                         BPy_MTex *obj = (BPy_MTex *)item;
2568
2569                         /* if MTex is already at this location, just skip it */
2570                         if( obj->mtex == mtex ) continue;
2571
2572                         /* create a new entry if needed, otherwise update reference count
2573                          * for texture that is being replaced */
2574                         if( !mtex )
2575                                 mtex = self->material->mtex[i] = add_mtex(  );
2576                         else
2577                                 mtex->tex->id.us--;
2578
2579                         /* copy the data */
2580                         mtex->tex = obj->mtex->tex;
2581                         id_us_plus( &mtex->tex->id );
2582                         mtex->texco = obj->mtex->texco;
2583                         mtex->mapto = obj->mtex->mapto;
2584                 }
2585         }
2586
2587         /* now go back and free any entries now marked as None */
2588         for( i= 0; i < PySequence_Size(value) ; ++i ) {
2589                 PyObject *item = PySequence_Fast_GET_ITEM( value, i );
2590                 struct MTex *mtex = self->material->mtex[i];
2591                 if( item == Py_None && mtex ) {
2592                         mtex->tex->id.us--;
2593                         MEM_freeN( mtex );
2594                         self->material->mtex[i] = NULL;
2595                 } 
2596         }
2597
2598         Py_DECREF(value);
2599         return 0;
2600 }
2601
2602 static PyObject *Material_clearTexture( BPy_Material * self, PyObject * value )
2603 {
2604         int texnum = (int)PyInt_AsLong(value);
2605         struct MTex *mtex;
2606         /* non ints will be -1 */
2607         if( ( texnum < 0 ) || ( texnum >= MAX_MTEX ) ) {
2608                 char errstr[64];
2609                 sprintf( errstr, "expected int in [0,%d]", MAX_MTEX );
2610                 return EXPP_ReturnPyObjError( PyExc_TypeError, errstr );
2611         }
2612
2613         mtex = self->material->mtex[texnum];
2614         if( mtex ) {
2615                 if( mtex->tex )
2616                         mtex->tex->id.us--;
2617                 MEM_freeN( mtex );
2618                 self->material->mtex[texnum] = NULL;
2619         }
2620
2621         Py_RETURN_NONE;
2622 }
2623
2624 /* mat.addScriptLink */
2625 static PyObject *Material_addScriptLink( BPy_Material * self, PyObject * args )
2626 {
2627         Material *mat = self->material;
2628         ScriptLink *slink = NULL;
2629
2630         slink = &( mat )->scriptlink;
2631
2632         return EXPP_addScriptLink( slink, args, 0 );
2633 }
2634
2635 /* mat.clearScriptLinks */
2636 static PyObject *Material_clearScriptLinks(BPy_Material *self, PyObject *args )
2637 {
2638         Material *mat = self->material;
2639         ScriptLink *slink = NULL;
2640
2641         slink = &( mat )->scriptlink;
2642
2643         return EXPP_clearScriptLinks( slink, args );
2644 }
2645
2646 /* mat.getScriptLinks */
2647 static PyObject *Material_getScriptLinks( BPy_Material * self,
2648                                           PyObject * value )
2649 {
2650         Material *mat = self->material;
2651         ScriptLink *slink = NULL;
2652         PyObject *ret = NULL;
2653
2654         slink = &( mat )->scriptlink;
2655
2656         /* can't this just return?  EXP_getScriptLinks() returns a PyObject*
2657          * or NULL anyway */
2658
2659         ret = EXPP_getScriptLinks( slink, value, 0 );
2660
2661         if( ret )
2662                 return ret;
2663         else
2664                 return NULL;
2665 }
2666
2667 /* mat.__copy__ */
2668 static PyObject *Material_copy( BPy_Material * self )
2669 {
2670         BPy_Material *pymat; /* for Material Data object wrapper in Python */
2671         Material *blmat; /* for actual Material Data we create in Blender */
2672         
2673         blmat = copy_material( self->material );        /* first copy the Material Data in Blender */
2674
2675         if( blmat )             /* now create the wrapper obj in Python */
2676                 pymat = ( BPy_Material * ) Material_CreatePyObject( blmat );
2677         else
2678                 return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
2679                                                 "couldn't create Material Data in Blender" ) );
2680
2681         blmat->id.us = 0;       /* was incref'ed by add_material() above */
2682
2683         if( pymat == NULL )
2684                 return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
2685                                                 "couldn't create Material Data object" ) );
2686
2687         return ( PyObject * ) pymat;
2688 }
2689
2690 /* mat.freeNodes() */
2691 static PyObject *Material_freeNodes( BPy_Material * self )
2692 {
2693         if (self->material->nodetree) {
2694                 if(self->material->nodetree) {
2695                         ntreeFreeTree(self->material->nodetree);
2696                         MEM_freeN(self->material->nodetree);
2697                 }
2698                 self->material->nodetree = NULL;
2699                 self->material->use_nodes = 0;
2700                 Py_RETURN_TRUE;
2701         } else {
2702                 Py_RETURN_FALSE;
2703         }
2704 }
2705
2706 /* mat_a==mat_b or mat_a!=mat_b*/
2707 static int Material_compare( BPy_Material * a, BPy_Material * b )
2708 {
2709         return ( a->material == b->material) ? 0 : -1;
2710 }
2711
2712 /*****************************************************************************/
2713 /* Function:    Material_repr    */
2714 /* Description: This is a callback function for the BPy_Material type. It  */
2715 /*               builds a meaninful string to represent material objects.   */
2716 /*****************************************************************************/
2717 static PyObject *Material_repr( BPy_Material * self )
2718 {
2719         return PyString_FromFormat( "[Material \"%s\"]",
2720                                     self->material->id.name + 2 );
2721 }
2722
2723 /*****************************************************************************/
2724 /* These functions are used here and in in Texture.c                                            */
2725 /*****************************************************************************/
2726 PyObject *EXPP_PyList_fromColorband( ColorBand *coba )
2727 {
2728         short i;
2729         PyObject *cbls;
2730         PyObject *colls;
2731         
2732         if (!coba)
2733                 return PyList_New( 0 );
2734         
2735         cbls = PyList_New( coba->tot );
2736         
2737         for (i=0; i < coba->tot; i++) {
2738                 colls = PyList_New( 5 );
2739                 PyList_SET_ITEM( colls, 0, PyFloat_FromDouble(coba->data[i].r) );
2740                 PyList_SET_ITEM( colls, 1, PyFloat_FromDouble(coba->data[i].g) );
2741                 PyList_SET_ITEM( colls, 2, PyFloat_FromDouble(coba->data[i].b) );
2742                 PyList_SET_ITEM( colls, 3, PyFloat_FromDouble(coba->data[i].a) );
2743                 PyList_SET_ITEM( colls, 4, PyFloat_FromDouble(coba->data[i].pos) );
2744                 PyList_SET_ITEM(cbls, i, colls);
2745         }
2746         return cbls;
2747 }
2748
2749 /* make sure you coba is not none before calling this */
2750 int EXPP_Colorband_fromPyList( ColorBand **coba, PyObject * value )
2751 {
2752         short totcol, i;
2753         PyObject *colseq;
2754         PyObject *pyflt;
2755         float f;
2756         
2757         if ( !PySequence_Check( value )  )
2758                 return ( EXPP_ReturnIntError( PyExc_TypeError,
2759                                 "Colorband must be a sequence" ) );
2760         
2761         totcol = PySequence_Size(value);
2762         if ( totcol > 31)
2763                 return ( EXPP_ReturnIntError( PyExc_ValueError,
2764                                 "Colorband must be between 1 and 31 in length" ) );
2765         
2766         if (totcol==0) {
2767                 MEM_freeN(*coba);
2768                 *coba = NULL;
2769                 return 0;
2770         }
2771         
2772         if (!*coba)
2773                 *coba = MEM_callocN( sizeof(ColorBand), "colorband");
2774         
2775         for (i=0; i<totcol; i++) {
2776                 colseq = PySequence_GetItem( value, i );
2777                 if ( !PySequence_Check( colseq ) || PySequence_Size( colseq ) != 5) {
2778                         Py_DECREF ( colseq );
2779                         return ( EXPP_ReturnIntError( PyExc_ValueError,
2780                                 "Colorband colors must be sequences of 5 floats" ) );
2781                 }
2782                 for (i=0; i<5; i++) {
2783                         pyflt = PySequence_GetItem( colseq, i );
2784                         if (!PyNumber_Check(pyflt)) {
2785                                 Py_DECREF ( pyflt );
2786                                 Py_DECREF ( colseq );
2787                                 return ( EXPP_ReturnIntError( PyExc_ValueError,
2788                                         "Colorband colors must be sequences of 5 floats" ) );
2789                         }
2790                         Py_DECREF ( pyflt );
2791                 }
2792                 Py_DECREF ( colseq );
2793         }
2794         
2795         /* ok, continue - should check for 5 floats, will ignore non floats for now */
2796         (*coba)->tot = totcol;
2797         for (i=0; i<totcol; i++) {
2798                 colseq = PySequence_GetItem( value, i );
2799                 
2800                 pyflt = PySequence_GetItem( colseq, 0 ); 
2801                 f = (float)PyFloat_AsDouble( pyflt );
2802                 CLAMP(f, 0.0, 1.0);
2803                 (*coba)->data[i].r = f;
2804                 Py_DECREF ( pyflt );
2805                 
2806                 pyflt = PySequence_GetItem( colseq, 1 ); 
2807                 f = (float)PyFloat_AsDouble( pyflt );
2808                 CLAMP(f, 0.0, 1.0);
2809                 (*coba)->data[i].g = f;
2810                 Py_DECREF ( pyflt );
2811                 
2812                 pyflt = PySequence_GetItem( colseq, 2 ); 
2813                 f = (float)PyFloat_AsDouble( pyflt );
2814                 CLAMP(f, 0.0, 1.0);
2815                 (*coba)->data[i].b = f;
2816                 Py_DECREF ( pyflt );
2817                 
2818                 pyflt = PySequence_GetItem( colseq, 3 ); 
2819                 f = (float)PyFloat_AsDouble( pyflt );
2820                 CLAMP(f, 0.0, 1.0);
2821                 (*coba)->data[i].a = f;
2822                 Py_DECREF ( pyflt );
2823                 
2824                 pyflt = PySequence_GetItem( colseq, 4 ); 
2825                 f = (float)PyFloat_AsDouble( pyflt );
2826                 CLAMP(f, 0.0, 1.0);
2827                 (*coba)->data[i].pos = f;
2828                 Py_DECREF ( pyflt );
2829                 
2830                 Py_DECREF ( colseq );
2831         }
2832         return 0;
2833 }
2834
2835
2836 /*****************************************************************************/
2837 /* These functions are used in NMesh.c and Object.c      */
2838 /*****************************************************************************/
2839 PyObject *EXPP_PyList_fromMaterialList( Material ** matlist, int len, int all )
2840 {
2841         PyObject *list;
2842         int i;
2843
2844         list = PyList_New( 0 );
2845         if( !matlist )
2846                 return list;
2847
2848         for( i = 0; i < len; i++ ) {
2849                 Material *mat = matlist[i];
2850                 PyObject *ob;
2851
2852                 if( mat ) {
2853                         ob = Material_CreatePyObject( mat );
2854                         PyList_Append( list, ob );
2855                         Py_DECREF( ob );        /* because Append increfs */
2856                 } else if( all ) {      /* return NULL mats (empty slots) as Py_None */
2857                         PyList_Append( list, Py_None );
2858                 }
2859         }
2860
2861         return list;
2862 }
2863
2864 Material **EXPP_newMaterialList_fromPyList( PyObject * list )
2865 {
2866         int i, len;
2867         BPy_Material *pymat = 0;
2868         Material *mat;
2869         Material **matlist;
2870
2871         len = PySequence_Length( list );
2872         if( len > 16 )
2873                 len = 16;
2874         else if( len <= 0 )
2875                 return NULL;
2876
2877         matlist = EXPP_newMaterialList( len );
2878
2879         for( i = 0; i < len; i++ ) {
2880
2881                 pymat = ( BPy_Material * ) PySequence_GetItem( list, i );
2882
2883                 if( BPy_Material_Check( ( PyObject * ) pymat ) ) {
2884                         mat = pymat->material;
2885                         matlist[i] = mat;
2886                 } else if( ( PyObject * ) pymat == Py_None ) {
2887                         matlist[i] = NULL;
2888                 } else {        /* error; illegal type in material list */
2889                         Py_DECREF( pymat );
2890                         MEM_freeN( matlist );
2891                         return NULL;
2892                 }
2893
2894                 Py_DECREF( pymat );
2895         }
2896
2897         return matlist;
2898 }
2899
2900 Material **EXPP_newMaterialList( int len )
2901 {
2902         Material **matlist =
2903                 ( Material ** ) MEM_mallocN( len * sizeof( Material * ),
2904                                              "MaterialList" );
2905
2906         return matlist;
2907 }
2908
2909 int EXPP_releaseMaterialList( Material ** matlist, int len )
2910 {
2911         int i;
2912         Material *mat;
2913
2914         if( ( len < 0 ) || ( len > MAXMAT ) ) {
2915                 printf( "illegal matindex!\n" );
2916                 return 0;
2917         }
2918
2919         for( i = 0; i < len; i++ ) {
2920                 mat = matlist[i];
2921                 if( mat ) {
2922                         if( ( ( ID * ) mat )->us > 0 )
2923                                 ( ( ID * ) mat )->us--;
2924                         else
2925                                 printf( "FATAL: material usage=0: %s",
2926                                         ( ( ID * ) mat )->name );
2927                 }
2928         }
2929         MEM_freeN( matlist );
2930
2931         return 1;
2932 }
2933
2934 /** expands pointer array of length 'oldsize' to length 'newsize'.
2935         * A pointer to the (void *) array must be passed as first argument 
2936         * The array pointer content can be NULL, in this case a new array of length
2937         * 'newsize' is created.
2938         */
2939
2940 static int expandPtrArray( void **p, int oldsize, int newsize )
2941 {
2942         void *newarray;
2943
2944         if( newsize < oldsize ) {
2945                 return 0;
2946         }
2947         newarray = MEM_callocN( sizeof( void * ) * newsize, "PtrArray" );
2948         if( *p ) {
2949                 memcpy( newarray, *p, sizeof( void * ) * oldsize );
2950                 MEM_freeN( *p );
2951         }
2952         *p = newarray;
2953         return 1;
2954 }
2955
2956 int EXPP_synchronizeMaterialLists( Object * object )
2957 {
2958         Material ***p_dataMaterials = give_matarar( object );
2959         short *nmaterials = give_totcolp( object );
2960         int result = 0;
2961
2962         if( object->totcol > *nmaterials ) {
2963                 /* More object mats than data mats */
2964                 result = expandPtrArray( ( void * ) p_dataMaterials,
2965                                          *nmaterials, object->totcol );
2966                 *nmaterials = object->totcol;
2967         } else {
2968                 if( object->totcol < *nmaterials ) {
2969                         /* More data mats than object mats */
2970                         result = expandPtrArray( ( void * ) &object->mat,
2971                                                  object->totcol, *nmaterials );
2972                         object->totcol = (char)*nmaterials;
2973                 }
2974         }                       /* else no synchronization needed, they are of equal length */
2975
2976         return result;          /* 1 if changed, 0 otherwise */
2977 }
2978
2979 void EXPP_incr_mats_us( Material ** matlist, int len )
2980 {
2981         int i;
2982         Material *mat;
2983
2984         if( len <= 0 )
2985                 return;
2986
2987         for( i = 0; i < len; i++ ) {
2988                 mat = matlist[i];
2989                 if( mat )
2990                         mat->id.us++;
2991         }
2992
2993         return;
2994 }
2995
2996 static PyObject *Material_getColorComponent( BPy_Material * self, 
2997                                                         void * closure )
2998 {
2999         switch ( GET_INT_FROM_POINTER(closure) ) {
3000         case EXPP_MAT_COMP_R:
3001                 return PyFloat_FromDouble( ( double ) self->material->r );
3002         case EXPP_MAT_COMP_G:
3003                 return PyFloat_FromDouble( ( double ) self->material->g );
3004         case EXPP_MAT_COMP_B:
3005                 return PyFloat_FromDouble( ( double ) self->material->b );
3006         case EXPP_MAT_COMP_SPECR:
3007                 return PyFloat_FromDouble( ( double ) self->material->specr );
3008         case EXPP_MAT_COMP_SPECG:
3009                 return PyFloat_FromDouble( ( double ) self->material->specg );
3010         case EXPP_MAT_COMP_SPECB:
3011                 return PyFloat_FromDouble( ( double ) self->material->specb );
3012         case EXPP_MAT_COMP_MIRR:
3013                 return PyFloat_FromDouble( ( double ) self->material->mirr );
3014         case EXPP_MAT_COMP_MIRG:
3015                 return PyFloat_FromDouble( ( double ) self->material->mirg );
3016         case EXPP_MAT_COMP_MIRB:
3017                 return PyFloat_FromDouble( ( double ) self->material->mirb );
3018         case EXPP_MAT_COMP_SSSR:
3019                 return PyFloat_FromDouble( ( double ) self->material->sss_col[0] );
3020         case EXPP_MAT_COMP_SSSG:
3021                 return PyFloat_FromDouble( ( double ) self->material->sss_col[1] );
3022         case EXPP_MAT_COMP_SSSB:
3023                 return PyFloat_FromDouble( ( double ) self->material->sss_col[2] );
3024         default:
3025                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
3026                                         "unknown color component specified" );
3027         }
3028 }
3029
3030 static PyObject *Material_getColorband( BPy_Material * self, void * type)
3031 {
3032         switch( (long)type ) {
3033     case 0:     /* these are backwards, but that how it works */
3034                 return EXPP_PyList_fromColorband( self->material->ramp_col );
3035     case 1:
3036                 return EXPP_PyList_fromColorband( self->material->ramp_spec );
3037         }
3038         Py_RETURN_NONE;
3039 }
3040
3041 static int Material_setColorband( BPy_Material * self, PyObject * value, void * type)
3042 {
3043         switch( (long)type ) {
3044     case 0:     /* these are backwards, but that how it works */
3045                 return EXPP_Colorband_fromPyList( &self->material->ramp_col, value );
3046     case 1:
3047                 return EXPP_Colorband_fromPyList( &self->material->ramp_spec, value );
3048         }
3049         return 0;
3050 }
3051
3052 /* #####DEPRECATED###### */
3053
3054 static PyObject *Matr_oldsetAdd( BPy_Material * self, PyObject * args )
3055 {
3056         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setAdd );
3057 }
3058
3059 static PyObject *Matr_oldsetAlpha( BPy_Material * self, PyObject * args )
3060 {
3061         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setAlpha );
3062 }
3063
3064 static PyObject *Matr_oldsetAmb( BPy_Material * self, PyObject * args )
3065 {
3066         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setAmb );
3067 }
3068
3069 static PyObject *Matr_oldsetDiffuseDarkness( BPy_Material * self, PyObject * args )
3070 {
3071         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setDiffuseDarkness );
3072 }
3073
3074 static PyObject *Matr_oldsetDiffuseShader( BPy_Material * self, PyObject * args )
3075 {
3076         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setDiffuseShader );
3077 }
3078
3079 static PyObject *Matr_oldsetDiffuseSize( BPy_Material * self, PyObject * args )
3080 {
3081         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setDiffuseSize );
3082 }
3083
3084 static PyObject *Matr_oldsetDiffuseSmooth( BPy_Material * self, PyObject * args )
3085 {
3086         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setDiffuseSmooth );
3087 }
3088
3089 static PyObject *Matr_oldsetEmit( BPy_Material * self, PyObject * args )
3090 {
3091         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setEmit );
3092 }
3093
3094 static PyObject *Matr_oldsetFilter( BPy_Material * self, PyObject * args )
3095 {
3096         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFilter );
3097 }
3098
3099 static PyObject *Matr_oldsetFlareBoost( BPy_Material * self, PyObject * args )
3100 {
3101         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFlareBoost );
3102 }
3103
3104 static PyObject *Matr_oldsetFlareSeed( BPy_Material * self, PyObject * args )
3105 {
3106         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFlareSeed );
3107 }
3108
3109 static PyObject *Matr_oldsetFlareSize( BPy_Material * self, PyObject * args )
3110 {
3111         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFlareSize );
3112 }
3113
3114 static PyObject *Matr_oldsetFresnelMirr( BPy_Material * self, PyObject * args )
3115 {
3116         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFresnelMirr );
3117 }
3118
3119 static PyObject *Matr_oldsetFresnelMirrFac( BPy_Material * self,
3120                                              PyObject * args )
3121 {
3122         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFresnelMirrFac );
3123 }
3124
3125 static PyObject *Matr_oldsetFresnelTrans( BPy_Material * self,
3126                                            PyObject * args )
3127 {
3128         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFresnelTrans );
3129 }
3130
3131 static PyObject *Matr_oldsetFresnelTransFac( BPy_Material * self,
3132                                               PyObject * args )
3133 {
3134         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFresnelTransFac );
3135 }
3136
3137 static PyObject *Matr_oldsetHaloSeed( BPy_Material * self, PyObject * args )
3138 {
3139         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setHaloSeed );
3140 }
3141
3142 static PyObject *Matr_oldsetHaloSize( BPy_Material * self, PyObject * args )
3143 {
3144         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setHaloSize );
3145 }
3146
3147 static PyObject *Matr_oldsetHardness( BPy_Material * self, PyObject * args )
3148 {
3149         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setHardness );
3150 }
3151
3152 static PyObject *Matr_oldsetIOR( BPy_Material * self, PyObject * args )
3153 {
3154         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setIOR );
3155 }
3156
3157 static PyObject *Matr_oldsetNFlares( BPy_Material * self, PyObject * args )
3158 {
3159         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setNFlares );
3160 }
3161
3162 static PyObject *Matr_oldsetNLines( BPy_Material * self, PyObject * args )
3163 {
3164         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setNLines );
3165 }
3166
3167 static PyObject *Matr_oldsetNRings( BPy_Material * self, PyObject * args )
3168 {
3169         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setNRings );
3170 }
3171
3172 static PyObject *Matr_oldsetNStars( BPy_Material * self, PyObject * args )
3173 {
3174         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setNStars );
3175 }
3176
3177 static PyObject *Matr_oldsetRayMirr( BPy_Material * self, PyObject * args )
3178 {
3179         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setRayMirr );
3180 }
3181
3182 static PyObject *Matr_oldsetRoughness( BPy_Material * self, PyObject * args )
3183 {
3184         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setRoughness );
3185 }
3186
3187 static PyObject *Matr_oldsetMirrDepth( BPy_Material * self, PyObject * args )
3188 {
3189         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setMirrDepth );
3190 }
3191
3192 static PyObject *Matr_oldsetRef( BPy_Material * self, PyObject * args )
3193 {
3194         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setRef );
3195 }
3196
3197 static PyObject *Matr_oldsetRefracIndex( BPy_Material * self, PyObject * args )
3198 {
3199         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setRefracIndex );
3200 }
3201
3202 static PyObject *Matr_oldsetRms( BPy_Material * self, PyObject * args )
3203 {
3204         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setRms );
3205 }
3206
3207 static PyObject *Matr_oldsetSpec( BPy_Material * self, PyObject * args )
3208 {
3209         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setSpec );
3210 }
3211
3212 static PyObject *Matr_oldsetSpecShader( BPy_Material * self, PyObject * args )
3213 {
3214         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setSpecShader );
3215 }
3216
3217 static PyObject *Matr_oldsetSpecSize( BPy_Material * self, PyObject * args )
3218 {
3219         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setSpecSize );
3220 }
3221
3222 static PyObject *Matr_oldsetSpecSmooth( BPy_Material * self, PyObject * args )
3223 {
3224         return EXPP_setterWrapper( (void *)self, args, (setter)Material_setSpecSmooth );