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