| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | /* 
 | 
					
						
							| 
									
										
										
										
											2004-09-18 18:47:03 +00:00
										 |  |  |  * $Id$ | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. The Blender | 
					
						
							|  |  |  |  * Foundation also sells licenses for use in proprietary software under | 
					
						
							|  |  |  |  * the Blender License.  See http://www.blender.org/BL/ for information
 | 
					
						
							|  |  |  |  * about this. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 59 Temple Place - Suite 330, Boston, MA    02111-1307, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This is a new part of Blender. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  |  * Contributor(s): Alex Mole, Yehoshua Sapir | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2005-07-18 03:50:37 +00:00
										 |  |  | #include "MTex.h" /*This must come first*/
 | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-18 03:50:37 +00:00
										 |  |  | #include "BKE_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | #include "Texture.h"
 | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | #include "Object.h"
 | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | #include "gen_utils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | #include <DNA_material_types.h>
 | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python BPy_MTex methods declarations:                                     */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | static PyObject *MTex_setTexMethod( BPy_MTex * self, PyObject * args ); | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python method structure definition for Blender.Texture.MTex module:       */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | struct PyMethodDef M_MTex_methods[] = { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	{NULL, NULL, 0, NULL} | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python BPy_MTex methods table:                                            */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyMethodDef BPy_MTex_methods[] = { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	/* name, method, flags, doc */ | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 	{"setTex", ( PyCFunction ) MTex_setTexMethod, METH_VARARGS, | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	 "(i) - Set MTex Texture"}, | 
					
						
							|  |  |  | 	{NULL, NULL, 0, NULL} | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python MTex_Type callback function prototypes:                            */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static void MTex_dealloc( BPy_MTex * self ); | 
					
						
							|  |  |  | static int MTex_compare( BPy_MTex * a, BPy_MTex * b ); | 
					
						
							|  |  |  | static PyObject *MTex_repr( BPy_MTex * self ); | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | #define MTEXGET(x) \
 | 
					
						
							|  |  |  | 	static PyObject *MTex_get##x( BPy_MTex *self, void *closure ); | 
					
						
							|  |  |  | #define MTEXSET(x) \
 | 
					
						
							|  |  |  | 	static int MTex_set##x( BPy_MTex *self, PyObject *value, void *closure); | 
					
						
							|  |  |  | #define MTEXGETSET(x) \
 | 
					
						
							|  |  |  | 	MTEXGET(x) \ | 
					
						
							|  |  |  | 	MTEXSET(x) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MTEXGETSET(Tex) | 
					
						
							|  |  |  | MTEXGETSET(TexCo) | 
					
						
							|  |  |  | MTEXGETSET(Object) | 
					
						
							|  |  |  | MTEXGETSET(MapTo) | 
					
						
							|  |  |  | MTEXGETSET(Col) | 
					
						
							|  |  |  | MTEXGETSET(DVar) | 
					
						
							|  |  |  | MTEXGETSET(BlendMode) | 
					
						
							|  |  |  | MTEXGETSET(ColFac) | 
					
						
							|  |  |  | MTEXGETSET(NorFac) | 
					
						
							|  |  |  | MTEXGETSET(VarFac) | 
					
						
							|  |  |  | MTEXGETSET(DispFac) | 
					
						
							|  |  |  | MTEXGETSET(WarpFac) | 
					
						
							|  |  |  | MTEXGETSET(Ofs) | 
					
						
							|  |  |  | MTEXGETSET(Size) | 
					
						
							|  |  |  | MTEXGETSET(Mapping) | 
					
						
							|  |  |  | MTEXGETSET(Flag) | 
					
						
							|  |  |  | MTEXGETSET(ProjX) | 
					
						
							|  |  |  | MTEXGETSET(ProjY) | 
					
						
							|  |  |  | MTEXGETSET(ProjZ) | 
					
						
							|  |  |  | MTEXGETSET(MapToFlag) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python get/set methods table                                              */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyGetSetDef MTex_getseters[] = { | 
					
						
							|  |  |  | 	{ "tex", (getter) MTex_getTex, (setter) MTex_setTex, | 
					
						
							|  |  |  | 		"Texture whose mapping this MTex describes", NULL }, | 
					
						
							|  |  |  | 	{ "texco", (getter) MTex_getTexCo, (setter) MTex_setTexCo, | 
					
						
							|  |  |  | 		"Texture coordinate space (UV, Global, etc.)", NULL }, | 
					
						
							|  |  |  | 	{ "object", (getter) MTex_getObject, (setter) MTex_setObject, | 
					
						
							|  |  |  | 		"Object whose space to use when texco is Object", NULL }, | 
					
						
							|  |  |  | 	{ "mapto", (getter) MTex_getMapTo, (setter) MTex_setMapTo, | 
					
						
							|  |  |  | 		"What values the texture affects", NULL }, | 
					
						
							|  |  |  | 	{ "col", (getter) MTex_getCol, (setter) MTex_setCol, | 
					
						
							|  |  |  | 		"Color that the texture blends with", NULL }, | 
					
						
							|  |  |  | 	{ "dvar", (getter) MTex_getDVar, (setter) MTex_setDVar, | 
					
						
							|  |  |  | 		"Value that the texture blends with when not blending colors", NULL }, | 
					
						
							|  |  |  | 	{ "blendmode", (getter) MTex_getBlendMode, (setter) MTex_setBlendMode, | 
					
						
							|  |  |  | 		"Texture blending mode", NULL }, | 
					
						
							|  |  |  | 	{ "colfac", (getter) MTex_getColFac, (setter) MTex_setColFac, | 
					
						
							|  |  |  | 		"Factor by which texture affects color", NULL }, | 
					
						
							|  |  |  | 	{ "norfac", (getter) MTex_getNorFac, (setter) MTex_setNorFac, | 
					
						
							|  |  |  | 		"Factor by which texture affects normal", NULL }, | 
					
						
							|  |  |  | 	{ "varfac", (getter) MTex_getVarFac, (setter) MTex_setVarFac, | 
					
						
							|  |  |  | 		"Factor by which texture affects most variables", NULL }, | 
					
						
							|  |  |  | 	{ "dispfac", (getter) MTex_getDispFac, (setter) MTex_setDispFac, | 
					
						
							|  |  |  | 		"Factor by which texture affects displacement", NULL }, | 
					
						
							|  |  |  | 	{ "warpfac", (getter) MTex_getWarpFac, (setter) MTex_setWarpFac, | 
					
						
							|  |  |  | 		"Factor by which texture affects warp", NULL }, | 
					
						
							|  |  |  | 	{ "ofs", (getter) MTex_getOfs, (setter) MTex_setOfs, | 
					
						
							|  |  |  | 		"Offset to adjust texture space", NULL }, | 
					
						
							|  |  |  | 	{ "size", (getter) MTex_getSize, (setter) MTex_setSize, | 
					
						
							|  |  |  | 		"Size to scale texture space", NULL }, | 
					
						
							|  |  |  | 	{ "mapping", (getter) MTex_getMapping, (setter) MTex_setMapping, | 
					
						
							|  |  |  | 		"Mapping of texture coordinates (flat, cube, etc.)", NULL }, | 
					
						
							|  |  |  | 	{ "stencil", (getter) MTex_getFlag, (setter) MTex_setFlag, | 
					
						
							|  |  |  | 		"Stencil mode", (void*) MTEX_STENCIL }, | 
					
						
							|  |  |  | 	{ "neg", (getter) MTex_getFlag, (setter) MTex_setFlag, | 
					
						
							|  |  |  | 		"Negate texture values mode", (void*) MTEX_NEGATIVE }, | 
					
						
							|  |  |  | 	{ "noRGB", (getter) MTex_getFlag, (setter) MTex_setFlag, | 
					
						
							|  |  |  | 		"Convert texture RGB values to intensity values", | 
					
						
							|  |  |  | 		(void*) MTEX_RGBTOINT }, | 
					
						
							|  |  |  | 	{ "correctNor", (getter) MTex_getFlag, (setter) MTex_setFlag, | 
					
						
							|  |  |  | 		"Correct normal mapping for Texture space and Object space", | 
					
						
							|  |  |  | 		(void*) MTEX_VIEWSPACE }, | 
					
						
							|  |  |  | 	{ "xproj", (getter) MTex_getProjX, (setter) MTex_setProjX, | 
					
						
							|  |  |  | 		"Projection of X axis to Texture space", NULL }, | 
					
						
							|  |  |  | 	{ "yproj", (getter) MTex_getProjY, (setter) MTex_setProjY, | 
					
						
							|  |  |  | 		"Projection of Y axis to Texture space", NULL }, | 
					
						
							|  |  |  | 	{ "zproj", (getter) MTex_getProjZ, (setter) MTex_setProjZ, | 
					
						
							|  |  |  | 		"Projection of Z axis to Texture space", NULL }, | 
					
						
							|  |  |  | 	{ "mtCol", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag, | 
					
						
							|  |  |  | 		"How texture maps to color", (void*) MAP_COL }, | 
					
						
							|  |  |  | 	{ "mtNor", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag, | 
					
						
							|  |  |  | 		"How texture maps to normals", (void*) MAP_NORM }, | 
					
						
							|  |  |  | 	{ "mtCsp", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag, | 
					
						
							|  |  |  | 		"How texture maps to specularity color", (void*) MAP_COLSPEC }, | 
					
						
							|  |  |  | 	{ "mtCmir", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag, | 
					
						
							|  |  |  | 		"How texture maps to mirror color", (void*) MAP_COLMIR }, | 
					
						
							|  |  |  | 	{ "mtRef", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag, | 
					
						
							|  |  |  | 		"How texture maps to reflectivity", (void*) MAP_REF }, | 
					
						
							|  |  |  | 	{ "mtSpec", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag, | 
					
						
							|  |  |  | 		"How texture maps to specularity", (void*) MAP_SPEC }, | 
					
						
							|  |  |  | 	{ "mtEmit", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag, | 
					
						
							|  |  |  | 		"How texture maps to emit value", (void*) MAP_EMIT }, | 
					
						
							|  |  |  | 	{ "mtAlpha", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag, | 
					
						
							|  |  |  | 		"How texture maps to alpha value", (void*) MAP_ALPHA }, | 
					
						
							|  |  |  | 	{ "mtHard", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag, | 
					
						
							|  |  |  | 		"How texture maps to hardness", (void*) MAP_HAR }, | 
					
						
							|  |  |  | 	{ "mtRayMir", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag, | 
					
						
							|  |  |  | 		"How texture maps to RayMir value", (void*) MAP_RAYMIRR }, | 
					
						
							|  |  |  | 	{ "mtTranslu", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag, | 
					
						
							|  |  |  | 		"How texture maps to translucency", (void*) MAP_TRANSLU }, | 
					
						
							|  |  |  | 	{ "mtAmb", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag, | 
					
						
							|  |  |  | 		"How texture maps to ambient value", (void*) MAP_AMB }, | 
					
						
							|  |  |  | 	{ "mtDisp", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag, | 
					
						
							|  |  |  | 		"How texture maps to displacement", (void*) MAP_DISPLACE }, | 
					
						
							|  |  |  | 	{ "mtWarp", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag, | 
					
						
							|  |  |  | 		"How texture maps to warp", (void*) MAP_WARP }, | 
					
						
							|  |  |  | 	{ NULL, NULL, NULL, NULL, NULL } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python MTex_Type structure definition:                                    */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | PyTypeObject MTex_Type = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT( NULL )  | 
					
						
							|  |  |  | 	0,	/* ob_size */ | 
					
						
							|  |  |  | 	"Blender MTex",		/* tp_name */ | 
					
						
							|  |  |  | 	sizeof( BPy_MTex ),	/* tp_basicsize */ | 
					
						
							|  |  |  | 	0,			/* tp_itemsize */ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							|  |  |  | 	( destructor ) MTex_dealloc,	/* tp_dealloc */ | 
					
						
							|  |  |  | 	0,			/* tp_print */ | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 	0,	/* tp_getattr */ | 
					
						
							|  |  |  | 	0,	/* tp_setattr */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	( cmpfunc ) MTex_compare,	/* tp_compare */ | 
					
						
							|  |  |  | 	( reprfunc ) MTex_repr,	/* tp_repr */ | 
					
						
							|  |  |  | 	0,			/* tp_as_number */ | 
					
						
							|  |  |  | 	0,			/* tp_as_sequence */ | 
					
						
							|  |  |  | 	0,			/* tp_as_mapping */ | 
					
						
							|  |  |  | 	0,			/* tp_as_hash */ | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 	0, 0, 0, 0, 0, | 
					
						
							|  |  |  |   /*** Flags to define presence of optional/expanded features ***/ | 
					
						
							|  |  |  | 	Py_TPFLAGS_DEFAULT,	/*    long tp_flags; */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	0,			/* tp_doc */ | 
					
						
							|  |  |  | 	0, 0, 0, 0, 0, 0, | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 	BPy_MTex_methods,			/* tp_methods */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	0,			/* tp_members */ | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 	MTex_getseters,  /*    struct PyGetSetDef *tp_getset; */ | 
					
						
							|  |  |  | 	0,			/*    struct _typeobject *tp_base; */ | 
					
						
							|  |  |  | 	0,			/*    PyObject *tp_dict; */ | 
					
						
							|  |  |  | 	0,			/*    descrgetfunc tp_descr_get; */ | 
					
						
							|  |  |  | 	0,			/*    descrsetfunc tp_descr_set; */ | 
					
						
							|  |  |  | 	0,			/*    long tp_dictoffset; */ | 
					
						
							|  |  |  | 	0,			/*    initproc tp_init; */ | 
					
						
							|  |  |  | 	0,			/*    allocfunc tp_alloc; */ | 
					
						
							|  |  |  | 	0,			/*    newfunc tp_new; */ | 
					
						
							|  |  |  | 	/*  Low-level free-memory routine */ | 
					
						
							|  |  |  | 	0,			/*    freefunc tp_free;  */ | 
					
						
							|  |  |  | 	/* For PyObject_IS_GC */ | 
					
						
							|  |  |  | 	0,			/*    inquiry tp_is_gc;  */ | 
					
						
							|  |  |  | 	0,			/*    PyObject *tp_bases; */ | 
					
						
							|  |  |  | 	/* method resolution order */ | 
					
						
							|  |  |  | 	0,			/*    PyObject *tp_mro;  */ | 
					
						
							|  |  |  | 	0,			/*    PyObject *tp_cache; */ | 
					
						
							|  |  |  | 	0,			/*    PyObject *tp_subclasses; */ | 
					
						
							|  |  |  | 	0,			/*    PyObject *tp_weaklist; */ | 
					
						
							|  |  |  | 	0 | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | PyObject *MTex_Init( void ) | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *submodule; | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | /*	PyObject *dict; */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 	/* call PyType_Ready() to init dictionaries & such */ | 
					
						
							|  |  |  | 	if( PyType_Ready( &MTex_Type) < 0) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* So do we need this? */ | 
					
						
							|  |  |  | /*	MTex_Type.ob_type = &PyType_Type;*/ | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	submodule = Py_InitModule( "Blender.Texture.MTex", M_MTex_methods ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return submodule; | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | PyObject *MTex_CreatePyObject( MTex * mtex ) | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_MTex *pymtex; | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	pymtex = ( BPy_MTex * ) PyObject_NEW( BPy_MTex, &MTex_Type ); | 
					
						
							|  |  |  | 	if( !pymtex ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_MemoryError, | 
					
						
							|  |  |  | 					      "couldn't create BPy_MTex PyObject" ); | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	pymtex->mtex = mtex; | 
					
						
							|  |  |  | 	return ( PyObject * ) pymtex; | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | MTex *MTex_FromPyObject( PyObject * pyobj ) | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return ( ( BPy_MTex * ) pyobj )->mtex; | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | int MTex_CheckPyObject( PyObject * pyobj ) | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return ( pyobj->ob_type == &MTex_Type ); | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python BPy_MTex methods:                                                  */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | static PyObject *MTex_setTexMethod( BPy_MTex * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 	Tex *tex; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( args == Py_None ) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		tex = NULL; | 
					
						
							|  |  |  | 	} else if( Texture_CheckPyObject( args ) ) { | 
					
						
							|  |  |  | 		tex = Texture_FromPyObject( args ); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected Texture argument" ); | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( self->mtex->tex ) | 
					
						
							|  |  |  | 		self->mtex->tex->id.us--; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 	self->mtex->tex = tex; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( self->mtex->tex ) | 
					
						
							|  |  |  | 		self->mtex->tex->id.us++; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Py_INCREF( Py_None ); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static void MTex_dealloc( BPy_MTex * self ) | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject_DEL( self ); | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | static int MTex_compare( BPy_MTex * a, BPy_MTex * b ) | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 	return ( a->mtex == b->mtex ) ? 0 : -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_repr( BPy_MTex * self ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyString_FromFormat( "[MTex]" ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python BPy_MTex get and set functions:                                    */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getTex( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if( self->mtex->tex ) | 
					
						
							|  |  |  | 		return Texture_CreatePyObject( self->mtex->tex ); | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		Py_INCREF( Py_None ); | 
					
						
							|  |  |  | 		return Py_None; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | static int MTex_setTex( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Tex *tex; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( value == Py_None ) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		tex = NULL; | 
					
						
							|  |  |  | 	} else if( Texture_CheckPyObject( value ) ) { | 
					
						
							|  |  |  | 		tex = Texture_FromPyObject( value ); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected Texture argument" ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if( self->mtex->tex ) | 
					
						
							|  |  |  | 		self->mtex->tex->id.us--; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	self->mtex->tex = tex; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( self->mtex->tex ) | 
					
						
							|  |  |  | 		self->mtex->tex->id.us++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getTexCo( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyInt_FromLong( self->mtex->texco ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setTexCo( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int texco; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !PyInt_Check( value ) ) { | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 			"Value must be a member of Texture.TexCo dictionary" ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	texco = PyInt_AsLong( value ) ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (texco != TEXCO_ORCO && texco != TEXCO_REFL && texco != TEXCO_NORM && | 
					
						
							|  |  |  | 		texco != TEXCO_GLOB && texco != TEXCO_UV && texco != TEXCO_OBJECT && | 
					
						
							|  |  |  | 		texco != TEXCO_WINDOW && texco != TEXCO_VIEW && texco != TEXCO_STICKY ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 			"Value must be a member of Texture.TexCo dictionary" ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-29 05:08:29 +00:00
										 |  |  | 	self->mtex->texco = (short)texco; | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getObject( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if( self->mtex->object ) | 
					
						
							|  |  |  | 		return Object_CreatePyObject( self->mtex->object ); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 		Py_INCREF( Py_None ); | 
					
						
							|  |  |  | 		return Py_None; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | static int MTex_setObject( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Object *obj; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( value == Py_None ) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		obj = NULL; | 
					
						
							|  |  |  | 	} else if( Object_CheckPyObject( value ) ) { | 
					
						
							|  |  |  | 		obj = Object_FromPyObject( value ); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected Object argument" ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if( self->mtex->object ) | 
					
						
							|  |  |  | 		self->mtex->object->id.us--; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 	self->mtex->object = obj; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 	if( self->mtex->object ) | 
					
						
							|  |  |  | 		self->mtex->object->id.us++; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | static PyObject *MTex_getMapTo( BPy_MTex *self, void *closure ) | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 	return PyInt_FromLong( self->mtex->mapto ); | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | static int MTex_setMapTo( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 	int mapto; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !PyInt_Check( value ) ) { | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 			"expected an int" ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mapto = PyInt_AsLong( value ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* This method is deprecated anyway. */ | 
					
						
							|  |  |  | 	if ( mapto < 0 || mapto > 16383 ) { | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 			"Value must be a sum of values from Texture.MapTo dictionary" ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-29 05:08:29 +00:00
										 |  |  | 	self->mtex->mapto = (short)mapto; | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getCol( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return Py_BuildValue( "(f,f,f)", self->mtex->r, self->mtex->g, | 
					
						
							|  |  |  | 		self->mtex->b ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setCol( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float rgb[3]; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !PyArg_ParseTuple( value, "fff", | 
					
						
							|  |  |  | 		&rgb[0], &rgb[1], &rgb[2] ) ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected tuple of 3 floats" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for( i = 0; i < 3; ++i ) | 
					
						
							|  |  |  | 		if( rgb[i] < 0 || rgb[i] > 1 ) | 
					
						
							|  |  |  | 			return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 					      "values must be in range [0,1]" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	self->mtex->r = rgb[0]; | 
					
						
							|  |  |  | 	self->mtex->g = rgb[1]; | 
					
						
							|  |  |  | 	self->mtex->b = rgb[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getDVar( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyFloat_FromDouble(self->mtex->def_var); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setDVar( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ( !PyFloat_Check( value ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 						"expected a float" ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-29 05:08:29 +00:00
										 |  |  | 	f = (float)PyFloat_AsDouble(value); | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (f < 0 || f > 1) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 					      "values must be in range [0,1]" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	self->mtex->def_var = f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getBlendMode( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyInt_FromLong(self->mtex->blendtype); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setBlendMode( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int n; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ( !PyInt_Check( value ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 					    "Value must be member of Texture.BlendModes dictionary" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	n = PyInt_AsLong(value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*	if (n != MTEX_BLEND && n != MTEX_MUL && n != MTEX_ADD &&
 | 
					
						
							|  |  |  | 		n != MTEX_SUB && n != MTEX_DIV && n != MTEX_DARK && | 
					
						
							|  |  |  | 		n != MTEX_DIFF && n != MTEX_LIGHT && n != MTEX_SCREEN)*/ | 
					
						
							|  |  |  | 	if (n < 0 || n > 8) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 					    "Value must be member of Texture.BlendModes dictionary" ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-29 05:08:29 +00:00
										 |  |  | 	self->mtex->blendtype = (short)n; | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getColFac( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyFloat_FromDouble(self->mtex->colfac); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setColFac( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ( !PyFloat_Check( value ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 						"expected a float" ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-29 05:08:29 +00:00
										 |  |  | 	f = (float)PyFloat_AsDouble(value); | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (f < 0 || f > 1) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 					      "values must be in range [0,1]" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	self->mtex->colfac = f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getNorFac( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyFloat_FromDouble(self->mtex->norfac); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setNorFac( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ( !PyFloat_Check( value ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 						"expected a float" ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-29 05:08:29 +00:00
										 |  |  | 	f = (float)PyFloat_AsDouble(value); | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (f < 0 || f > 25) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 					      "values must be in range [0,25]" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	self->mtex->norfac = f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getVarFac( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyFloat_FromDouble(self->mtex->varfac); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setVarFac( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ( !PyFloat_Check( value ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 						"expected a float" ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-29 05:08:29 +00:00
										 |  |  | 	f = (float)PyFloat_AsDouble(value); | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (f < 0 || f > 1) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 					      "values must be in range [0,1]" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	self->mtex->varfac = f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getDispFac( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyFloat_FromDouble(self->mtex->dispfac); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setDispFac( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ( !PyFloat_Check( value ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 						"expected a float" ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-29 05:08:29 +00:00
										 |  |  | 	f = (float)PyFloat_AsDouble(value); | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (f < 0 || f > 1) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 					      "values must be in range [0,1]" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	self->mtex->dispfac = f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getWarpFac( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyFloat_FromDouble(self->mtex->warpfac); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setWarpFac( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ( !PyFloat_Check( value ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 						"expected a float" ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-29 05:08:29 +00:00
										 |  |  | 	f = (float)PyFloat_AsDouble(value); | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (f < 0 || f > 1) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 					      "values must be in range [0,1]" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	self->mtex->warpfac = f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getOfs( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return Py_BuildValue( "(f,f,f)", self->mtex->ofs[0], self->mtex->ofs[1], | 
					
						
							|  |  |  | 		self->mtex->ofs[2] ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setOfs( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float f[3]; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !PyArg_ParseTuple( value, "fff", &f[0], &f[1], &f[2] ) ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected tuple of 3 floats" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for( i = 0; i < 3; ++i ) | 
					
						
							|  |  |  | 		if( f[i] < -10 || f[i] > 10 ) | 
					
						
							|  |  |  | 			return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 					      "values must be in range [-10,10]" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	self->mtex->ofs[0] = f[0]; | 
					
						
							|  |  |  | 	self->mtex->ofs[1] = f[1]; | 
					
						
							|  |  |  | 	self->mtex->ofs[2] = f[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getSize( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return Py_BuildValue( "(f,f,f)", self->mtex->size[0], self->mtex->size[1], | 
					
						
							|  |  |  | 		self->mtex->size[2] ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setSize( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float f[3]; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !PyArg_ParseTuple( value, "fff", &f[0], &f[1], &f[2] ) ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected tuple of 3 floats" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for( i = 0; i < 3; ++i ) | 
					
						
							|  |  |  | 		if( f[i] < -100 || f[i] > 100 ) | 
					
						
							|  |  |  | 			return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 					      "values must be in range [-100,100]" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	self->mtex->size[0] = f[0]; | 
					
						
							|  |  |  | 	self->mtex->size[1] = f[1]; | 
					
						
							|  |  |  | 	self->mtex->size[2] = f[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getMapping( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyInt_FromLong( self->mtex->mapping ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setMapping( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int n; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ( !PyInt_Check( value ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 				"Value must be member of Texture.Mappings dictionary" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	n = PyInt_AsLong(value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*	if (n != MTEX_FLAT && n != MTEX_TUBE && n != MTEX_CUBE &&
 | 
					
						
							|  |  |  | 		n != MTEX_SPHERE) */ | 
					
						
							|  |  |  | 	if (n < 0 || n > 3) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 			    "Value must be member of Texture.Mappings dictionary" ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-29 05:08:29 +00:00
										 |  |  | 	self->mtex->mapping = (char)n; | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getFlag( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyBool_FromLong( self->mtex->texflag & ((int) closure) ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setFlag( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if ( !PyBool_Check( value ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 				"expected a bool"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ( value == Py_True ) | 
					
						
							|  |  |  | 		self->mtex->texflag |= (int)closure; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		self->mtex->texflag &= ~((int) closure); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getProjX( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyInt_FromLong( self->mtex->projx ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setProjX( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int proj; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !PyInt_Check( value ) ) { | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 			"Value must be a member of Texture.Proj dictionary" ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	proj = PyInt_AsLong( value ) ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* valid values are from PROJ_N to PROJ_Z = 0 to 3 */ | 
					
						
							|  |  |  | 	if (proj < 0 || proj > 3) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 			"Value must be a member of Texture.Proj dictionary" ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-29 05:08:29 +00:00
										 |  |  | 	self->mtex->projx = (char)proj; | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getProjY( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyInt_FromLong( self->mtex->projy ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setProjY( BPy_MTex *self, PyObject *value, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int proj; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !PyInt_Check( value ) ) { | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 			"Value must be a member of Texture.Proj dictionary" ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	proj = PyInt_AsLong( value ) ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* valid values are from PROJ_N to PROJ_Z = 0 to 3 */ | 
					
						
							|  |  |  | 	if (proj < 0 || proj > 3) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 			"Value must be a member of Texture.Proj dictionary" ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-29 05:08:29 +00:00
										 |  |  | 	self->mtex->projy = (char)proj; | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getProjZ( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyInt_FromLong( self->mtex->projz ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setProjZ( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int proj; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !PyInt_Check( value ) ) { | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 			"Value must be a member of Texture.Proj dictionary" ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	proj = PyInt_AsLong( value ) ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* valid values are from PROJ_N to PROJ_Z = 0 to 3 */ | 
					
						
							|  |  |  | 	if (proj < 0 || proj > 3) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 			"Value must be a member of Texture.Proj dictionary" ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-29 05:08:29 +00:00
										 |  |  | 	self->mtex->projz = (char)proj; | 
					
						
							| 
									
										
										
										
											2005-11-26 02:10:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *MTex_getMapToFlag( BPy_MTex *self, void *closure ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int flag = (int) closure; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ( self->mtex->mapto & flag ) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return PyInt_FromLong( ( self->mtex->maptoneg & flag ) ? -1 : 1 ); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return PyInt_FromLong( 0 ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int MTex_setMapToFlag( BPy_MTex *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int flag = (int) closure; | 
					
						
							|  |  |  | 	int intVal; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ( !PyInt_Check( value ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 				"expected an int"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	intVal = PyInt_AsLong( value ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (flag == MAP_COL || flag == MAP_COLSPEC || flag == MAP_COLMIR || | 
					
						
							|  |  |  | 		flag == MAP_WARP) { | 
					
						
							|  |  |  | 		if (intVal < 0 || intVal > 1) { | 
					
						
							|  |  |  | 			return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 				"value for that mapping must be 0 or 1" ); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		if (intVal < -1 || intVal > 1) { | 
					
						
							|  |  |  | 			return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 				"value for that mapping must be -1, 0 or 1" ); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (intVal) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	case 0: | 
					
						
							|  |  |  | 		self->mtex->mapto &= ~flag; | 
					
						
							|  |  |  | 		self->mtex->maptoneg &= ~flag; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case 1: | 
					
						
							|  |  |  | 		self->mtex->mapto |= flag; | 
					
						
							|  |  |  | 		self->mtex->maptoneg &= ~flag; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case -1: | 
					
						
							|  |  |  | 		self->mtex->mapto |= flag; | 
					
						
							|  |  |  | 		self->mtex->maptoneg |= flag; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2003-11-23 17:46:06 +00:00
										 |  |  | } |