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