7682facd8179991f79daee7bd20c81ada633a039
[blender-staging.git] / source / blender / python / api2_2x / Texture.c
1 /*  
2  *  $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA    02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * This is a new part of Blender.
27  *
28  * Contributor(s): Alex Mole, Nathan Letwory, Joilnen B. Leite, Ken Hughes
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31 */
32 #include "Texture.h" /*This must come first*/
33
34 #include "BKE_global.h"
35 #include "BKE_main.h"
36 #include "BKE_library.h"
37 #include "BLI_blenlib.h"
38 #include "BKE_texture.h"
39 #include "BKE_utildefines.h"
40 #include "DNA_material_types.h"
41 #include "MTex.h"
42 #include "Image.h"
43 #include "Ipo.h"
44 #include "constant.h"
45 #include "blendef.h"
46 #include "render.h"
47 #include "gen_utils.h"
48
49 /*****************************************************************************/
50 /* Blender.Texture constants                                                 */
51 /*****************************************************************************/
52 #define EXPP_TEX_TYPE_NONE                  0
53
54 #define EXPP_TEX_TYPE_MIN                   EXPP_TEX_TYPE_NONE
55 #define EXPP_TEX_TYPE_MAX                   TEX_DISTNOISE
56
57 #define EXPP_TEX_ANIMFRAME_MIN              0
58 #define EXPP_TEX_ANIMFRAME_MAX              ((int)MAXFRAMEF)
59 #define EXPP_TEX_ANIMLEN_MIN                0
60 #define EXPP_TEX_ANIMLEN_MAX                ((int)(MAXFRAMEF)/2)
61 #define EXPP_TEX_ANIMMONSTART_MIN           0
62 #define EXPP_TEX_ANIMMONSTART_MAX           ((int)MAXFRAMEF)
63 #define EXPP_TEX_ANIMMONDUR_MIN             0
64 #define EXPP_TEX_ANIMMONDUR_MAX             250
65 #define EXPP_TEX_ANIMOFFSET_MIN             -((int)(MAXFRAMEF)/2)
66 #define EXPP_TEX_ANIMOFFSET_MAX             ((int)(MAXFRAMEF)/2)
67 #define EXPP_TEX_ANIMSTART_MIN              0
68 #define EXPP_TEX_ANIMSTART_MAX              ((int)(MAXFRAMEF)/2)
69 #define EXPP_TEX_FIEIMA_MIN                 1
70 #define EXPP_TEX_FIEIMA_MAX                 200
71 #define EXPP_TEX_NOISEDEPTH_MIN             0
72 #define EXPP_TEX_NOISEDEPTH_MAX             6
73 /* max depth is different for magic type textures */
74 #define EXPP_TEX_NOISEDEPTH_MAX_MAGIC       10
75 #define EXPP_TEX_REPEAT_MIN                 1
76 #define EXPP_TEX_REPEAT_MAX                 512
77
78 #define EXPP_TEX_FILTERSIZE_MIN             0.1f
79 #define EXPP_TEX_FILTERSIZE_MAX             25.0f
80 #define EXPP_TEX_NOISESIZE_MIN              0.0001f
81 #define EXPP_TEX_NOISESIZE_MAX              2.0f
82 #define EXPP_TEX_BRIGHTNESS_MIN             0.0f
83 #define EXPP_TEX_BRIGHTNESS_MAX             2.0f
84 #define EXPP_TEX_CONTRAST_MIN               0.01f
85 #define EXPP_TEX_CONTRAST_MAX               5.0f
86 #define EXPP_TEX_CROP_MIN                   -10.0f
87 #define EXPP_TEX_CROP_MAX                   10.0f
88 #define EXPP_TEX_RGBCOL_MIN                 0.0f
89 #define EXPP_TEX_RGBCOL_MAX                 2.0f
90 #define EXPP_TEX_TURBULENCE_MIN             0.0f
91 #define EXPP_TEX_TURBULENCE_MAX             200.0f
92 #define EXPP_TEX_MH_G_MIN                   0.0001f
93 #define EXPP_TEX_MH_G_MAX                   2.0f
94 #define EXPP_TEX_LACUNARITY_MIN             0.0f
95 #define EXPP_TEX_LACUNARITY_MAX             6.0f
96 #define EXPP_TEX_OCTS_MIN                   0.0f
97 #define EXPP_TEX_OCTS_MAX                   8.0f
98 #define EXPP_TEX_ISCALE_MIN                 0.0f
99 #define EXPP_TEX_ISCALE_MAX                 10.0f
100 #define EXPP_TEX_EXP_MIN                    0.010f
101 #define EXPP_TEX_EXP_MAX                    10.0f
102 #define EXPP_TEX_WEIGHT1_MIN                -2.0f
103 #define EXPP_TEX_WEIGHT1_MAX                2.0f
104 #define EXPP_TEX_WEIGHT2_MIN                -2.0f
105 #define EXPP_TEX_WEIGHT2_MAX                2.0f
106 #define EXPP_TEX_WEIGHT3_MIN                -2.0f
107 #define EXPP_TEX_WEIGHT3_MAX                2.0f
108 #define EXPP_TEX_WEIGHT4_MIN                -2.0f
109 #define EXPP_TEX_WEIGHT4_MAX                2.0f
110 #define EXPP_TEX_DISTAMNT_MIN               0.0f
111 #define EXPP_TEX_DISTAMNT_MAX               10.0f
112
113 /* i can't find these defined anywhere- they're just taken from looking at   */
114 /* the button creation code in source/blender/src/buttons_shading.c          */
115 /* cloud stype */
116 #define EXPP_TEX_STYPE_CLD_DEFAULT          0
117 #define EXPP_TEX_STYPE_CLD_COLOR            1
118 /* wood stype */
119 #define EXPP_TEX_STYPE_WOD_BANDS            0
120 #define EXPP_TEX_STYPE_WOD_RINGS            1
121 #define EXPP_TEX_STYPE_WOD_BANDNOISE        2
122 #define EXPP_TEX_STYPE_WOD_RINGNOISE        3
123 /* magic stype */
124 #define EXPP_TEX_STYPE_MAG_DEFAULT          0
125 /* marble stype */
126 #define EXPP_TEX_STYPE_MBL_SOFT             0
127 #define EXPP_TEX_STYPE_MBL_SHARP            1
128 #define EXPP_TEX_STYPE_MBL_SHARPER          2
129 /* blend stype */
130 #define EXPP_TEX_STYPE_BLN_LIN              0
131 #define EXPP_TEX_STYPE_BLN_QUAD             1
132 #define EXPP_TEX_STYPE_BLN_EASE             2
133 #define EXPP_TEX_STYPE_BLN_DIAG             3
134 #define EXPP_TEX_STYPE_BLN_SPHERE           4
135 #define EXPP_TEX_STYPE_BLN_HALO             5
136 /* stucci stype */
137 #define EXPP_TEX_STYPE_STC_PLASTIC          0
138 #define EXPP_TEX_STYPE_STC_WALLIN           1
139 #define EXPP_TEX_STYPE_STC_WALLOUT          2
140 /* noise stype */
141 #define EXPP_TEX_STYPE_NSE_DEFAULT          0
142 /* image stype */
143 #define EXPP_TEX_STYPE_IMG_DEFAULT          0
144 /* plug-in stype */
145 #define EXPP_TEX_STYPE_PLG_DEFAULT          0
146 /* envmap stype */
147 #define EXPP_TEX_STYPE_ENV_STATIC           0
148 #define EXPP_TEX_STYPE_ENV_ANIM             1
149 #define EXPP_TEX_STYPE_ENV_LOAD             2
150 /* musgrave stype */
151 #define EXPP_TEX_STYPE_MUS_MFRACTAL         0
152 #define EXPP_TEX_STYPE_MUS_RIDGEDMF         1
153 #define EXPP_TEX_STYPE_MUS_HYBRIDMF         2
154 #define EXPP_TEX_STYPE_MUS_FBM              3
155 #define EXPP_TEX_STYPE_MUS_HTERRAIN         4
156 /* voronoi stype */
157 #define EXPP_TEX_STYPE_VN_INT               0
158 #define EXPP_TEX_STYPE_VN_COL1              1
159 #define EXPP_TEX_STYPE_VN_COL2              2
160 #define EXPP_TEX_STYPE_VN_COL3              3
161
162 #define EXPP_TEX_EXTEND_MIN                 TEX_EXTEND
163 #define EXPP_TEX_EXTEND_MAX                 TEX_CHECKER
164
165 #define EXPP_TEX_NOISE_SINE                                     0
166 #define EXPP_TEX_NOISE_SAW                                      1
167 #define EXPP_TEX_NOISE_TRI                                      2
168 #define EXPP_TEX_NOISEBASIS2                            0xffff
169
170 /****************************************************************************/
171 /* Texture String->Int maps                                                 */
172 /****************************************************************************/
173
174 static const EXPP_map_pair tex_type_map[] = {
175         {"None", EXPP_TEX_TYPE_NONE},
176         {"Clouds", TEX_CLOUDS},
177         {"Wood", TEX_WOOD},
178         {"Marble", TEX_MARBLE},
179         {"Magic", TEX_MAGIC},
180         {"Blend", TEX_BLEND},
181         {"Stucci", TEX_STUCCI},
182         {"Noise", TEX_NOISE},
183         {"Image", TEX_IMAGE},
184         {"Plugin", TEX_PLUGIN},
185         {"EnvMap", TEX_ENVMAP},
186         {"Musgrave", TEX_MUSGRAVE},
187         {"Voronoi", TEX_VORONOI},
188         {"DistortedNoise", TEX_DISTNOISE},
189         {NULL, 0}
190 };
191
192 static const EXPP_map_pair tex_flag_map[] = {
193 /* NOTE "CheckerOdd" and "CheckerEven" are new */
194 #if 0
195     {"ColorBand",  TEX_COLORBAND },
196 #endif
197         {"FlipBlend", TEX_FLIPBLEND},
198         {"NegAlpha", TEX_NEGALPHA},
199         {"CheckerOdd",TEX_CHECKER_ODD},
200         {"CheckerEven",TEX_CHECKER_EVEN},
201         {NULL, 0}
202 };
203
204 static const EXPP_map_pair tex_imageflag_map[] = {
205         {"InterPol", TEX_INTERPOL},
206         {"UseAlpha", TEX_USEALPHA},
207         {"MipMap", TEX_MIPMAP},
208         {"Fields", TEX_FIELDS},
209         {"Rot90", TEX_IMAROT},
210         {"CalcAlpha", TEX_CALCALPHA},
211         {"Cyclic", TEX_ANIMCYCLIC},
212         {"Movie", TEX_ANIM5},
213         {"StField", TEX_STD_FIELD},
214         {"Anti", TEX_ANTIALI},
215         {"NormalMap", TEX_NORMALMAP},
216         {NULL, 0}
217 };
218
219 static const EXPP_map_pair tex_extend_map[] = {
220         {"Extend", TEX_EXTEND},
221         {"Clip", TEX_CLIP},
222         {"ClipCube", TEX_CLIPCUBE},
223         {"Repeat", TEX_REPEAT},
224 /* NOTE "Checker" is new */
225         {"Checker", TEX_CHECKER},
226         {NULL, 0}
227 };
228
229 /* array of maps for stype */
230 static const EXPP_map_pair tex_stype_default_map[] = {
231         {"Default", 0},
232         {NULL, 0}
233 };
234 static const EXPP_map_pair tex_stype_clouds_map[] = {
235         {"Default", 0},
236         {"CloudDefault", EXPP_TEX_STYPE_CLD_DEFAULT},
237         {"CloudColor", EXPP_TEX_STYPE_CLD_COLOR},
238         {NULL, 0}
239 };
240 static const EXPP_map_pair tex_stype_wood_map[] = {
241         {"Default", 0},
242         {"WoodBands", EXPP_TEX_STYPE_WOD_BANDS},
243         {"WoodRings", EXPP_TEX_STYPE_WOD_RINGS},
244         {"WoodBandNoise", EXPP_TEX_STYPE_WOD_BANDNOISE},
245         {"WoodRingNoise", EXPP_TEX_STYPE_WOD_RINGNOISE},
246         {NULL, 0}
247 };
248 static const EXPP_map_pair tex_stype_marble_map[] = {
249         {"Default", 0},
250         {"MarbleSoft", EXPP_TEX_STYPE_MBL_SOFT},
251         {"MarbleSharp", EXPP_TEX_STYPE_MBL_SHARP},
252         {"MarbleSharper", EXPP_TEX_STYPE_MBL_SHARPER},
253         {NULL, 0}
254 };
255 static const EXPP_map_pair tex_stype_blend_map[] = {
256         {"Default", 0},
257         {"BlendLin", EXPP_TEX_STYPE_BLN_LIN},
258         {"BlendQuad", EXPP_TEX_STYPE_BLN_QUAD},
259         {"BlendEase", EXPP_TEX_STYPE_BLN_EASE},
260         {"BlendDiag", EXPP_TEX_STYPE_BLN_DIAG},
261         {"BlendSphere", EXPP_TEX_STYPE_BLN_SPHERE},
262         {"BlendHalo", EXPP_TEX_STYPE_BLN_HALO},
263         {NULL, 0}
264 };
265 static const EXPP_map_pair tex_stype_stucci_map[] = {
266         {"Default", 0},
267         {"StucciPlastic", EXPP_TEX_STYPE_STC_PLASTIC},
268         {"StucciWallIn", EXPP_TEX_STYPE_STC_WALLIN},
269         {"StucciWallOut", EXPP_TEX_STYPE_STC_WALLOUT},
270         {NULL, 0}
271 };
272 static const EXPP_map_pair tex_stype_envmap_map[] = {
273         {"Default", 0},
274         {"EnvmapStatic", EXPP_TEX_STYPE_ENV_STATIC},
275         {"EnvmapAnim", EXPP_TEX_STYPE_ENV_ANIM},
276         {"EnvmapLoad", EXPP_TEX_STYPE_ENV_LOAD},
277         {NULL, 0}
278 };
279
280 static const EXPP_map_pair tex_stype_musg_map[] = {
281         {"Default", 0},
282         {"MultiFractal", EXPP_TEX_STYPE_MUS_MFRACTAL},
283         {"HeteroTerrain", EXPP_TEX_STYPE_MUS_HTERRAIN},
284         {"RidgedMultiFractal", EXPP_TEX_STYPE_MUS_RIDGEDMF},
285         {"HybridMultiFractal", EXPP_TEX_STYPE_MUS_HYBRIDMF},
286         {"fBM", EXPP_TEX_STYPE_MUS_FBM},
287         {NULL, 0}
288 };
289
290 static const EXPP_map_pair tex_stype_distortednoise_map[] = {
291         {"Default", 0},
292         {"BlenderOriginal", TEX_BLENDER},
293         {"OriginalPerlin", TEX_STDPERLIN},
294         {"ImprovedPerlin", TEX_NEWPERLIN},
295         {"VoronoiF1", TEX_VORONOI_F1},
296         {"VoronoiF2", TEX_VORONOI_F2},
297         {"VoronoiF3", TEX_VORONOI_F3},
298         {"VoronoiF4", TEX_VORONOI_F4},
299         {"VoronoiF2-F1", TEX_VORONOI_F2F1},
300         {"VoronoiCrackle", TEX_VORONOI_CRACKLE},
301         {"CellNoise", TEX_CELLNOISE},
302         {NULL, 0}
303 };
304
305 static const EXPP_map_pair tex_stype_voronoi_map[] = {
306         {"Default", 0},
307         {"Int", EXPP_TEX_STYPE_VN_INT},
308         {"Col1", EXPP_TEX_STYPE_VN_COL1},
309         {"Col2", EXPP_TEX_STYPE_VN_COL2},
310         {"Col3", EXPP_TEX_STYPE_VN_COL3},
311         {NULL, 0}
312 };
313
314 static const EXPP_map_pair tex_distance_voronoi_map[] = {
315         {"Default", 0},
316         {"Distance", TEX_DISTANCE},
317         {"DistanceSquared", TEX_DISTANCE_SQUARED},
318         {"Manhattan", TEX_MANHATTAN},
319         {"Chebychev", TEX_CHEBYCHEV},
320         {"MinkovskyHalf", TEX_MINKOVSKY_HALF},
321         {"MinkovskyFour", TEX_MINKOVSKY_FOUR},
322         {"Minkovsky", TEX_MINKOVSKY},
323         {NULL, 0}
324 };
325
326 static const EXPP_map_pair *tex_stype_map[] = {
327         tex_stype_default_map,  /* none */
328         tex_stype_clouds_map,
329         tex_stype_wood_map,
330         tex_stype_marble_map,
331         tex_stype_default_map,  /* magic */
332         tex_stype_blend_map,
333         tex_stype_stucci_map,
334         tex_stype_default_map,  /* noise */
335         tex_stype_default_map,  /* image */
336         tex_stype_default_map,  /* plugin */
337         tex_stype_envmap_map,
338         tex_stype_musg_map,     /* musgrave */
339         tex_stype_voronoi_map,  /* voronoi */
340         tex_stype_distortednoise_map,   /* distorted noise */
341         tex_distance_voronoi_map
342 };
343
344 /*****************************************************************************/
345 /* Python API function prototypes for the Texture module.                    */
346 /*****************************************************************************/
347 static PyObject *M_Texture_New( PyObject * self, PyObject * args,
348                                 PyObject * keywords );
349 static PyObject *M_Texture_Get( PyObject * self, PyObject * args );
350
351 /*****************************************************************************/
352 /* The following string definitions are used for documentation strings.      */
353 /* In Python these will be written to the console when doing a               */
354 /* Blender.Texture.__doc__                                                   */
355 /*****************************************************************************/
356 static char M_Texture_doc[] = "The Blender Texture module\n\
357 \n\
358 This module provides access to **Texture** objects in Blender\n";
359
360 static char M_Texture_New_doc[] = "Texture.New (name = 'Tex'):\n\
361         Return a new Texture object with the given type and name.";
362
363 static char M_Texture_Get_doc[] = "Texture.Get (name = None):\n\
364         Return the texture with the given 'name', None if not found, or\n\
365         Return a list with all texture objects in the current scene,\n\
366         if no argument was given.";
367
368 /*****************************************************************************/
369 /* Python method structure definition for Blender.Texture module:            */
370 /*****************************************************************************/
371 struct PyMethodDef M_Texture_methods[] = {
372         {"New", ( PyCFunction ) M_Texture_New, METH_VARARGS | METH_KEYWORDS,
373          M_Texture_New_doc},
374         {"Get", M_Texture_Get, METH_VARARGS, M_Texture_Get_doc},
375         {NULL, NULL, 0, NULL}
376 };
377
378 /*****************************************************************************/
379 /* Python BPy_Texture methods declarations:                                  */
380 /*****************************************************************************/
381 #define GETFUNC(name)   static PyObject *Texture_##name(BPy_Texture *self)
382 #define OLDSETFUNC(name)   static PyObject *Texture_old##name(BPy_Texture *self,   \
383                                                         PyObject *args)
384 #define SETFUNC(name)   static int Texture_##name(BPy_Texture *self,   \
385                                                         PyObject *value)
386 #if 0
387 GETFUNC( getExtend );
388 GETFUNC( getImage );
389 GETFUNC( getName );
390 GETFUNC( getType );
391 GETFUNC( getSType );
392 GETFUNC( clearIpo );
393 #endif
394
395 GETFUNC( oldgetSType );
396 GETFUNC( oldgetType );
397
398 GETFUNC( clearIpo );
399 GETFUNC( getAnimFrames );
400 GETFUNC( getAnimLength );
401 GETFUNC( getAnimMontage );
402 GETFUNC( getAnimOffset );
403 GETFUNC( getAnimStart );
404 GETFUNC( getBrightness );
405 GETFUNC( getContrast );
406 GETFUNC( getCrop );
407 GETFUNC( getDistAmnt );
408 GETFUNC( getDistMetric );
409 GETFUNC( getExp );
410 GETFUNC( getExtend );
411 GETFUNC( getIntExtend );
412 GETFUNC( getFieldsPerImage );
413 GETFUNC( getFilterSize );
414 GETFUNC( getFlags );
415 GETFUNC( getHFracDim );
416 GETFUNC( getImage );
417 GETFUNC( getIpo );
418 GETFUNC( getIScale );
419 GETFUNC( getLacunarity );
420 GETFUNC( getName );
421 GETFUNC( getNoiseBasis );
422 GETFUNC( getNoiseDepth );
423 GETFUNC( getNoiseSize );
424 GETFUNC( getNoiseType );
425 GETFUNC( getOcts );
426 GETFUNC( getRepeat );
427 GETFUNC( getRGBCol );
428 GETFUNC( getSType );
429 GETFUNC( getTurbulence );
430 GETFUNC( getType );
431 GETFUNC( getWeight1 );
432 GETFUNC( getWeight2 );
433 GETFUNC( getWeight3 );
434 GETFUNC( getWeight4 );
435 GETFUNC( getUsers );
436
437 OLDSETFUNC( setDistMetric );
438 OLDSETFUNC( setDistNoise );     /* special case used for ".noisebasis = ...  */
439 OLDSETFUNC( setExtend );
440 OLDSETFUNC( setFlags );
441 OLDSETFUNC( setImage );
442 OLDSETFUNC( setImageFlags );
443 OLDSETFUNC( setIpo );
444 OLDSETFUNC( setName );
445 OLDSETFUNC( setNoiseBasis );
446 OLDSETFUNC( setSType );
447 OLDSETFUNC( setType );
448
449 SETFUNC( setAnimFrames );
450 SETFUNC( setAnimLength );
451 SETFUNC( setAnimMontage );
452 SETFUNC( setAnimOffset );
453 SETFUNC( setAnimStart );
454 SETFUNC( setBrightness );
455 SETFUNC( setContrast );
456 SETFUNC( setCrop );
457 SETFUNC( setDistAmnt );
458 SETFUNC( setDistMetric );
459 SETFUNC( setExp );
460 SETFUNC( setIntExtend );
461 SETFUNC( setFieldsPerImage );
462 SETFUNC( setFilterSize );
463 SETFUNC( setFlags );
464 SETFUNC( setHFracDim );
465 SETFUNC( setImage );
466 SETFUNC( setIpo );
467 SETFUNC( setIScale );
468 SETFUNC( setLacunarity );
469 SETFUNC( setName );
470 SETFUNC( setNoiseBasis );
471 SETFUNC( setNoiseDepth );
472 SETFUNC( setNoiseSize );
473 SETFUNC( setNoiseType );
474 SETFUNC( setOcts );
475 SETFUNC( setRepeat );
476 SETFUNC( setRGBCol );
477 SETFUNC( setSType );
478 SETFUNC( setTurbulence );
479 SETFUNC( setType );
480 SETFUNC( setWeight1 );
481 SETFUNC( setWeight2 );
482 SETFUNC( setWeight3 );
483 SETFUNC( setWeight4 );
484
485 static PyObject *Texture_getImageFlags( BPy_Texture *self, void *type );
486 static PyObject *Texture_getNoiseBasis2( BPy_Texture *self, void *type );
487 static int Texture_setImageFlags( BPy_Texture *self, PyObject *args,
488                                                                 void *type );
489 static int Texture_setNoiseBasis2( BPy_Texture *self, PyObject *args,
490                                                                 void *type );
491
492 /*****************************************************************************/
493 /* Python BPy_Texture methods table:                                         */
494 /*****************************************************************************/
495 static PyMethodDef BPy_Texture_methods[] = {
496         /* name, method, flags, doc */
497         {"getExtend", ( PyCFunction ) Texture_getExtend, METH_NOARGS,
498          "() - Return Texture extend mode"},
499         {"getImage", ( PyCFunction ) Texture_getImage, METH_NOARGS,
500          "() - Return Texture Image"},
501         {"getName", ( PyCFunction ) Texture_getName, METH_NOARGS,
502          "() - Return Texture name"},
503         {"getSType", ( PyCFunction ) Texture_oldgetSType, METH_NOARGS,
504          "() - Return Texture stype as string"},
505         {"getType", ( PyCFunction ) Texture_oldgetType, METH_NOARGS,
506          "() - Return Texture type as string"},
507         {"getIpo", ( PyCFunction ) Texture_getIpo, METH_NOARGS,
508          "() - Return Texture Ipo"},
509         {"setIpo", ( PyCFunction ) Texture_oldsetIpo, METH_VARARGS,
510          "(Blender Ipo) - Set Texture Ipo"},
511         {"clearIpo", ( PyCFunction ) Texture_clearIpo, METH_NOARGS,
512          "() - Unlink Ipo from this Texture."},
513         {"setExtend", ( PyCFunction ) Texture_oldsetExtend, METH_VARARGS,
514          "(s) - Set Texture extend mode"},
515         {"setFlags", ( PyCFunction ) Texture_oldsetFlags, METH_VARARGS,
516          "(f1,f2,f3,f4,f5) - Set Texture flags"},
517         {"setImage", ( PyCFunction ) Texture_oldsetImage, METH_VARARGS,
518          "(Blender Image) - Set Texture Image"},
519         {"setImageFlags", ( PyCFunction ) Texture_oldsetImageFlags, METH_VARARGS,
520          "(s,s,s,s,...) - Set Texture image flags"},
521         {"setName", ( PyCFunction ) Texture_oldsetName, METH_VARARGS,
522          "(s) - Set Texture name"},
523         {"setSType", ( PyCFunction ) Texture_oldsetSType, METH_VARARGS,
524          "(s) - Set Texture stype"},
525         {"setType", ( PyCFunction ) Texture_oldsetType, METH_VARARGS,
526          "(s) - Set Texture type"},
527         {"setNoiseBasis", ( PyCFunction ) Texture_oldsetNoiseBasis, METH_VARARGS,
528          "(s) - Set Noise basis"},
529         {"setDistNoise", ( PyCFunction ) Texture_oldsetDistNoise, METH_VARARGS,
530          "(s) - Set Dist Noise"},
531         {"setDistMetric", ( PyCFunction ) Texture_oldsetDistMetric, METH_VARARGS,
532          "(s) - Set Dist Metric"},
533         {NULL, NULL, 0, NULL}
534 };
535
536 /*****************************************************************************/
537 /* Python Texture_Type attributes get/set structure:                         */
538 /*****************************************************************************/
539 static PyGetSetDef BPy_Texture_getseters[] = {
540         {"animFrames",
541          (getter)Texture_getAnimFrames, (setter)Texture_setAnimFrames,
542          "Number of frames of a movie to use",
543          NULL},
544         {"animLength",
545          (getter)Texture_getAnimLength, (setter)Texture_setAnimLength,
546          "Number of frames of a movie to use (0 for all)",
547          NULL},
548         {"animMontage",
549          (getter)Texture_getAnimMontage, (setter)Texture_setAnimMontage,
550          "Montage mode, start frames and durations",
551          NULL},
552         {"animOffset",
553          (getter)Texture_getAnimOffset, (setter)Texture_setAnimOffset,
554          "Offsets the number of the first movie frame to use",
555          NULL},
556         {"animStart",
557          (getter)Texture_getAnimStart, (setter)Texture_setAnimStart,
558          "Starting frame of the movie to use",
559          NULL},
560         {"brightness",
561          (getter)Texture_getBrightness, (setter)Texture_setBrightness,
562          "Changes the brightness of a texture's color",
563          NULL},
564         {"contrast",
565          (getter)Texture_getContrast, (setter)Texture_setContrast,
566          "Changes the contrast of a texture's color",
567          NULL},
568         {"crop",
569          (getter)Texture_getCrop, (setter)Texture_setCrop,
570          "Sets the cropping extents (for image textures)",
571          NULL},
572         {"distAmnt",
573          (getter)Texture_getDistAmnt, (setter)Texture_setDistAmnt,
574          "Amount of distortion (for distorted noise textures)",
575          NULL},
576         {"distMetric",
577          (getter)Texture_getDistMetric, (setter)Texture_setDistMetric,
578          "The distance metric (for Voronoi textures)",
579          NULL},
580         {"exp",
581          (getter)Texture_getExp, (setter)Texture_setExp,
582          "Minkovsky exponent (for Minkovsky Voronoi textures)",
583          NULL},
584         {"extend",
585          (getter)Texture_getIntExtend, (setter)Texture_setIntExtend,
586          "Texture's 'Extend' mode (for image textures)",
587          NULL},
588         {"fieldsPerImage",
589          (getter)Texture_getFieldsPerImage, (setter)Texture_setFieldsPerImage,
590          "Number of fields per rendered frame",
591          NULL},
592         {"filterSize",
593          (getter)Texture_getFilterSize, (setter)Texture_setFilterSize,
594          "The filter size (for image and envmap textures)",
595          NULL},
596         {"flags",
597          (getter)Texture_getFlags, (setter)Texture_setFlags,
598          "Texture's 'Flag' bits",
599          NULL},
600         {"hFracDim",
601          (getter)Texture_getHFracDim, (setter)Texture_setHFracDim,
602          "Highest fractional dimension (for Musgrave textures)",
603          NULL},
604         {"imageFlags",
605          (getter)Texture_getImageFlags, (setter)Texture_setImageFlags,
606          "Texture's 'ImageFlags' bits",
607          NULL},
608         {"image",
609          (getter)Texture_getImage, (setter)Texture_setImage,
610          "Texture's image object",
611          NULL},
612         {"ipo",
613          (getter)Texture_getIpo, (setter)Texture_setIpo,
614          "Texture Ipo data",
615          NULL},
616         {"iScale",
617          (getter)Texture_getIScale, (setter)Texture_setIScale,
618          "Intensity output scale (for Musgrave and Voronoi textures)",
619          NULL},
620         {"lacunarity",
621          (getter)Texture_getLacunarity, (setter)Texture_setLacunarity,
622          "Gap between succesive frequencies (for Musgrave textures)",
623          NULL},
624         {"name",
625          (getter)Texture_getName, (setter)Texture_setName,
626          "Texture data name",
627          NULL},
628         {"noiseBasis",
629          (getter)Texture_getNoiseBasis, (setter)Texture_setNoiseBasis,
630          "Noise basis type (wood, stucci, marble, clouds, Musgrave, distorted noise)",
631          NULL},
632         {"noiseBasis2",
633          (getter)Texture_getNoiseBasis2, (setter)Texture_setNoiseBasis2,
634          "Additional noise basis type (wood, marble, distorted noise)",
635          (void *)EXPP_TEX_NOISEBASIS2},
636         {"noiseDepth",
637          (getter)Texture_getNoiseDepth, (setter)Texture_setNoiseDepth,
638          "Noise depth (magic, marble, clouds)",
639          NULL},
640         {"noiseSize",
641          (getter)Texture_getNoiseSize, (setter)Texture_setNoiseSize,
642          "Noise size (wood, stucci, marble, clouds, Musgrave, distorted noise, Voronoi)",
643          NULL},
644 /* NOTE for API rewrite: should use dict constants instead of strings */
645         {"noiseType",
646          (getter)Texture_getNoiseType, (setter)Texture_setNoiseType,
647          "Noise type (for wood, stucci, marble, clouds textures)",
648          NULL},
649         {"octs",
650          (getter)Texture_getOcts, (setter)Texture_setOcts,
651          "Number of frequencies (for Musgrave textures)",
652          NULL},
653         {"repeat",
654          (getter)Texture_getRepeat, (setter)Texture_setRepeat,
655          "Repetition multiplier (for image textures)",
656          NULL},
657         {"rgbCol",
658          (getter)Texture_getRGBCol, (setter)Texture_setRGBCol,
659          "RGB color tuple",
660          NULL},
661         {"stype",
662          (getter)Texture_getSType, (setter)Texture_setSType,
663          "Texture's 'SType' mode",
664          NULL},
665         {"turbulence",
666          (getter)Texture_getTurbulence, (setter)Texture_setTurbulence,
667          "Turbulence (for magic, wood, stucci, marble textures)",
668          NULL},
669         {"type",
670          (getter)Texture_getType, (setter)Texture_setType,
671          "Texture's 'Type' mode",
672          NULL},
673         {"users",
674          (getter)Texture_getUsers, (setter)NULL,
675          "Number of texture users",
676          NULL},
677         {"weight1",
678          (getter)Texture_getWeight1, (setter)Texture_setWeight1,
679          "Weight 1 (for Voronoi textures)",
680          NULL},
681         {"weight2",
682          (getter)Texture_getWeight2, (setter)Texture_setWeight2,
683          "Weight 2 (for Voronoi textures)",
684          NULL},
685         {"weight3",
686          (getter)Texture_getWeight3, (setter)Texture_setWeight3,
687          "Weight 3 (for Voronoi textures)",
688          NULL},
689         {"weight4",
690          (getter)Texture_getWeight4, (setter)Texture_setWeight4,
691          "Weight 4 (for Voronoi textures)",
692          NULL},
693         {"sine",
694          (getter)Texture_getNoiseBasis2, (setter)Texture_setNoiseBasis2,
695          "Produce bands using sine wave (marble, wood textures)",
696          (void *)EXPP_TEX_NOISE_SINE},
697         {"saw",
698          (getter)Texture_getNoiseBasis2, (setter)Texture_setNoiseBasis2,
699          "Produce bands using saw wave (marble, wood textures)",
700          (void *)EXPP_TEX_NOISE_SAW},
701         {"tri",
702          (getter)Texture_getNoiseBasis2, (setter)Texture_setNoiseBasis2,
703          "Produce bands using triangle wave (marble, wood textures)",
704          (void *)EXPP_TEX_NOISE_TRI},
705         {"interpol",
706          (getter)Texture_getImageFlags, (setter)Texture_setImageFlags,
707          "Interpolate image's pixels to fit texture mapping enabled ('ImageFlags')",
708          (void *)TEX_INTERPOL},
709         {"useAlpha",
710          (getter)Texture_getImageFlags, (setter)Texture_setImageFlags,
711          "Use of image's alpha channel enabled ('ImageFlags')",
712          (void *)TEX_USEALPHA},
713         {"calcAlpha",
714          (getter)Texture_getImageFlags, (setter)Texture_setImageFlags,
715          "Calculation of image's alpha channel enabled ('ImageFlags')",
716          (void *)TEX_CALCALPHA},
717         {"mipmap",
718          (getter)Texture_getImageFlags, (setter)Texture_setImageFlags,
719          "Mipmaps enabled ('ImageFlags')",
720          (void *)TEX_MIPMAP},
721         {"fields",
722          (getter)Texture_getImageFlags, (setter)Texture_setImageFlags,
723          "Use of image's fields enabled ('ImageFlags')",
724          (void *)TEX_FIELDS},
725         {"rot90",
726          (getter)Texture_getImageFlags, (setter)Texture_setImageFlags,
727          "X/Y flip for rendering enabled ('ImageFlags')",
728          (void *)TEX_IMAROT},
729         {"cyclic",
730          (getter)Texture_getImageFlags, (setter)Texture_setImageFlags,
731          "Looping of animated frames enabled ('ImageFlags')",
732          (void *)TEX_ANIMCYCLIC},
733         {"movie",
734          (getter)Texture_getImageFlags, (setter)Texture_setImageFlags,
735          "Movie frames as images enabled ('ImageFlags')",
736          (void *)TEX_ANIM5},
737         {"anti",
738          (getter)Texture_getImageFlags, (setter)Texture_setImageFlags,
739          "Image anti-aliasing enabled ('ImageFlags')",
740          (void *)TEX_ANTIALI},
741         {"stField",
742          (getter)Texture_getImageFlags, (setter)Texture_setImageFlags,
743          "Standard field deinterlacing enabled ('ImageFlags')",
744          (void *)TEX_STD_FIELD},
745         {"normalMap",
746          (getter)Texture_getImageFlags, (setter)Texture_setImageFlags,
747          "Use of image RGB values for normal mapping enabled ('ImageFlags')",
748          (void *)TEX_NORMALMAP},
749         {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
750 };
751
752 /*****************************************************************************/
753 /* Python Texture_Type callback function prototypes:                         */
754 /*****************************************************************************/
755 static void Texture_dealloc( BPy_Texture * self );
756 static int Texture_compare( BPy_Texture * a, BPy_Texture * b );
757 static PyObject *Texture_repr( BPy_Texture * self );
758
759 /*****************************************************************************/
760 /* Python Texture_Type structure definition:                                 */
761 /*****************************************************************************/
762 PyTypeObject Texture_Type = {
763         PyObject_HEAD_INIT( NULL )  /* required py macro */
764         0,                          /* ob_size */
765         /*  For printing, in format "<module>.<name>" */
766         "Blender Texture",          /* char *tp_name; */
767         sizeof( BPy_Texture ),      /* int tp_basicsize; */
768         0,                          /* tp_itemsize;  For allocation */
769
770         /* Methods to implement standard operations */
771
772         ( destructor ) Texture_dealloc,/* destructor tp_dealloc; */
773         NULL,                       /* printfunc tp_print; */
774         NULL,                       /* getattrfunc tp_getattr; */
775         NULL,                       /* setattrfunc tp_setattr; */
776         ( cmpfunc ) Texture_compare, /* cmpfunc tp_compare; */
777         ( reprfunc ) Texture_repr,  /* reprfunc tp_repr; */
778
779         /* Method suites for standard classes */
780
781         NULL,                       /* PyNumberMethods *tp_as_number; */
782         NULL,                       /* PySequenceMethods *tp_as_sequence; */
783         NULL,                       /* PyMappingMethods *tp_as_mapping; */
784
785         /* More standard operations (here for binary compatibility) */
786
787         NULL,                       /* hashfunc tp_hash; */
788         NULL,                       /* ternaryfunc tp_call; */
789         NULL,                       /* reprfunc tp_str; */
790         NULL,                       /* getattrofunc tp_getattro; */
791         NULL,                       /* setattrofunc tp_setattro; */
792
793         /* Functions to access object as input/output buffer */
794         NULL,                       /* PyBufferProcs *tp_as_buffer; */
795
796   /*** Flags to define presence of optional/expanded features ***/
797         Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
798
799         NULL,                       /*  char *tp_doc;  Documentation string */
800   /*** Assigned meaning in release 2.0 ***/
801         /* call function for all accessible objects */
802         NULL,                       /* traverseproc tp_traverse; */
803
804         /* delete references to contained objects */
805         NULL,                       /* inquiry tp_clear; */
806
807   /***  Assigned meaning in release 2.1 ***/
808   /*** rich comparisons ***/
809         NULL,                       /* richcmpfunc tp_richcompare; */
810
811   /***  weak reference enabler ***/
812         0,                          /* long tp_weaklistoffset; */
813
814   /*** Added in release 2.2 ***/
815         /*   Iterators */
816         NULL,                       /* getiterfunc tp_iter; */
817         NULL,                       /* iternextfunc tp_iternext; */
818
819   /*** Attribute descriptor and subclassing stuff ***/
820         BPy_Texture_methods,        /* struct PyMethodDef *tp_methods; */
821         NULL,                       /* struct PyMemberDef *tp_members; */
822         BPy_Texture_getseters,      /* struct PyGetSetDef *tp_getset; */
823         NULL,                       /* struct _typeobject *tp_base; */
824         NULL,                       /* PyObject *tp_dict; */
825         NULL,                       /* descrgetfunc tp_descr_get; */
826         NULL,                       /* descrsetfunc tp_descr_set; */
827         0,                          /* long tp_dictoffset; */
828         NULL,                       /* initproc tp_init; */
829         NULL,                       /* allocfunc tp_alloc; */
830         NULL,                       /* newfunc tp_new; */
831         /*  Low-level free-memory routine */
832         NULL,                       /* freefunc tp_free;  */
833         /* For PyObject_IS_GC */
834         NULL,                       /* inquiry tp_is_gc;  */
835         NULL,                       /* PyObject *tp_bases; */
836         /* method resolution order */
837         NULL,                       /* PyObject *tp_mro;  */
838         NULL,                       /* PyObject *tp_cache; */
839         NULL,                       /* PyObject *tp_subclasses; */
840         NULL,                       /* PyObject *tp_weaklist; */
841         NULL
842 };
843
844 static PyObject *M_Texture_New( PyObject * self, PyObject * args,
845                                 PyObject * kwords )
846 {
847         char *name_str = "Tex";
848         static char *kwlist[] = { "name_str", NULL };
849         PyObject *pytex;        /* for Texture object wrapper in Python */
850         Tex *bltex;             /* for actual Tex we create in Blender */
851
852         /* Parse the arguments passed in by the Python interpreter */
853         if( !PyArg_ParseTupleAndKeywords
854             ( args, kwords, "|s", kwlist, &name_str ) )
855                 return EXPP_ReturnPyObjError( PyExc_AttributeError,
856                                               "expected zero, one or two strings as arguments" );
857
858         bltex = add_texture( name_str );  /* first create the texture in Blender */
859
860         if( bltex )             /* now create the wrapper obj in Python */
861                 pytex = Texture_CreatePyObject( bltex );
862         else
863                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
864                                               "couldn't create Texture in Blender" );
865
866         /* let's return user count to zero, because add_texture() incref'd it */
867         bltex->id.us = 0;
868
869         if( pytex == NULL )
870                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
871                                               "couldn't create Tex PyObject" );
872
873         return pytex;
874 }
875
876 static PyObject *M_Texture_Get( PyObject * self, PyObject * args )
877 {
878         char *name = NULL;
879         Tex *tex_iter;
880
881         if( !PyArg_ParseTuple( args, "|s", &name ) )
882                 return EXPP_ReturnPyObjError( PyExc_TypeError,
883                                               "expected string argument (or nothing)" );
884
885         tex_iter = G.main->tex.first;
886
887         if( name ) {            /* (name) - Search for texture by name */
888
889                 PyObject *wanted_tex = NULL;
890
891                 while( tex_iter ) {
892                         if( STREQ( name, tex_iter->id.name + 2 ) ) {
893                                 wanted_tex =
894                                         Texture_CreatePyObject( tex_iter );
895                                 break;
896                         }
897
898                         tex_iter = tex_iter->id.next;
899                 }
900
901                 if( !wanted_tex ) {     /* Requested texture doesn't exist */
902                         char error_msg[64];
903                         PyOS_snprintf( error_msg, sizeof( error_msg ),
904                                        "Texture \"%s\" not found", name );
905                         return EXPP_ReturnPyObjError( PyExc_NameError,
906                                                       error_msg );
907                 }
908
909                 return wanted_tex;
910         }
911
912         else {                  /* () - return a list of wrappers for all textures in the scene */
913                 int index = 0;
914                 PyObject *tex_pylist, *pyobj;
915
916                 tex_pylist = PyList_New( BLI_countlist( &( G.main->tex ) ) );
917                 if( !tex_pylist )
918                         return EXPP_ReturnPyObjError( PyExc_MemoryError,
919                                                       "couldn't create PyList" );
920
921                 while( tex_iter ) {
922                         pyobj = Texture_CreatePyObject( tex_iter );
923                         if( !pyobj )
924                                 return EXPP_ReturnPyObjError
925                                         ( PyExc_MemoryError,
926                                           "couldn't create Texture PyObject" );
927
928                         PyList_SET_ITEM( tex_pylist, index, pyobj );
929
930                         tex_iter = tex_iter->id.next;
931                         index++;
932                 }
933
934                 return tex_pylist;
935         }
936 }
937
938 static int Texture_compare( BPy_Texture * a, BPy_Texture * b )
939 {
940         return ( a->texture == b->texture ) ? 0 : -1;
941 }
942
943 static PyObject *Texture_repr( BPy_Texture * self )
944 {
945         return PyString_FromFormat( "[Texture \"%s\"]",
946                                     self->texture->id.name + 2 );
947 }
948
949 static void Texture_dealloc( BPy_Texture * self )
950 {
951         PyObject_DEL( self );
952 }
953
954 static PyObject *M_Texture_TypesDict( void )
955 {
956         PyObject *Types = PyConstant_New(  );
957         if( Types ) {
958                 BPy_constant *d = ( BPy_constant * ) Types;
959                 PyConstant_Insert(d, "NONE", PyInt_FromLong(EXPP_TEX_TYPE_NONE));
960                 PyConstant_Insert(d, "CLOUDS", PyInt_FromLong(TEX_CLOUDS));
961                 PyConstant_Insert(d, "WOOD", PyInt_FromLong(TEX_WOOD));
962                 PyConstant_Insert(d, "MARBLE", PyInt_FromLong(TEX_MARBLE));
963                 PyConstant_Insert(d, "MAGIC", PyInt_FromLong(TEX_MAGIC));
964                 PyConstant_Insert(d, "BLEND", PyInt_FromLong(TEX_BLEND));
965                 PyConstant_Insert(d, "STUCCI", PyInt_FromLong(TEX_STUCCI));
966                 PyConstant_Insert(d, "NOISE", PyInt_FromLong(TEX_NOISE));
967                 PyConstant_Insert(d, "IMAGE", PyInt_FromLong(TEX_IMAGE));
968                 PyConstant_Insert(d, "PLUGIN", PyInt_FromLong(TEX_PLUGIN));
969                 PyConstant_Insert(d, "ENVMAP", PyInt_FromLong(TEX_ENVMAP));
970                 PyConstant_Insert(d, "MUSGRAVE", PyInt_FromLong(TEX_MUSGRAVE));
971                 PyConstant_Insert(d, "VORONOI", PyInt_FromLong(TEX_VORONOI));
972                 PyConstant_Insert(d, "DISTNOISE", PyInt_FromLong(TEX_DISTNOISE)); 
973         }
974         return Types;
975 }
976
977 static PyObject *M_Texture_STypesDict( void )
978 {
979         PyObject *STypes = PyConstant_New(  );
980         if( STypes ) {
981                 BPy_constant *d = ( BPy_constant * ) STypes;
982
983                 PyConstant_Insert(d, "CLD_DEFAULT",
984                                         PyInt_FromLong(EXPP_TEX_STYPE_CLD_DEFAULT));
985                 PyConstant_Insert(d, "CLD_COLOR",
986                                         PyInt_FromLong(EXPP_TEX_STYPE_CLD_COLOR));
987                 PyConstant_Insert(d, "WOD_BANDS",
988                                         PyInt_FromLong(EXPP_TEX_STYPE_WOD_BANDS));
989                 PyConstant_Insert(d, "WOD_RINGS",
990                                         PyInt_FromLong(EXPP_TEX_STYPE_WOD_RINGS));
991                 PyConstant_Insert(d, "WOD_BANDNOISE",
992                                         PyInt_FromLong(EXPP_TEX_STYPE_WOD_BANDNOISE));
993                 PyConstant_Insert(d, "WOD_RINGNOISE",
994                                         PyInt_FromLong(EXPP_TEX_STYPE_WOD_RINGNOISE));
995                 PyConstant_Insert(d, "MAG_DEFAULT",
996                                         PyInt_FromLong(EXPP_TEX_STYPE_MAG_DEFAULT));
997                 PyConstant_Insert(d, "MBL_SOFT",
998                                         PyInt_FromLong(EXPP_TEX_STYPE_MBL_SOFT));
999                 PyConstant_Insert(d, "MBL_SHARP",
1000                                         PyInt_FromLong(EXPP_TEX_STYPE_MBL_SHARP));
1001                 PyConstant_Insert(d, "MBL_SHARPER",
1002                                         PyInt_FromLong(EXPP_TEX_STYPE_MBL_SHARPER));
1003                 PyConstant_Insert(d, "BLN_LIN",
1004                                         PyInt_FromLong(EXPP_TEX_STYPE_BLN_LIN));
1005                 PyConstant_Insert(d, "BLN_QUAD",
1006                                         PyInt_FromLong(EXPP_TEX_STYPE_BLN_QUAD));
1007                 PyConstant_Insert(d, "BLN_EASE",
1008                                         PyInt_FromLong(EXPP_TEX_STYPE_BLN_EASE));
1009                 PyConstant_Insert(d, "BLN_DIAG",
1010                                         PyInt_FromLong(EXPP_TEX_STYPE_BLN_DIAG));
1011                 PyConstant_Insert(d, "BLN_SPHERE",
1012                                         PyInt_FromLong(EXPP_TEX_STYPE_BLN_SPHERE));
1013                 PyConstant_Insert(d, "BLN_HALO",
1014                                         PyInt_FromLong(EXPP_TEX_STYPE_BLN_HALO));
1015                 PyConstant_Insert(d, "STC_PLASTIC",
1016                                         PyInt_FromLong(EXPP_TEX_STYPE_STC_PLASTIC));
1017                 PyConstant_Insert(d, "STC_WALLIN",
1018                                         PyInt_FromLong(EXPP_TEX_STYPE_STC_WALLIN));
1019                 PyConstant_Insert(d, "STC_WALLOUT",
1020                                         PyInt_FromLong(EXPP_TEX_STYPE_STC_WALLOUT));
1021                 PyConstant_Insert(d, "NSE_DEFAULT",
1022                                         PyInt_FromLong(EXPP_TEX_STYPE_NSE_DEFAULT));
1023                 PyConstant_Insert(d, "IMG_DEFAULT",
1024                                         PyInt_FromLong(EXPP_TEX_STYPE_IMG_DEFAULT));
1025                 PyConstant_Insert(d, "PLG_DEFAULT",
1026                                         PyInt_FromLong(EXPP_TEX_STYPE_PLG_DEFAULT));
1027                 PyConstant_Insert(d, "ENV_STATIC",
1028                                         PyInt_FromLong(EXPP_TEX_STYPE_ENV_STATIC));
1029                 PyConstant_Insert(d, "ENV_ANIM",
1030                                         PyInt_FromLong(EXPP_TEX_STYPE_ENV_ANIM));
1031                 PyConstant_Insert(d, "ENV_LOAD",
1032                                         PyInt_FromLong(EXPP_TEX_STYPE_ENV_LOAD));
1033                 PyConstant_Insert(d, "MUS_MFRACTAL",
1034                                         PyInt_FromLong(EXPP_TEX_STYPE_MUS_MFRACTAL));
1035                 PyConstant_Insert(d, "MUS_RIDGEDMF",
1036                                         PyInt_FromLong(EXPP_TEX_STYPE_MUS_RIDGEDMF));
1037                 PyConstant_Insert(d, "MUS_HYBRIDMF",
1038                                         PyInt_FromLong(EXPP_TEX_STYPE_MUS_HYBRIDMF));
1039                 PyConstant_Insert(d, "MUS_FBM",
1040                                         PyInt_FromLong(EXPP_TEX_STYPE_MUS_FBM));
1041                 PyConstant_Insert(d, "MUS_HTERRAIN",
1042                                         PyInt_FromLong(EXPP_TEX_STYPE_MUS_HTERRAIN));
1043                 PyConstant_Insert(d, "DN_BLENDER",
1044                                         PyInt_FromLong(TEX_BLENDER));
1045                 PyConstant_Insert(d, "DN_PERLIN",
1046                                         PyInt_FromLong(TEX_STDPERLIN));
1047                 PyConstant_Insert(d, "DN_IMPROVEPERLIN",
1048                                         PyInt_FromLong(TEX_NEWPERLIN));
1049                 PyConstant_Insert(d, "DN_VORONOIF1",
1050                                         PyInt_FromLong(TEX_VORONOI_F1));
1051                 PyConstant_Insert(d, "DN_VORONOIF2",
1052                                         PyInt_FromLong(TEX_VORONOI_F2));
1053                 PyConstant_Insert(d, "DN_VORONOIF3",
1054                                         PyInt_FromLong(TEX_VORONOI_F3));
1055                 PyConstant_Insert(d, "DN_VORONOIF4",
1056                                         PyInt_FromLong(TEX_VORONOI_F4));
1057                 PyConstant_Insert(d, "DN_VORONOIF2F1",
1058                                         PyInt_FromLong(TEX_VORONOI_F2F1));
1059                 PyConstant_Insert(d, "DN_VORONOICRACKLE",
1060                                         PyInt_FromLong(TEX_VORONOI_CRACKLE));
1061                 PyConstant_Insert(d, "DN_CELLNOISE",
1062                                         PyInt_FromLong(TEX_CELLNOISE));
1063                 PyConstant_Insert(d, "VN_INT",
1064                                         PyInt_FromLong(EXPP_TEX_STYPE_VN_INT));
1065                 PyConstant_Insert(d, "VN_COL1",
1066                                         PyInt_FromLong(EXPP_TEX_STYPE_VN_COL1));
1067                 PyConstant_Insert(d, "VN_COL2",
1068                                         PyInt_FromLong(EXPP_TEX_STYPE_VN_COL2));
1069                 PyConstant_Insert(d, "VN_COL3",
1070                                         PyInt_FromLong(EXPP_TEX_STYPE_VN_COL3));
1071                 PyConstant_Insert(d, "VN_TEX_DISTANCE",
1072                                         PyInt_FromLong(TEX_DISTANCE));
1073                 PyConstant_Insert(d, "VN_TEX_DISTANCE_SQUARED",
1074                                         PyInt_FromLong(TEX_DISTANCE_SQUARED));
1075                 PyConstant_Insert(d, "VN_TEX_MANHATTAN",
1076                                         PyInt_FromLong(TEX_MANHATTAN));
1077                 PyConstant_Insert(d, "VN_TEX_CHEBYCHEV",
1078                                         PyInt_FromLong(TEX_CHEBYCHEV));
1079                 PyConstant_Insert(d, "VN_TEX_MINKOVSKY_HALF",
1080                                         PyInt_FromLong(TEX_MINKOVSKY_HALF));
1081                 PyConstant_Insert(d, "VN_TEX_MINKOVSKY_FOUR",
1082                                         PyInt_FromLong(TEX_MINKOVSKY_FOUR));
1083                 PyConstant_Insert(d, "VN_TEX_MINKOVSKY",
1084                                         PyInt_FromLong(TEX_MINKOVSKY));
1085
1086         }
1087         return STypes;
1088 }
1089
1090 static PyObject *M_Texture_TexCoDict( void )
1091 {
1092         PyObject *TexCo = PyConstant_New(  );
1093         if( TexCo ) {
1094                 BPy_constant *d = ( BPy_constant * ) TexCo;
1095                 PyConstant_Insert(d, "ORCO", PyInt_FromLong(TEXCO_ORCO));
1096                 PyConstant_Insert(d, "REFL", PyInt_FromLong(TEXCO_REFL));
1097                 PyConstant_Insert(d, "NOR", PyInt_FromLong(TEXCO_NORM));
1098                 PyConstant_Insert(d, "GLOB", PyInt_FromLong(TEXCO_GLOB));
1099                 PyConstant_Insert(d, "UV", PyInt_FromLong(TEXCO_UV));
1100                 PyConstant_Insert(d, "OBJECT", PyInt_FromLong(TEXCO_OBJECT));
1101                 PyConstant_Insert(d, "WIN", PyInt_FromLong(TEXCO_WINDOW));
1102                 PyConstant_Insert(d, "VIEW", PyInt_FromLong(TEXCO_VIEW));
1103                 PyConstant_Insert(d, "STICK", PyInt_FromLong(TEXCO_STICKY));
1104         }
1105         return TexCo;
1106 }
1107
1108 static PyObject *M_Texture_MapToDict( void )
1109 {
1110         PyObject *MapTo = PyConstant_New(  );
1111         if( MapTo ) {
1112                 BPy_constant *d = ( BPy_constant * ) MapTo;
1113                 PyConstant_Insert(d, "COL", PyInt_FromLong(MAP_COL));
1114                 PyConstant_Insert(d, "NOR", PyInt_FromLong(MAP_NORM));
1115                 PyConstant_Insert(d, "CSP", PyInt_FromLong(MAP_COLSPEC));
1116                 PyConstant_Insert(d, "CMIR", PyInt_FromLong(MAP_COLMIR));
1117                 PyConstant_Insert(d, "REF", PyInt_FromLong(MAP_REF));
1118                 PyConstant_Insert(d, "SPEC", PyInt_FromLong(MAP_SPEC));
1119                 PyConstant_Insert(d, "HARD", PyInt_FromLong(MAP_HAR));
1120                 PyConstant_Insert(d, "ALPHA", PyInt_FromLong(MAP_ALPHA));
1121                 PyConstant_Insert(d, "EMIT", PyInt_FromLong(MAP_EMIT));
1122                 PyConstant_Insert(d, "RAYMIR", PyInt_FromLong(MAP_RAYMIRR));
1123                 PyConstant_Insert(d, "AMB", PyInt_FromLong(MAP_AMB));
1124                 PyConstant_Insert(d, "TRANSLU", PyInt_FromLong(MAP_TRANSLU));
1125                 PyConstant_Insert(d, "DISP", PyInt_FromLong(MAP_DISPLACE));
1126         }
1127         return MapTo;
1128 }
1129
1130 static PyObject *M_Texture_FlagsDict( void )
1131 {
1132         PyObject *Flags = PyConstant_New(  );
1133         if( Flags ) {
1134                 BPy_constant *d = ( BPy_constant * ) Flags;
1135                 PyConstant_Insert(d, "COLORBAND", PyInt_FromLong(TEX_COLORBAND));
1136                 PyConstant_Insert(d, "FLIPBLEND", PyInt_FromLong(TEX_FLIPBLEND));
1137                 PyConstant_Insert(d, "NEGALPHA", PyInt_FromLong(TEX_NEGALPHA));
1138                 PyConstant_Insert(d, "CHECKER_ODD", PyInt_FromLong(TEX_CHECKER_ODD)); 
1139                 PyConstant_Insert(d, "CHECKER_EVEN", PyInt_FromLong(TEX_CHECKER_EVEN));
1140         }
1141         return Flags;
1142 }
1143
1144 static PyObject *M_Texture_ExtendModesDict( void )
1145 {
1146         PyObject *ExtendModes = PyConstant_New(  );
1147         if( ExtendModes ) {
1148                 BPy_constant *d = ( BPy_constant * ) ExtendModes;
1149                 PyConstant_Insert(d, "EXTEND", PyInt_FromLong(TEX_EXTEND));
1150                 PyConstant_Insert(d, "CLIP", PyInt_FromLong(TEX_CLIP));
1151                 PyConstant_Insert(d, "CLIPCUBE", PyInt_FromLong(TEX_CLIPCUBE));
1152                 PyConstant_Insert(d, "REPEAT", PyInt_FromLong(TEX_REPEAT));
1153         }
1154         return ExtendModes;
1155 }
1156
1157 static PyObject *M_Texture_ImageFlagsDict( void )
1158 {
1159         PyObject *ImageFlags = PyConstant_New(  );
1160         if( ImageFlags ) {
1161                 BPy_constant *d = ( BPy_constant * ) ImageFlags;
1162                 PyConstant_Insert(d, "INTERPOL", PyInt_FromLong(TEX_INTERPOL));
1163                 PyConstant_Insert(d, "USEALPHA", PyInt_FromLong(TEX_USEALPHA));
1164                 PyConstant_Insert(d, "MIPMAP", PyInt_FromLong(TEX_MIPMAP));
1165                 PyConstant_Insert(d, "FIELDS", PyInt_FromLong(TEX_FIELDS));
1166                 PyConstant_Insert(d, "ROT90", PyInt_FromLong(TEX_IMAROT));
1167                 PyConstant_Insert(d, "CALCALPHA", PyInt_FromLong(TEX_CALCALPHA));
1168                 PyConstant_Insert(d, "STFIELD", PyInt_FromLong(TEX_STD_FIELD));
1169                 PyConstant_Insert(d, "MOVIE", PyInt_FromLong(TEX_ANIM5));
1170                 PyConstant_Insert(d, "CYCLIC", PyInt_FromLong(TEX_ANIMCYCLIC));
1171                 PyConstant_Insert(d, "NORMALMAP", PyInt_FromLong(TEX_NORMALMAP));
1172         }
1173         return ImageFlags;
1174 }
1175
1176 static PyObject *M_Texture_NoiseDict( void )
1177 {
1178         PyObject *Noise = PyConstant_New(  );
1179         if( Noise ) {
1180                 BPy_constant *d = ( BPy_constant * ) Noise;
1181                 PyConstant_Insert(d, "SINE", PyInt_FromLong(EXPP_TEX_NOISE_SINE));
1182                 PyConstant_Insert(d, "SAW", PyInt_FromLong(EXPP_TEX_NOISE_SAW));
1183                 PyConstant_Insert(d, "TRI", PyInt_FromLong(EXPP_TEX_NOISE_TRI));
1184                 PyConstant_Insert(d, "BLENDER", PyInt_FromLong(TEX_BLENDER));
1185                 PyConstant_Insert(d, "PERLIN", PyInt_FromLong(TEX_STDPERLIN));
1186                 PyConstant_Insert(d, "IMPROVEPERLIN", PyInt_FromLong(TEX_NEWPERLIN));
1187                 PyConstant_Insert(d, "VORONOIF1", PyInt_FromLong(TEX_VORONOI_F1));
1188                 PyConstant_Insert(d, "VORONOIF2", PyInt_FromLong(TEX_VORONOI_F2));
1189                 PyConstant_Insert(d, "VORONOIF3", PyInt_FromLong(TEX_VORONOI_F3));
1190                 PyConstant_Insert(d, "VORONOIF4", PyInt_FromLong(TEX_VORONOI_F4));
1191                 PyConstant_Insert(d, "VORONOIF2F1", PyInt_FromLong(TEX_VORONOI_F2F1));
1192                 PyConstant_Insert(d, "VORONOICRACKLE",
1193                                         PyInt_FromLong(TEX_VORONOI_CRACKLE));
1194                 PyConstant_Insert(d, "CELLNOISE", PyInt_FromLong(TEX_CELLNOISE));
1195         }
1196         return Noise;
1197 }
1198
1199 PyObject *Texture_Init( void )
1200 {
1201         PyObject *submodule;
1202         PyObject *dict;
1203
1204         /* constants */
1205         PyObject *Types = M_Texture_TypesDict(  );
1206         PyObject *STypes = M_Texture_STypesDict(  );
1207         PyObject *TexCo = M_Texture_TexCoDict(  );
1208         PyObject *MapTo = M_Texture_MapToDict(  );
1209         PyObject *Flags = M_Texture_FlagsDict(  );
1210         PyObject *ExtendModes = M_Texture_ExtendModesDict(  );
1211         PyObject *ImageFlags = M_Texture_ImageFlagsDict(  );
1212         PyObject *Noise = M_Texture_NoiseDict(  );
1213
1214         if( PyType_Ready( &Texture_Type ) < 0)
1215                 return NULL;
1216
1217         submodule = Py_InitModule3( "Blender.Texture",
1218                                     M_Texture_methods, M_Texture_doc );
1219
1220         if( Types )
1221                 PyModule_AddObject( submodule, "Types", Types );
1222         if( STypes )
1223                 PyModule_AddObject( submodule, "STypes", STypes );
1224         if( TexCo )
1225                 PyModule_AddObject( submodule, "TexCo", TexCo );
1226         if( MapTo )
1227                 PyModule_AddObject( submodule, "MapTo", MapTo );
1228         if( Flags )
1229                 PyModule_AddObject( submodule, "Flags", Flags );
1230         if( ExtendModes )
1231                 PyModule_AddObject( submodule, "ExtendModes", ExtendModes );
1232         if( ImageFlags )
1233                 PyModule_AddObject( submodule, "ImageFlags", ImageFlags );
1234         if( Noise )
1235                 PyModule_AddObject( submodule, "Noise", Noise );
1236
1237         /* Add the MTex submodule to this module */
1238         dict = PyModule_GetDict( submodule );
1239         PyDict_SetItemString( dict, "MTex", MTex_Init(  ) );
1240
1241         return submodule;
1242 }
1243
1244 PyObject *Texture_CreatePyObject( Tex * tex )
1245 {
1246         BPy_Texture *pytex;
1247
1248         pytex = ( BPy_Texture * ) PyObject_NEW( BPy_Texture, &Texture_Type );
1249         if( !pytex )
1250                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
1251                                               "couldn't create BPy_Texture PyObject" );
1252
1253         pytex->texture = tex;
1254         return ( PyObject * ) pytex;
1255 }
1256
1257 Tex *Texture_FromPyObject( PyObject * pyobj )
1258 {
1259         return ( ( BPy_Texture * ) pyobj )->texture;
1260 }
1261
1262 int Texture_CheckPyObject( PyObject * pyobj )
1263 {
1264         return ( pyobj->ob_type == &Texture_Type );
1265 }
1266
1267 /*****************************************************************************/
1268 /* Python BPy_Texture methods:                                               */
1269 /*****************************************************************************/
1270
1271 static PyObject *Texture_getExtend( BPy_Texture * self )
1272 {
1273         PyObject *attr = NULL;
1274         const char *extend = NULL;
1275
1276         if( EXPP_map_getStrVal
1277             ( tex_extend_map, self->texture->extend, &extend ) )
1278                 attr = PyString_FromString( extend );
1279
1280         if( !attr )
1281                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1282                                               "invalid internal extend mode" );
1283
1284         return attr;
1285 }
1286
1287 static PyObject *Texture_getImage( BPy_Texture * self )
1288 {
1289         /* we need this to be an IMAGE texture, and we must have an image */
1290         if( ( self->texture->type != TEX_IMAGE ) || !self->texture->ima ) {
1291                 Py_INCREF( Py_None );
1292                 return Py_None;
1293         }
1294
1295         return Image_CreatePyObject( self->texture->ima );
1296 }
1297
1298
1299 static PyObject *Texture_getName( BPy_Texture * self )
1300 {
1301         PyObject *attr = PyString_FromString( self->texture->id.name + 2 );
1302         if( !attr )
1303                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1304                                               "couldn't get Texture.name attribute" );
1305
1306         return attr;
1307 }
1308
1309 static PyObject *Texture_oldgetSType( BPy_Texture * self )
1310 {
1311         PyObject *attr = NULL;
1312         const char *stype = NULL;
1313         int n_stype;
1314
1315         if( self->texture->type == TEX_VORONOI )
1316                 n_stype = self->texture->vn_coltype;
1317 #if 0
1318         else if( self->texture->type == TEX_MUSGRAVE )
1319                 n_stype = self->texture->noisebasis;
1320 #endif
1321         else if( self->texture->type == TEX_ENVMAP )
1322                 n_stype = self->texture->env->stype;
1323         else 
1324                 n_stype = self->texture->stype;
1325
1326         if( EXPP_map_getStrVal( tex_stype_map[self->texture->type],
1327                                 n_stype, &stype ) )
1328                 attr = PyString_FromString( stype );
1329
1330         if( !attr )
1331                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1332                                               "invalid texture stype internally" );
1333
1334         return attr;
1335 }
1336
1337 static PyObject *Texture_oldgetType( BPy_Texture * self )
1338 {
1339         PyObject *attr = NULL;
1340         const char *type = NULL;
1341
1342         if( EXPP_map_getStrVal( tex_type_map, self->texture->type, &type ) )
1343                 attr = PyString_FromString( type );
1344
1345         if( !attr )
1346                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1347                                               "invalid texture type internally" );
1348
1349         return attr;
1350 }
1351
1352 static int Texture_setAnimFrames( BPy_Texture * self, PyObject * value )
1353 {
1354         return EXPP_setIValueClamped ( value, &self->texture->frames,
1355                                                                 EXPP_TEX_ANIMFRAME_MIN,
1356                                                                 EXPP_TEX_ANIMFRAME_MAX, 'h' );
1357 }
1358
1359 static int Texture_setAnimLength( BPy_Texture * self, PyObject * value )
1360 {
1361         return EXPP_setIValueClamped ( value, &self->texture->len,
1362                                                                 EXPP_TEX_ANIMLEN_MIN,
1363                                                                 EXPP_TEX_ANIMLEN_MAX, 'h' );
1364 }
1365
1366 static int Texture_setAnimMontage( BPy_Texture * self, PyObject * value )
1367 {
1368         int fradur[4][2];
1369         int i;
1370
1371         if( !PyArg_ParseTuple( value, "(ii)(ii)(ii)(ii)",
1372                                &fradur[0][0], &fradur[0][1],
1373                                &fradur[1][0], &fradur[1][1],
1374                                &fradur[2][0], &fradur[2][1],
1375                                &fradur[3][0], &fradur[3][1] ) )
1376                 return EXPP_ReturnIntError( PyExc_TypeError,
1377                                               "expected a tuple of tuples" );
1378
1379         for( i = 0; i < 4; ++i ) {
1380                 self->texture->fradur[i][0] = 
1381                         EXPP_ClampInt ( fradur[i][0], EXPP_TEX_ANIMMONSTART_MIN,
1382                                                                 EXPP_TEX_ANIMMONSTART_MAX );
1383                 self->texture->fradur[i][1] = 
1384                         EXPP_ClampInt ( fradur[i][1], EXPP_TEX_ANIMMONDUR_MIN,
1385                                                                 EXPP_TEX_ANIMMONDUR_MAX );
1386         }
1387
1388         return 0;
1389 }
1390
1391 static int Texture_setAnimOffset( BPy_Texture * self, PyObject * value )
1392 {
1393         return EXPP_setIValueClamped ( value, &self->texture->offset,
1394                                                                 EXPP_TEX_ANIMOFFSET_MIN,
1395                                                                 EXPP_TEX_ANIMOFFSET_MAX, 'h' );
1396 }
1397
1398 static int Texture_setAnimStart( BPy_Texture * self, PyObject * value )
1399 {
1400         return EXPP_setIValueClamped ( value, &self->texture->sfra,
1401                                                                 EXPP_TEX_ANIMSTART_MIN,
1402                                                                 EXPP_TEX_ANIMSTART_MAX, 'h' );
1403 }
1404
1405 static int Texture_setBrightness( BPy_Texture * self, PyObject * value )
1406 {
1407         return EXPP_setFloatClamped ( value, &self->texture->bright,
1408                                                                 EXPP_TEX_BRIGHTNESS_MIN,
1409                                                                 EXPP_TEX_BRIGHTNESS_MAX );
1410 }
1411
1412 static int Texture_setContrast( BPy_Texture * self, PyObject * value )
1413 {
1414         return EXPP_setFloatClamped ( value, &self->texture->contrast,
1415                                                                 EXPP_TEX_CONTRAST_MIN,
1416                                                                 EXPP_TEX_CONTRAST_MAX );
1417 }
1418
1419 static int Texture_setCrop( BPy_Texture * self, PyObject * value )
1420 {
1421         float crop[4];
1422
1423         if( !PyArg_ParseTuple( value, "ffff",
1424                                &crop[0], &crop[1], &crop[2], &crop[3] ) )
1425                 return EXPP_ReturnIntError( PyExc_TypeError,
1426                                               "expected tuple of 4 floats" );
1427
1428         self->texture->cropxmin = EXPP_ClampFloat( crop[0], EXPP_TEX_CROP_MIN,
1429                                                                                                 EXPP_TEX_CROP_MAX );
1430         self->texture->cropymin = EXPP_ClampFloat( crop[1], EXPP_TEX_CROP_MIN,
1431                                                                                                 EXPP_TEX_CROP_MAX );
1432         self->texture->cropxmax = EXPP_ClampFloat( crop[2], EXPP_TEX_CROP_MIN,
1433                                                                                                 EXPP_TEX_CROP_MAX );
1434         self->texture->cropymax = EXPP_ClampFloat( crop[3], EXPP_TEX_CROP_MIN,
1435                                                                                                 EXPP_TEX_CROP_MAX );
1436
1437         return 0;
1438 }
1439
1440 static int Texture_setIntExtend( BPy_Texture * self, PyObject * value )
1441 {
1442         return EXPP_setIValueRange ( value, &self->texture->extend,
1443                                                                 EXPP_TEX_EXTEND_MIN,
1444                                                                 EXPP_TEX_EXTEND_MAX, 'h' );
1445 }
1446
1447 static int Texture_setFieldsPerImage( BPy_Texture * self,
1448                                             PyObject * value )
1449 {
1450         return EXPP_setIValueClamped ( value, &self->texture->fie_ima,
1451                                                                 EXPP_TEX_FIEIMA_MIN,
1452                                                                 EXPP_TEX_FIEIMA_MAX, 'h' );
1453
1454 }
1455
1456 static int Texture_setFilterSize( BPy_Texture * self, PyObject * value )
1457 {
1458         return EXPP_setFloatClamped ( value, &self->texture->filtersize,
1459                                                                 EXPP_TEX_FILTERSIZE_MIN,
1460                                                                 EXPP_TEX_FILTERSIZE_MAX );
1461 }
1462
1463 static int Texture_setFlags( BPy_Texture * self, PyObject * value )
1464 {
1465         int param;
1466         int bitmask = TEX_FLIPBLEND
1467 #if 0
1468                                         | TEX_COLORBAND
1469 #endif
1470                                         | TEX_NEGALPHA
1471                                         | TEX_CHECKER_ODD
1472                                         | TEX_CHECKER_EVEN;
1473
1474         if( !PyInt_CheckExact ( value ) ) {
1475                 char errstr[128];
1476                 sprintf ( errstr , "expected int bitmask of 0x%08x", bitmask );
1477                 return EXPP_ReturnIntError( PyExc_TypeError, errstr );
1478         }
1479         param = PyInt_AS_LONG ( value );
1480
1481         if ( ( param & bitmask ) != param )
1482                 return EXPP_ReturnIntError( PyExc_ValueError,
1483                                                 "invalid bit(s) set in mask" );
1484
1485         self->texture->flag = param;
1486
1487 #if 0
1488         /* if Colorband enabled, make sure we allocate memory for it */
1489
1490         if ( ( param & TEX_COLORBAND ) && !self->texture->coba )
1491                 self->texture->coba = add_colorband();
1492 #endif
1493
1494         return 0;
1495 }
1496
1497 static int Texture_setImage( BPy_Texture * self, PyObject * value )
1498 {
1499         Image *blimg = NULL;
1500
1501         if( !BPy_Image_Check (value) )
1502                 return EXPP_ReturnIntError( PyExc_TypeError,
1503                                               "expected an Image" );
1504         blimg = Image_FromPyObject( value );
1505
1506         if( self->texture->ima ) {
1507                 self->texture->ima->id.us--;
1508         }
1509
1510         self->texture->ima = blimg;
1511         id_us_plus( &blimg->id );
1512
1513         return 0;
1514 }
1515
1516 static int Texture_setImageFlags( BPy_Texture * self, PyObject * value,
1517                                                                         void *type )
1518 {
1519         short param;
1520
1521         /*
1522          * if type is non-zero, then attribute is "mipmap", "calcAlpha", etc.,
1523          * so set/clear the bit in the bitfield based on the type
1524          */
1525
1526         if( (int)type ) {
1527                 int err;
1528                 param = self->texture->imaflag;
1529                 err = EXPP_setBitfield( value, &param, (int)type, 'h' );
1530                 if( err )
1531                         return err;
1532
1533         /*
1534          * if type is zero, then attribute is "imageFlags", so check
1535          * value for a valid bitmap range.
1536          */
1537
1538         } else {
1539                 int bitmask = TEX_INTERPOL
1540                                         | TEX_USEALPHA
1541                                         | TEX_MIPMAP
1542                                         | TEX_FIELDS
1543                                         | TEX_IMAROT
1544                                         | TEX_CALCALPHA
1545                                         | TEX_ANIMCYCLIC
1546                                         | TEX_ANIM5
1547                                         | TEX_ANTIALI
1548                                         | TEX_STD_FIELD
1549                                         | TEX_NORMALMAP;
1550
1551                 if( !PyInt_CheckExact ( value ) ) {
1552                         char errstr[128];
1553                         sprintf ( errstr , "expected int bitmask of 0x%08x", bitmask );
1554                         return EXPP_ReturnIntError( PyExc_TypeError, errstr );
1555                 }
1556
1557                 param = PyInt_AS_LONG( value );
1558                 if( ( param & bitmask ) != param )
1559                         return EXPP_ReturnIntError( PyExc_ValueError,
1560                                                         "invalid bit(s) set in mask" );
1561         }
1562
1563         /* "mipmap" and "fields" can't be set at the same time */
1564
1565         if( ( param & TEX_MIPMAP ) &&
1566                         ( param & TEX_FIELDS ) )
1567                 return EXPP_ReturnIntError( PyExc_ValueError,
1568                                 "image flags MIPMAP and FIELDS cannot be used together" );
1569
1570         /* everything is OK; save the new flag setting */
1571
1572         self->texture->imaflag = param;
1573         return 0;
1574 }
1575
1576 static int Texture_setName( BPy_Texture * self, PyObject * value )
1577 {
1578         char *name;
1579         char buf[21];
1580
1581         name = PyString_AsString ( value );
1582         if( !name )
1583                 return EXPP_ReturnIntError( PyExc_TypeError,
1584                                               "expected string argument" );
1585
1586         PyOS_snprintf( buf, sizeof( buf ), "%s", name );
1587
1588         rename_id( &self->texture->id, buf );
1589
1590         return 0;
1591 }
1592
1593 static int Texture_setNoiseDepth( BPy_Texture * self, PyObject * value )
1594 {
1595         short max = EXPP_TEX_NOISEDEPTH_MAX;
1596
1597         /* for whatever reason, magic texture has a different max value */
1598
1599         if( self->texture->type == TEX_MAGIC )
1600                 max = EXPP_TEX_NOISEDEPTH_MAX_MAGIC;
1601
1602         return EXPP_setIValueClamped ( value, &self->texture->noisedepth,
1603                                                                 EXPP_TEX_NOISEDEPTH_MIN, max, 'h' );
1604 }
1605
1606 static int Texture_setNoiseSize( BPy_Texture * self, PyObject * value )
1607 {
1608         return EXPP_setFloatClamped ( value, &self->texture->noisesize,
1609                                                                 EXPP_TEX_NOISESIZE_MIN,
1610                                                                 EXPP_TEX_NOISESIZE_MAX );
1611 }
1612
1613 static int Texture_setNoiseType( BPy_Texture * self, PyObject * value )
1614 {
1615         char *param;
1616
1617         if( !PyString_Check( value ) )
1618                 return EXPP_ReturnIntError( PyExc_TypeError,
1619                                               "expected string argument" );
1620         param = PyString_AS_STRING( value );
1621
1622         if( STREQ( param, "soft" ) )
1623                 self->texture->noisetype = TEX_NOISESOFT;
1624         else if( STREQ( param, "hard" ) )
1625                 self->texture->noisetype = TEX_NOISEPERL;
1626         else
1627                 return EXPP_ReturnIntError( PyExc_ValueError,
1628                                               "noise type must be 'soft' or 'hard'" );
1629
1630         return 0;
1631 }
1632
1633 static int Texture_setNoiseBasis( BPy_Texture * self, PyObject * value )
1634 {
1635     int param;
1636
1637         if( !PyInt_CheckExact ( value ) )
1638                 return EXPP_ReturnIntError( PyExc_TypeError, 
1639                                 "expected int (see 'Noise' constant dictionary)" );
1640
1641         param = PyInt_AS_LONG ( value );
1642
1643         if ( param < TEX_BLENDER
1644                         || ( param > TEX_VORONOI_CRACKLE
1645                         && param != TEX_CELLNOISE ) )
1646                 return EXPP_ReturnIntError( PyExc_ValueError,
1647                                               "invalid noise type" );
1648
1649         self->texture->noisebasis = param;
1650         return 0;
1651 }
1652
1653 static int Texture_setNoiseBasis2( BPy_Texture * self, PyObject * value,
1654                                                                 void *type )
1655 {
1656         /*
1657          * if type is EXPP_TEX_NOISEBASIS2, then this is the "noiseBasis2"
1658          * attribute, so check the range and set the whole value
1659          */
1660
1661         if( (int)type == EXPP_TEX_NOISEBASIS2 ) {
1662         int param;
1663                 if( !PyInt_CheckExact ( value ) )
1664                         return EXPP_ReturnIntError( PyExc_TypeError, 
1665                                         "expected int (see 'Noise' constant dictionary)" );
1666
1667                 param = PyInt_AS_LONG ( value );
1668
1669                 if ( param < TEX_BLENDER
1670                                 || ( param > TEX_VORONOI_CRACKLE
1671                                 && param != TEX_CELLNOISE ) )
1672                         return EXPP_ReturnIntError( PyExc_ValueError,
1673                                                           "invalid noise type" );
1674
1675                 self->texture->noisebasis2 = param;
1676
1677         /*
1678          * for other type values, the attribute is "sine", "saw" or "tri", 
1679          * so set the noise basis to the supplied type if value is 1
1680          */
1681
1682         } else {
1683                 if( !PyInt_CheckExact ( value ) )
1684                         return EXPP_ReturnIntError( PyExc_TypeError, 
1685                                         "expected int value of 1" );
1686
1687                 if( PyInt_AS_LONG ( value ) != 1 )
1688                         return EXPP_ReturnIntError( PyExc_ValueError,
1689                                                           "expected int value of 1" );
1690
1691                 self->texture->noisebasis2 = (int)type;
1692         }
1693         return 0;
1694 }
1695
1696 static int Texture_setRepeat( BPy_Texture * self, PyObject * args )
1697 {
1698         int repeat[2];
1699
1700         if( !PyArg_ParseTuple( args, "ii", &repeat[0], &repeat[1] ) )
1701                 return EXPP_ReturnIntError( PyExc_TypeError,
1702                                               "expected tuple of 2 ints" );
1703
1704         self->texture->xrepeat = EXPP_ClampInt( repeat[0], EXPP_TEX_REPEAT_MIN,
1705                                                                                         EXPP_TEX_REPEAT_MAX );
1706         self->texture->yrepeat = EXPP_ClampInt( repeat[1], EXPP_TEX_REPEAT_MIN,
1707                                                                                         EXPP_TEX_REPEAT_MAX );
1708
1709         return 0;
1710 }
1711
1712 static int Texture_setRGBCol( BPy_Texture * self, PyObject * args )
1713 {
1714         float rgb[3];
1715
1716         if( !PyArg_ParseTuple( args, "fff", &rgb[0], &rgb[1], &rgb[2] ) )
1717                 return EXPP_ReturnIntError( PyExc_TypeError,
1718                                               "expected tuple of 3 floats" );
1719
1720         self->texture->rfac = EXPP_ClampFloat( rgb[0], EXPP_TEX_RGBCOL_MIN,
1721                                                                                         EXPP_TEX_RGBCOL_MAX );
1722         self->texture->gfac = EXPP_ClampFloat( rgb[1], EXPP_TEX_RGBCOL_MIN,
1723                                                                                         EXPP_TEX_RGBCOL_MAX );
1724         self->texture->bfac = EXPP_ClampFloat( rgb[2], EXPP_TEX_RGBCOL_MIN,
1725                                                                                         EXPP_TEX_RGBCOL_MAX );
1726
1727         return 0;
1728 }
1729
1730 static int Texture_setSType( BPy_Texture * self, PyObject * value )
1731 {
1732         short param;
1733         const char *dummy = NULL;
1734
1735         if( !PyInt_CheckExact ( value ) )
1736                 return EXPP_ReturnIntError( PyExc_TypeError,
1737                                               "expected int argument" );
1738
1739         param = PyInt_AS_LONG ( value );
1740
1741         /* use the stype map to find out if this is a valid stype for this type *
1742          * note that this will allow CLD_COLOR when type is ENVMAP. there's not *
1743          * much that we can do about this though.                               */
1744         if( !EXPP_map_getStrVal
1745             ( tex_stype_map[self->texture->type], param, &dummy ) )
1746                 return EXPP_ReturnIntError( PyExc_ValueError,
1747                                               "invalid stype (for this type)" );
1748
1749         if( self->texture->type == TEX_VORONOI )
1750                 self->texture->vn_coltype = param;
1751 #if 0
1752         else if( self->texture->type == TEX_MUSGRAVE )
1753                 self->texture->noisebasis = param;
1754 #endif
1755         else if( self->texture->type == TEX_ENVMAP )
1756                 self->texture->env->stype = param;
1757         else 
1758                 self->texture->stype = param;
1759
1760         return 0;
1761 }
1762
1763 static int Texture_setTurbulence( BPy_Texture * self, PyObject * value )
1764 {
1765         return EXPP_setFloatClamped ( value, &self->texture->turbul,
1766                                                                 EXPP_TEX_TURBULENCE_MIN,
1767                                                                 EXPP_TEX_TURBULENCE_MAX );
1768 }
1769
1770 static int Texture_setHFracDim( BPy_Texture * self, PyObject * value )
1771 {
1772         return EXPP_setFloatClamped ( value, &self->texture->mg_H,
1773                                                                 EXPP_TEX_MH_G_MIN,
1774                                                                 EXPP_TEX_MH_G_MAX );
1775 }
1776
1777 static int Texture_setLacunarity( BPy_Texture * self, PyObject * value )
1778 {
1779         return EXPP_setFloatClamped ( value, &self->texture->mg_lacunarity,
1780                                                                 EXPP_TEX_LACUNARITY_MIN,
1781                                                                 EXPP_TEX_LACUNARITY_MAX );
1782 }
1783
1784 static int Texture_setOcts( BPy_Texture * self, PyObject * value )
1785 {
1786         return EXPP_setFloatClamped ( value, &self->texture->mg_octaves,
1787                                                                 EXPP_TEX_OCTS_MIN,
1788                                                                 EXPP_TEX_OCTS_MAX );
1789 }
1790
1791 static int Texture_setIScale( BPy_Texture * self, PyObject * value )
1792 {
1793         return EXPP_setFloatClamped ( value, &self->texture->ns_outscale,
1794                                                                 EXPP_TEX_ISCALE_MIN,
1795                                                                 EXPP_TEX_ISCALE_MAX );
1796 }
1797
1798 static int Texture_setType( BPy_Texture * self, PyObject * value )
1799 {
1800         int err = EXPP_setIValueRange ( value, &self->texture->type,
1801                                                                 EXPP_TEX_TYPE_MIN,
1802                                                                 EXPP_TEX_TYPE_MAX, 'h' );
1803
1804         /*
1805          * if we set the texture OK, and it's a environment map, and
1806          * there is no environment map yet, allocate one (code borrowed
1807          * from texture_panel_envmap() in source/blender/src/buttons_shading.c)
1808          */
1809
1810         if( !err && self->texture->type == TEX_ENVMAP 
1811                         && !self->texture->env ) {
1812                 self->texture->env = RE_add_envmap();
1813                 self->texture->env->object= OBACT;
1814         }
1815         return err;
1816 }
1817
1818 static int Texture_setDistMetric( BPy_Texture * self, PyObject * value )
1819 {
1820 #if 0
1821         char *dist = NULL;
1822
1823         if( !PyArg_ParseTuple( value, "s", &dist ) )
1824                 return EXPP_ReturnPyObjError( PyExc_TypeError,
1825                                               "expected string argument" );
1826
1827         /* can we really trust texture->type? */
1828         if( self->texture->type == TEX_VORONOI &&
1829             !EXPP_map_getShortVal( tex_stype_map[self->texture->type + 2],
1830                                    dist, &self->texture->vn_distm ) )
1831                 return EXPP_ReturnPyObjError( PyExc_ValueError,
1832                                               "invalid dist metric type" );
1833
1834         Py_INCREF( Py_None );
1835         return Py_None;
1836 #else
1837         return EXPP_setIValueRange ( value, &self->texture->vn_distm,
1838                                                         TEX_DISTANCE,
1839                                                         TEX_MINKOVSKY, 'h' );
1840 #endif
1841 }
1842
1843 static int Texture_setExp( BPy_Texture * self, PyObject * value )
1844 {
1845         return EXPP_setFloatClamped ( value, &self->texture->vn_mexp,
1846                                                                 EXPP_TEX_EXP_MIN,
1847                                                                 EXPP_TEX_EXP_MAX );
1848 }
1849
1850 static int Texture_setWeight1( BPy_Texture * self, PyObject * value )
1851 {
1852         return EXPP_setFloatClamped ( value, &self->texture->vn_w1,
1853                                                                 EXPP_TEX_WEIGHT1_MIN,
1854                                                                 EXPP_TEX_WEIGHT1_MAX );
1855 }
1856
1857 static int Texture_setWeight2( BPy_Texture * self, PyObject * value )
1858 {
1859         return EXPP_setFloatClamped ( value, &self->texture->vn_w2,
1860                                                                 EXPP_TEX_WEIGHT2_MIN,
1861                                                                 EXPP_TEX_WEIGHT2_MAX );
1862 }
1863
1864 static int Texture_setWeight3( BPy_Texture * self, PyObject * value )
1865 {
1866         return EXPP_setFloatClamped ( value, &self->texture->vn_w3,
1867                                                                 EXPP_TEX_WEIGHT3_MIN,
1868                                                                 EXPP_TEX_WEIGHT3_MAX );
1869 }
1870
1871 static int Texture_setWeight4( BPy_Texture * self, PyObject * value )
1872 {
1873         return EXPP_setFloatClamped ( value, &self->texture->vn_w4,
1874                                                                 EXPP_TEX_WEIGHT4_MIN,
1875                                                                 EXPP_TEX_WEIGHT4_MAX );
1876 }
1877
1878 static int Texture_setDistAmnt( BPy_Texture * self, PyObject * value )
1879 {
1880         return EXPP_setFloatClamped ( value, &self->texture->dist_amount,
1881                                                                 EXPP_TEX_DISTAMNT_MIN,
1882                                                                 EXPP_TEX_DISTAMNT_MAX );
1883 }
1884
1885 static PyObject *Texture_getIpo( BPy_Texture * self )
1886 {
1887         struct Ipo *ipo = self->texture->ipo;
1888
1889         if( !ipo ) {
1890                 Py_INCREF( Py_None );
1891                 return Py_None;
1892         }
1893
1894         return Ipo_CreatePyObject( ipo );
1895 }
1896
1897 /*
1898  * this should accept a Py_None argument and just delete the Ipo link
1899  * (as Texture_clearIpo() does)
1900  */
1901
1902 static int Texture_setIpo( BPy_Texture * self, PyObject * value )
1903 {
1904         Ipo *ipo = NULL;
1905         Ipo *oldipo = self->texture->ipo;
1906         ID *id;
1907
1908         /* if parameter is not None, check for valid Ipo */
1909
1910         if ( value != Py_None ) {
1911                 if ( !Ipo_CheckPyObject( value ) )
1912                         return EXPP_ReturnIntError( PyExc_RuntimeError,
1913                                                 "expected an Ipo object" );
1914
1915                 ipo = Ipo_FromPyObject( value );
1916
1917                 if( !ipo )
1918                         return EXPP_ReturnIntError( PyExc_RuntimeError,
1919                                                 "null ipo!" );
1920
1921                 if( ipo->blocktype != ID_TE )
1922                         return EXPP_ReturnIntError( PyExc_TypeError,
1923                                                 "Ipo is not a texture data Ipo" );
1924         }
1925
1926         /* if already linked to Ipo, delete link */
1927
1928         if ( oldipo ) {
1929                 id = &oldipo->id;
1930                 if( id->us > 0 )
1931                         id->us--;
1932         }
1933
1934         /* assign new Ipo and increment user count, or set to NULL if deleting */
1935
1936         self->texture->ipo = ipo;
1937         if ( ipo ) {
1938                 id = &ipo->id;
1939                 id->us++;
1940         }
1941
1942         return 0;
1943 }
1944
1945 static PyObject *Texture_getAnimFrames( BPy_Texture *self )
1946 {
1947         PyObject *attr = PyInt_FromLong( self->texture->frames );
1948
1949         if( !attr )
1950                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1951                                 "couldn't get attribute" );
1952
1953         return attr;
1954 }
1955
1956 static PyObject *Texture_getAnimLength( BPy_Texture *self )
1957 {
1958         PyObject *attr = PyInt_FromLong( self->texture->len );
1959
1960         if( !attr )
1961                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1962                 "couldn't get attribute" );return attr;
1963
1964         return attr;
1965 }
1966
1967 static PyObject *Texture_getAnimMontage( BPy_Texture *self )
1968 {
1969         PyObject *attr;
1970         
1971         attr = Py_BuildValue( "((i,i),(i,i),(i,i),(i,i))",
1972                                                 self->texture->fradur[0][0],
1973                                                 self->texture->fradur[0][1],
1974                                                 self->texture->fradur[1][0],
1975                                                 self->texture->fradur[1][1],
1976                                                 self->texture->fradur[2][0],
1977                                                 self->texture->fradur[2][1],
1978                                                 self->texture->fradur[3][0],
1979                                                 self->texture->fradur[3][1] );
1980
1981         if( !attr )
1982                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1983                                 "couldn't get attribute" );
1984
1985         return attr;
1986 }
1987
1988 static PyObject *Texture_getAnimOffset( BPy_Texture *self )
1989 {
1990         PyObject *attr = PyInt_FromLong( self->texture->offset );
1991
1992         if( !attr )
1993                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1994                                 "couldn't get attribute" );
1995
1996         return attr;
1997 }
1998
1999 static PyObject *Texture_getAnimStart( BPy_Texture *self )
2000 {
2001         PyObject *attr = PyInt_FromLong( self->texture->sfra );
2002
2003         if( !attr )
2004                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2005                                 "couldn't get attribute" );
2006
2007         return attr;
2008 }
2009
2010 static PyObject *Texture_getBrightness( BPy_Texture *self )
2011 {
2012         PyObject *attr = PyFloat_FromDouble ( self->texture->bright );
2013
2014         if( !attr )
2015                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2016                                 "couldn't get attribute" );
2017
2018         return attr;
2019 }
2020
2021 static PyObject *Texture_getContrast( BPy_Texture *self )
2022 {
2023         PyObject *attr = PyFloat_FromDouble( self->texture->contrast );
2024
2025         if( !attr )
2026                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2027                                 "couldn't get attribute" );
2028
2029         return attr;
2030 }
2031
2032 static PyObject *Texture_getCrop( BPy_Texture *self )
2033 {
2034         PyObject *attr;
2035
2036         attr = Py_BuildValue( "(f,f,f,f)",
2037                                                         self->texture->cropxmin,
2038                                                         self->texture->cropymin,
2039                                                         self->texture->cropxmax,
2040                                                         self->texture->cropymax );
2041         if( !attr )
2042                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2043                                 "couldn't get attribute" );
2044
2045         return attr;
2046 }
2047
2048 static PyObject *Texture_getDistAmnt( BPy_Texture *self )
2049 {
2050         PyObject *attr = PyFloat_FromDouble( self->texture->dist_amount );
2051
2052         if( !attr )
2053                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2054                                 "couldn't get attribute" );
2055
2056         return attr;
2057 }
2058
2059 static PyObject *Texture_getDistMetric( BPy_Texture *self )
2060 {
2061         PyObject *attr = PyInt_FromLong( self->texture->vn_distm );
2062
2063         if( !attr )
2064                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2065                                 "couldn't get attribute" );
2066
2067         return attr;
2068 }
2069
2070 static PyObject *Texture_getExp( BPy_Texture *self )
2071 {
2072         PyObject *attr = PyFloat_FromDouble( self->texture->vn_mexp );
2073
2074         if( !attr )
2075                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2076                                 "couldn't get attribute" );
2077
2078         return attr;
2079 }
2080
2081 static PyObject *Texture_getIntExtend( BPy_Texture * self )
2082 {
2083         PyObject *attr = PyInt_FromLong( self->texture->extend );
2084
2085         if( !attr )
2086                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2087                                 "couldn't get attribute" );
2088
2089         return attr;
2090 }
2091
2092 static PyObject *Texture_getFieldsPerImage( BPy_Texture *self )
2093 {
2094         PyObject *attr = PyInt_FromLong( self->texture->fie_ima );
2095
2096         if( !attr )
2097                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2098                                 "couldn't get attribute" );
2099
2100         return attr;
2101 }
2102
2103 static PyObject *Texture_getFilterSize( BPy_Texture *self )
2104 {
2105         PyObject *attr = PyFloat_FromDouble( self->texture->filtersize );
2106
2107         if( !attr )
2108                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2109                                 "couldn't get attribute" );
2110
2111         return attr;
2112 }
2113
2114 static PyObject *Texture_getFlags( BPy_Texture *self )
2115 {
2116         PyObject *attr = PyInt_FromLong( self->texture->flag );
2117
2118         if( !attr )
2119                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2120                                 "couldn't get attribute" );
2121
2122         return attr;
2123 }
2124
2125 static PyObject *Texture_getHFracDim( BPy_Texture *self )
2126 {
2127         PyObject *attr = PyInt_FromLong( self->texture->mg_H );
2128
2129         if( !attr )
2130                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2131                                 "couldn't get attribute" );
2132
2133         return attr;
2134 }
2135
2136 static PyObject *Texture_getImageFlags( BPy_Texture *self, void *type )
2137 {
2138         PyObject *attr;
2139
2140         /*
2141          * type == 0 means attribute "imageFlags"
2142          * other types means attribute "mipmap", "calcAlpha", etc
2143          */
2144
2145         if( (int)type )
2146                 attr = EXPP_getBitfield( &self->texture->imaflag, (int)type, 'h' );
2147         else
2148                 attr = PyInt_FromLong( self->texture->imaflag );
2149
2150         if( !attr )
2151                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2152                                 "couldn't get attribute" );
2153
2154         return attr;
2155 }
2156
2157 static PyObject *Texture_getIScale( BPy_Texture *self )
2158 {
2159         PyObject *attr = PyFloat_FromDouble( self->texture->ns_outscale );
2160
2161         if( !attr )
2162                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2163                                 "couldn't get attribute" );
2164
2165         return attr;
2166 }
2167
2168 static PyObject *Texture_getLacunarity( BPy_Texture *self )
2169 {
2170         PyObject *attr = PyFloat_FromDouble( self->texture->mg_lacunarity );
2171
2172         if( !attr )
2173                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2174                                 "couldn't get attribute" );
2175
2176         return attr;
2177 }
2178
2179 static PyObject *Texture_getNoiseBasis( BPy_Texture *self )
2180 {
2181         PyObject *attr = PyInt_FromLong( self->texture->noisebasis );
2182
2183         if( !attr )
2184                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2185                                 "couldn't get attribute" );
2186
2187         return attr;
2188 }
2189
2190 static PyObject *Texture_getNoiseBasis2( BPy_Texture *self, void *type )
2191 {
2192         PyObject *attr;
2193
2194         /*
2195          * type == EXPP_TEX_NOISEBASIS2 means attribute "noiseBasis2"
2196          * other types means attribute "sine", "saw", or "tri" attribute
2197          */
2198
2199         if( (int)type == EXPP_TEX_NOISEBASIS2 )
2200                 attr = PyInt_FromLong( self->texture->noisebasis2 );
2201         else
2202                 attr = PyInt_FromLong( ( self->texture->noisebasis2 == (int)type ) ? 1 : 0 );
2203
2204         if( !attr )
2205                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2206                                 "couldn't get attribute" );
2207
2208         return attr;
2209 }
2210
2211 static PyObject *Texture_getNoiseDepth( BPy_Texture *self )
2212 {
2213         PyObject *attr = PyInt_FromLong( self->texture->noisedepth );
2214
2215         if( !attr )
2216                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2217                                 "couldn't get attribute" );
2218
2219         return attr;
2220 }
2221
2222 static PyObject *Texture_getNoiseSize( BPy_Texture *self )
2223 {
2224         PyObject *attr = PyFloat_FromDouble( self->texture->noisesize );
2225
2226         if( !attr )
2227                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2228                                 "couldn't get attribute" );
2229
2230         return attr;
2231 }
2232
2233 static PyObject *Texture_getNoiseType( BPy_Texture *self )
2234 {
2235         PyObject *attr;
2236
2237         if ( self->texture->noisetype == TEX_NOISESOFT )
2238                 attr = PyString_FromString( "soft" );
2239         else
2240                 attr = PyString_FromString( "hard" );
2241
2242         if( !attr )
2243                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2244                                 "couldn't get attribute" );
2245
2246         return attr;
2247 }
2248
2249 static PyObject *Texture_getOcts( BPy_Texture *self )
2250 {
2251         PyObject *attr = PyFloat_FromDouble( self->texture->mg_octaves );
2252
2253         if( !attr )
2254                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2255                                 "couldn't get attribute" );
2256
2257         return attr;
2258 }
2259
2260 static PyObject *Texture_getRepeat( BPy_Texture *self )
2261 {
2262         PyObject *attr;
2263
2264         attr = Py_BuildValue( "(i,i)", self->texture->xrepeat,
2265                                                                         self->texture->yrepeat );
2266         if( !attr )
2267                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2268                                 "couldn't get attribute" );
2269
2270         return attr;
2271 }
2272
2273 static PyObject *Texture_getRGBCol( BPy_Texture *self )
2274 {
2275         PyObject *attr;
2276
2277         attr = Py_BuildValue( "(f,f,f)", self->texture->rfac,
2278                                                                         self->texture->gfac, self->texture->bfac );
2279
2280         if( !attr )
2281                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2282                                 "couldn't get attribute" );
2283
2284         return attr;
2285 }
2286
2287 static PyObject *Texture_getSType( BPy_Texture *self )
2288 {
2289         PyObject *attr;
2290
2291         if( self->texture->type == TEX_VORONOI )
2292                 attr = PyInt_FromLong( self->texture->vn_coltype );
2293 #if 0
2294         else if( self->texture->type == TEX_MUSGRAVE )
2295                 attr = PyInt_FromLong( self->texture->noisebasis );
2296 #endif
2297         else if( self->texture->type == TEX_ENVMAP )
2298                 attr = PyInt_FromLong( self->texture->env->stype );
2299         else 
2300                 attr = PyInt_FromLong( self->texture->stype );
2301
2302         if( !attr )
2303                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2304                                 "couldn't get attribute" );
2305
2306         return attr;
2307 }
2308
2309 static PyObject *Texture_getTurbulence( BPy_Texture *self )
2310 {
2311         PyObject *attr = PyFloat_FromDouble( self->texture->turbul );
2312
2313         if( !attr )
2314                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2315                                 "couldn't get attribute" );
2316
2317         return attr;
2318 }
2319
2320 static PyObject *Texture_getType( BPy_Texture *self )
2321 {
2322         PyObject *attr = PyInt_FromLong( self->texture->type );
2323
2324         if( !attr )
2325                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2326                                 "couldn't get attribute" );
2327
2328         return attr;
2329 }
2330
2331 static PyObject *Texture_getUsers( BPy_Texture *self )
2332 {
2333         PyObject *attr = PyInt_FromLong( self->texture->id.us );
2334
2335         if( !attr )
2336                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2337                                 "couldn't get attribute" );
2338
2339         return attr;
2340 }
2341
2342 static PyObject *Texture_getWeight1( BPy_Texture *self )
2343 {
2344         PyObject *attr = PyFloat_FromDouble( self->texture->vn_w1 );
2345
2346         if( !attr )
2347                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2348                                 "couldn't get attribute" );
2349
2350         return attr;
2351 }
2352
2353 static PyObject *Texture_getWeight2( BPy_Texture *self )
2354 {
2355         PyObject *attr = PyFloat_FromDouble( self->texture->vn_w2 );
2356
2357         if( !attr )
2358                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2359                                 "couldn't get attribute" );
2360
2361         return attr;
2362 }
2363
2364 static PyObject *Texture_getWeight3( BPy_Texture *self )
2365 {
2366         PyObject *attr = PyFloat_FromDouble( self->texture->vn_w3 );
2367
2368         if( !attr )
2369                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2370                                 "couldn't get attribute" );
2371
2372         return attr;
2373 }
2374
2375 static PyObject *Texture_getWeight4( BPy_Texture *self )
2376 {
2377         PyObject *attr = PyFloat_FromDouble( self->texture->vn_w4 );
2378
2379         if( !attr )
2380                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2381                                 "couldn't get attribute" );
2382
2383         return attr;
2384 }
2385
2386 /* #####DEPRECATED###### */
2387
2388 static PyObject *Texture_oldsetImage( BPy_Texture * self, PyObject * args )
2389 {
2390         return EXPP_setterWrapper( (void *)self, args,
2391                                                                                 (setter)Texture_setImage );
2392 }
2393
2394 static PyObject *Texture_oldsetName( BPy_Texture * self, PyObject * args )
2395 {
2396         return EXPP_setterWrapper( (void *)self, args,
2397                                                                                 (setter)Texture_setName );
2398 }
2399
2400 static PyObject *Texture_oldsetIpo( BPy_Texture * self, PyObject * args )
2401 {
2402         return EXPP_setterWrapper ( (void *)self, args, (setter)Texture_setIpo );
2403 }
2404
2405 /*
2406  * clearIpo() returns True/False depending on whether material has an Ipo
2407  */
2408
2409 static PyObject *Texture_clearIpo( BPy_Texture * self )
2410 {
2411         /* if Ipo defined, delete it and return true */
2412
2413         if( self->texture->ipo ) {
2414                 PyObject *value = Py_BuildValue( "(O)", Py_None );
2415                 EXPP_setterWrapper( (void *)self, value, (setter)Texture_setIpo );
2416                 Py_DECREF( value );
2417                 return EXPP_incr_ret_True();
2418         }
2419         return EXPP_incr_ret_False(); /* no ipo found */
2420 }
2421
2422 /*
2423  * these older setter methods take strings as parameters; check the list of
2424  * strings to figure out which bits to set, then call new attribute setters
2425  * using the wrapper.
2426  */
2427
2428 static PyObject *Texture_oldsetFlags( BPy_Texture * self, PyObject * args )
2429 {
2430         unsigned int i, flag = 0;
2431         PyObject *value, *error;
2432
2433         /* check that we're passed a tuple */
2434
2435         if ( !PyTuple_Check( args ) )
2436                 return EXPP_ReturnPyObjError ( PyExc_AttributeError,
2437                                         "expected a tuple of string arguments" );
2438
2439         /* check each argument for type, find its value */
2440
2441         for ( i = PyTuple_Size( args ); i-- ; ) {
2442                 short thisflag;
2443                 char * name = PyString_AsString( PySequence_Fast_GET_ITEM( args, i ) );
2444                 if( !name )
2445                         return EXPP_ReturnPyObjError ( PyExc_AttributeError,
2446                                         "expected string argument" );
2447
2448                 if( !EXPP_map_getShortVal( tex_flag_map, name, &thisflag ) )
2449                         return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
2450                                                         "unknown Texture flag argument" ) );
2451
2452                 flag |= thisflag;
2453         }
2454
2455         /* build tuple, call wrapper */
2456
2457         value = Py_BuildValue( "(i)", flag );
2458         error = EXPP_setterWrapper( (void *)self, value, (setter)Texture_setFlags );
2459         Py_DECREF ( value );
2460         return error;
2461 }
2462
2463 /*
2464  * Texture_oldsetType() and Texture_oldsetExtend()
2465  *
2466  * These older setter methods convert a string into an integer setting, so
2467  * doesn't make sense to try wrapping them.
2468  */
2469
2470 static PyObject *Texture_oldsetType( BPy_Texture * self, PyObject * args )
2471 {
2472         char *type = NULL;
2473
2474         if( !PyArg_ParseTuple( args, "s", &type ) )
2475                 return EXPP_ReturnPyObjError( PyExc_TypeError,
2476                                               "expected string argument" );
2477
2478         if( !EXPP_map_getShortVal( tex_type_map, type, &self->texture->type ) )
2479                 return EXPP_ReturnPyObjError( PyExc_ValueError,
2480                                               "invalid texture type" );
2481
2482         /*
2483          * if we set the texture OK, and it's a environment map, and
2484          * there is no environment map yet, allocate one (code borrowed
2485          * from texture_panel_envmap() in source/blender/src/buttons_shading.c)
2486          */
2487
2488         if( self->texture->type == TEX_ENVMAP 
2489                         && !self->texture->env ) {
2490                 self->texture->env = RE_add_envmap();
2491                 self->texture->env->object= OBACT;
2492         }
2493
2494         Py_INCREF( Py_None );
2495         return Py_None;
2496 }
2497
2498 static PyObject *Texture_oldsetExtend( BPy_Texture * self, PyObject * args )
2499 {
2500         char *extend = NULL;
2501         if( !PyArg_ParseTuple( args, "s", &extend ) )
2502                 return EXPP_ReturnPyObjError( PyExc_TypeError,
2503                                               "expected string argument" );
2504
2505         if( !EXPP_map_getShortVal
2506             ( tex_extend_map, extend, &self->texture->extend ) )
2507                 return EXPP_ReturnPyObjError( PyExc_ValueError,
2508                                               "invalid extend mode" );
2509
2510         Py_INCREF( Py_None );
2511         return Py_None;
2512 }
2513
2514 /*
2515  * Texture_oldsetNoiseBasis(), Texture_oldsetDistNoise()
2516  *   Texture_oldsetSType(), Texture_oldsetDistMetric(),
2517  *   Texture_oldsetImageFlags()
2518  *
2519  * these old setter methods behave differently from the attribute
2520  * setters, so they are left unchanged.
2521  */
2522
2523 static PyObject *Texture_oldsetNoiseBasis( BPy_Texture * self, PyObject * args )
2524 {
2525 /* NOTE: leave as-is: don't use setterWrapper */
2526         char *nbasis;
2527
2528         if( !PyArg_ParseTuple( args, "s", &nbasis ) )
2529                 return EXPP_ReturnPyObjError( PyExc_TypeError,
2530                                                   "expected string argument" );
2531         if( self->texture->type == TEX_MUSGRAVE &&
2532             EXPP_map_getShortVal( tex_stype_map[TEX_DISTNOISE],
2533                                   nbasis, &self->texture->noisebasis ) );
2534         else if( self->texture->type == TEX_DISTNOISE &&
2535                  !EXPP_map_getShortVal( tex_stype_map[TEX_DISTNOISE],
2536                                         nbasis, &self->texture->noisebasis2 ) )
2537                 return EXPP_ReturnPyObjError( PyExc_ValueError,
2538                                               "invalid noise basis" );
2539
2540         Py_INCREF( Py_None );
2541         return Py_None;
2542 }
2543
2544 static PyObject *Texture_oldsetDistNoise( BPy_Texture * self, PyObject * args )
2545 {
2546 /* NOTE: leave as-is: don't use setterWrapper */
2547         char *nbasis;
2548
2549         if( !PyArg_ParseTuple( args, "s", &nbasis ) )
2550                 return EXPP_ReturnPyObjError( PyExc_TypeError,
2551                                               "expected string argument" );
2552         if( self->texture->type == TEX_DISTNOISE &&
2553             !EXPP_map_getShortVal( tex_stype_map[TEX_DISTNOISE],
2554                                    nbasis, &self->texture->noisebasis ) )
2555                 return EXPP_ReturnPyObjError( PyExc_ValueError,
2556                                               "invalid noise basis" );
2557
2558         Py_INCREF( Py_None );
2559         return Py_None;
2560 }
2561
2562 static PyObject *Texture_oldsetSType( BPy_Texture * self, PyObject * args )
2563 {
2564         char *stype = NULL;
2565         if( !PyArg_ParseTuple( args, "s", &stype ) )
2566                 return EXPP_ReturnPyObjError( PyExc_TypeError,
2567                                               "expected string argument" );
2568
2569         /* can we really trust texture->type? */
2570         if( ( self->texture->type == TEX_VORONOI &&
2571               EXPP_map_getShortVal( tex_stype_map[self->texture->type],
2572                                     stype, &self->texture->vn_coltype ) ) );
2573 #if 0
2574         else if( ( self->texture->type == TEX_MUSGRAVE &&
2575                    EXPP_map_getShortVal( tex_stype_map
2576                                          [TEX_DISTNOISE], stype,
2577                                          &self->texture->noisebasis ) ) );
2578 #endif
2579         else if( ( self->texture->type == TEX_ENVMAP &&
2580               EXPP_map_getShortVal( tex_stype_map[self->texture->type],
2581                                     stype, &self->texture->env->stype ) ) );
2582         else if( !EXPP_map_getShortVal
2583                  ( tex_stype_map[self->texture->type], stype,
2584                    &self->texture->stype ) )
2585                 return EXPP_ReturnPyObjError( PyExc_ValueError,
2586                                               "invalid texture stype" );
2587
2588         Py_INCREF( Py_None );
2589         return Py_None;
2590 }
2591
2592 static PyObject *Texture_oldsetDistMetric( BPy_Texture * self, PyObject * args )
2593 {
2594 /* NOTE: leave as-is: don't use setterWrapper */
2595         char *dist = NULL;
2596
2597         if( !PyArg_ParseTuple( args, "s", &dist ) )
2598                 return EXPP_ReturnPyObjError( PyExc_TypeError,
2599                                               "expected string argument" );
2600         /* can we really trust texture->type? */
2601         if( self->texture->type == TEX_VORONOI &&
2602             !EXPP_map_getShortVal( tex_stype_map[self->texture->type + 2],
2603                                    dist, &self->texture->vn_distm ) )
2604                 return EXPP_ReturnPyObjError( PyExc_ValueError,
2605                                               "invalid dist metric type" );
2606
2607         Py_INCREF( Py_None );
2608         return Py_None;
2609 }
2610
2611 static PyObject *Texture_oldsetImageFlags( BPy_Texture * self, PyObject * args )
2612 {
2613         unsigned int i, flag = 0;
2614
2615         /* check that we're passed a tuple of no more than 3 args*/
2616
2617         if( !PyTuple_Check( args ) )
2618                 return EXPP_ReturnPyObjError ( PyExc_AttributeError,
2619                                         "expected tuple of string arguments" );
2620
2621         /* check each argument for type, find its value */
2622
2623         for( i = PyTuple_Size( args ); i-- ; ) {
2624                 short thisflag;
2625                 char * name = PyString_AsString( PySequence_Fast_GET_ITEM( args, i ) );
2626                 if( !name )
2627                         return EXPP_ReturnPyObjError ( PyExc_AttributeError,
2628                                         "expected string argument" );
2629
2630                 if( !EXPP_map_getShortVal( tex_imageflag_map, name, &thisflag ) )
2631                         return EXPP_ReturnPyObjError( PyExc_ValueError,
2632                                                       "unknown Texture image flag name" );
2633
2634                 flag |= thisflag;
2635         }
2636
2637         self->texture->imaflag = flag;
2638
2639         Py_INCREF( Py_None );
2640         return Py_None;
2641 }
2642