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