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