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