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