diff options
author | Stephen Swaney <sswaney@centurytel.net> | 2005-09-21 23:48:40 +0400 |
---|---|---|
committer | Stephen Swaney <sswaney@centurytel.net> | 2005-09-21 23:48:40 +0400 |
commit | 5bac916e83cadce7ff5eec4fee9e905347a97b8c (patch) | |
tree | 5d123ad89521eef9802245020d7f5afeb4561a71 /source | |
parent | e1fe7c88eca7a2aef1050c606ee622724e92d09a (diff) |
Part of Bpy Cleanup: change attribute access to use tp_getset.
for these modules. Adds some new convenience funcs to gen_utils.
This is internal change only and presents little change to the
BPy API except for cleanup of some inconsistencies.
A big contribution from Ken Hughes. Thanks!
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/api2_2x/Lamp.c | 112 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Material.c | 2643 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Texture.c | 2849 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Lamp.py | 124 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Material.py | 221 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Texture.py | 256 | ||||
-rw-r--r-- | source/blender/python/api2_2x/gen_utils.c | 281 | ||||
-rw-r--r-- | source/blender/python/api2_2x/gen_utils.h | 40 | ||||
-rw-r--r-- | source/blender/python/api2_2x/rgbTuple.c | 50 | ||||
-rw-r--r-- | source/blender/python/api2_2x/rgbTuple.h | 2 |
10 files changed, 3796 insertions, 2782 deletions
diff --git a/source/blender/python/api2_2x/Lamp.c b/source/blender/python/api2_2x/Lamp.c index 27398f8ca46..3a1e4a815e5 100644 --- a/source/blender/python/api2_2x/Lamp.c +++ b/source/blender/python/api2_2x/Lamp.c @@ -1,5 +1,6 @@ /* * $Id$ + * * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or @@ -393,11 +394,11 @@ static PyGetSetDef BPy_Lamp_getseters[] = { NULL}, {"quad1", (getter)Lamp_getQuad1, (setter)Lamp_setQuad1, - "Quad lamp linear distance attenuatation", + "Quad lamp linear distance attenuation", NULL}, {"quad2", (getter)Lamp_getQuad2, (setter)Lamp_setQuad2, - "Quad lamp quadratic distance attenuatation", + "Quad lamp quadratic distance attenuation", NULL}, {"samples", (getter)Lamp_getSamples, (setter)Lamp_setSamples, @@ -1055,8 +1056,8 @@ static int Lamp_setName( BPy_Lamp * self, PyObject * value ) static int Lamp_setType( BPy_Lamp * self, PyObject * value ) { - return EXPP_setShortRange ( value, &self->lamp->type, - 0, EXPP_LAMP_TYPE_MAX ); + return EXPP_setIValueRange ( value, &self->lamp->type, + 0, EXPP_LAMP_TYPE_MAX, 'h' ); } static int Lamp_setMode( BPy_Lamp * self, PyObject * value ) @@ -1091,23 +1092,23 @@ static int Lamp_setMode( BPy_Lamp * self, PyObject * value ) static int Lamp_setSamples( BPy_Lamp * self, PyObject * value ) { - return EXPP_setShortClamped ( value, &self->lamp->samp, + return EXPP_setIValueClamped ( value, &self->lamp->samp, EXPP_LAMP_SAMPLES_MIN, - EXPP_LAMP_SAMPLES_MAX ); + EXPP_LAMP_SAMPLES_MAX, 'h' ); } static int Lamp_setBufferSize( BPy_Lamp * self, PyObject * value ) { - return EXPP_setShortClamped ( value, &self->lamp->bufsize, + return EXPP_setIValueClamped ( value, &self->lamp->bufsize, EXPP_LAMP_BUFFERSIZE_MIN, - EXPP_LAMP_BUFFERSIZE_MAX ); + EXPP_LAMP_BUFFERSIZE_MAX, 'h' ); } static int Lamp_setHaloStep( BPy_Lamp * self, PyObject * value ) { - return EXPP_setShortClamped ( value, &self->lamp->shadhalostep, + return EXPP_setIValueClamped ( value, &self->lamp->shadhalostep, EXPP_LAMP_HALOSTEP_MIN, - EXPP_LAMP_HALOSTEP_MAX ); + EXPP_LAMP_HALOSTEP_MAX, 'h' ); } static int Lamp_setEnergy( BPy_Lamp * self, PyObject * value ) @@ -1217,11 +1218,11 @@ static int Lamp_setComponent( BPy_Lamp * self, PyObject * value, { float color; - if( !PyFloat_CheckExact ( value ) ) + if( !PyNumber_Check ( value ) ) return EXPP_ReturnIntError( PyExc_TypeError, "expected float argument in [0.0,1.0]" ); - color = PyFloat_AS_DOUBLE( value ); + color = PyFloat_AsDouble( value ); color = EXPP_ClampFloat( color, EXPP_LAMP_COL_MIN, EXPP_LAMP_COL_MAX ); switch ( (int)closure ) { @@ -1241,14 +1242,7 @@ static int Lamp_setComponent( BPy_Lamp * self, PyObject * value, static int Lamp_setCol( BPy_Lamp * self, PyObject * args ) { - PyObject *error; - - error = rgbTuple_setCol( self->color, args ); - if ( error ) { - Py_DECREF ( error ); - return 0; - } - return -1; + return rgbTuple_setCol( self->color, args ); } /* lamp.addScriptLink */ @@ -1476,108 +1470,89 @@ static PyObject *Lamp_getUsers( BPy_Lamp * self ) /* #####DEPRECATED###### */ -/* - * Procedure to handle older setStuff() methods. Assumes that argument - * is a tuple with one object, and so grabs the object and passes it to - * the specified tp_getset setter for the corresponding attribute. - */ - -static PyObject *Lamp_setterWrapper ( BPy_Lamp * self, PyObject * args, - int (*func)( BPy_Lamp * self, PyObject * args )) -{ - int error; - - if ( !PyTuple_Check( args ) || PyTuple_Size( args ) != 1 ) - return EXPP_ReturnPyObjError( PyExc_RuntimeError, - "expected tuple of one item" ); - - error = func ( self, PySequence_Fast_GET_ITEM( args, 0 ) ); - if ( !error ) { - Py_INCREF( Py_None ); - return Py_None; - } else - return NULL; -} - static PyObject *Lamp_oldsetName( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setName ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setName ); } - static PyObject *Lamp_oldsetSamples( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setSamples ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setSamples ); } static PyObject *Lamp_oldsetBufferSize( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setBufferSize ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setBufferSize ); } static PyObject *Lamp_oldsetHaloStep( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setHaloStep ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setHaloStep ); } static PyObject *Lamp_oldsetEnergy( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setEnergy ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setEnergy ); } static PyObject *Lamp_oldsetDist( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setDist ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setDist ); } static PyObject *Lamp_oldsetSpotSize( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setSpotSize ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setSpotSize ); } static PyObject *Lamp_oldsetSpotBlend( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setSpotBlend ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setSpotBlend ); } static PyObject *Lamp_oldsetClipStart( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setClipStart ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setClipStart ); } static PyObject *Lamp_oldsetClipEnd( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setClipEnd ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setClipEnd ); } static PyObject *Lamp_oldsetBias( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setBias ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setBias ); } static PyObject *Lamp_oldsetSoftness( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setSoftness ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setSoftness ); } static PyObject *Lamp_oldsetHaloInt( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setHaloInt ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setHaloInt ); } static PyObject *Lamp_oldsetQuad1( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setQuad1 ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setQuad1 ); } static PyObject *Lamp_oldsetQuad2( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setQuad2 ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setQuad2 ); } static PyObject *Lamp_oldsetIpo( BPy_Lamp * self, PyObject * args ) { - return Lamp_setterWrapper ( self, args, Lamp_setIpo ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setIpo ); +} + +static PyObject *Lamp_oldsetCol( BPy_Lamp * self, PyObject * args ) +{ + return EXPP_setterWrapper ( (void *)self, args, (setter)Lamp_setCol ); } /* @@ -1595,7 +1570,7 @@ static PyObject *Lamp_clearIpo( BPy_Lamp * self ) if( self->lamp->ipo ) { PyObject *value = Py_BuildValue( "(O)", Py_None ); - Lamp_setterWrapper ( self, value, Lamp_setIpo ); + EXPP_setterWrapper ( (void *)self, value, (setter)Lamp_setIpo ); Py_DECREF ( value ); return EXPP_incr_ret_True(); } @@ -1638,7 +1613,7 @@ static PyObject *Lamp_oldsetType( BPy_Lamp * self, PyObject * args ) /* build tuple, call wrapper */ value = Py_BuildValue( "(i)", type ); - error = Lamp_setterWrapper ( self, value, Lamp_setType ); + error = EXPP_setterWrapper ( (void *)self, value, (setter)Lamp_setType ); Py_DECREF ( value ); return error; } @@ -1695,19 +1670,8 @@ static PyObject *Lamp_oldsetMode( BPy_Lamp * self, PyObject * args ) /* build tuple, call wrapper */ value = Py_BuildValue( "(i)", flag ); - error = Lamp_setterWrapper ( self, value, Lamp_setMode ); + error = EXPP_setterWrapper ( (void *)self, value, (setter)Lamp_setMode ); Py_DECREF ( value ); return error; } -/* - * This one isn't changed at all since rgbTuple_setCol() hasn't changed - * either, and the new attribute setter expects a tuple with a single - * argument. It's valid to do "lamp.setCol(r,g,b)", which passes three- - * argument tuple. - */ - -static PyObject *Lamp_oldsetCol( BPy_Lamp * self, PyObject * args ) -{ - return rgbTuple_setCol( self->color, args ); -} diff --git a/source/blender/python/api2_2x/Material.c b/source/blender/python/api2_2x/Material.c index a316039915c..fc550545857 100644 --- a/source/blender/python/api2_2x/Material.c +++ b/source/blender/python/api2_2x/Material.c @@ -35,6 +35,7 @@ #include "DNA_oops_types.h" #include "DNA_space_types.h" +#include "DNA_material_types.h" #include "BKE_main.h" #include "BKE_global.h" #include "BKE_library.h" @@ -54,34 +55,6 @@ /*****************************************************************************/ /* Python BPy_Material defaults: */ /*****************************************************************************/ -#define EXPP_MAT_MODE_TRACEABLE MA_TRACEBLE -#define EXPP_MAT_MODE_SHADOW MA_SHADOW -#define EXPP_MAT_MODE_SHADELESS MA_SHLESS -#define EXPP_MAT_MODE_WIRE MA_WIRE -#define EXPP_MAT_MODE_VCOL_LIGHT MA_VERTEXCOL -#define EXPP_MAT_MODE_HALO MA_HALO -#define EXPP_MAT_MODE_ZTRANSP MA_ZTRA -#define EXPP_MAT_MODE_VCOL_PAINT MA_VERTEXCOLP -#define EXPP_MAT_MODE_ZINVERT MA_ZINV -#define EXPP_MAT_MODE_HALORINGS MA_HALO_RINGS -#define EXPP_MAT_MODE_ENV MA_ENV -#define EXPP_MAT_MODE_HALOLINES MA_HALO_LINES -#define EXPP_MAT_MODE_ONLYSHADOW MA_ONLYSHADOW -#define EXPP_MAT_MODE_HALOXALPHA MA_HALO_XALPHA -#define EXPP_MAT_MODE_HALOSTAR MA_STAR -#define EXPP_MAT_MODE_TEXFACE MA_FACETEXTURE -#define EXPP_MAT_MODE_HALOTEX MA_HALOTEX -#define EXPP_MAT_MODE_HALOPUNO MA_HALOPUNO -#define EXPP_MAT_MODE_NOMIST MA_NOMIST -#define EXPP_MAT_MODE_HALOSHADE MA_HALO_SHADE -#define EXPP_MAT_MODE_HALOFLARE MA_HALO_FLARE -#define EXPP_MAT_MODE_RADIO MA_RADIO -#define EXPP_MAT_MODE_RAYMIRROR MA_RAYMIRROR -#define EXPP_MAT_MODE_ZTRA MA_ZTRA -#define EXPP_MAT_MODE_RAYTRANSP MA_RAYTRANSP -#define EXPP_MAT_MODE_ONLYSHADOW MA_ONLYSHADOW -#define EXPP_MAT_MODE_NOMIST MA_NOMIST -#define EXPP_MAT_MODE_ENV MA_ENV /* Material MIN, MAX values */ #define EXPP_MAT_ADD_MIN 0.0f #define EXPP_MAT_ADD_MAX 1.0f @@ -100,11 +73,7 @@ #define EXPP_MAT_SPECTRA_MIN 0.0f #define EXPP_MAT_SPECTRA_MAX 1.0f -/* Shader spesific settings */ -#define EXPP_MAT_SPEC_SHADER_MIN 0 -#define EXPP_MAT_SPEC_SHADER_MAX 4 -#define EXPP_MAT_DIFFUSE_SHADER_MIN 0 -#define EXPP_MAT_DIFFUSE_SHADER_MAX 3 +/* Shader specific settings */ #define EXPP_MAT_ROUGHNESS_MIN 0.0f #define EXPP_MAT_ROUGHNESS_MAX 3.140f @@ -124,31 +93,6 @@ #define EXPP_MAT_RMS_MAX 0.4f /* End shader settings */ -/* diff_shader */ -#define MA_DIFF_LAMBERT 0 -#define MA_DIFF_ORENNAYAR 1 -#define MA_DIFF_TOON 2 -#define MA_DIFF_MINNAERT 3 - -/* spec_shader */ -#define MA_SPEC_COOKTORR 0 -#define MA_SPEC_PHONG 1 -#define MA_SPEC_BLINN 2 -#define MA_SPEC_TOON 3 -#define MA_SPEC_WARDISO 4 - -/* shader dicts - Diffuse */ -#define EXPP_MAT_SHADER_DIFFUSE_LAMBERT MA_DIFF_LAMBERT -#define EXPP_MAT_SHADER_DIFFUSE_ORENNAYAR MA_DIFF_ORENNAYAR -#define EXPP_MAT_SHADER_DIFFUSE_TOON MA_DIFF_TOON -#define EXPP_MAT_SHADER_DIFFUSE_MINNAERT MA_DIFF_MINNAERT -/* shader dicts - Specular */ -#define EXPP_MAT_SHADER_SPEC_COOKTORR MA_SPEC_COOKTORR -#define EXPP_MAT_SHADER_SPEC_PHONG MA_SPEC_PHONG -#define EXPP_MAT_SHADER_SPEC_BLINN MA_SPEC_BLINN -#define EXPP_MAT_SHADER_SPEC_TOON MA_SPEC_TOON -#define EXPP_MAT_SHADER_SPEC_WARDISO MA_SPEC_WARDISO - #define EXPP_MAT_ZOFFS_MIN 0.0 #define EXPP_MAT_ZOFFS_MAX 10.0 #define EXPP_MAT_HALOSIZE_MIN 0.0 @@ -202,6 +146,17 @@ #define EXPP_MAT_MIRRTRANSADD_MIN 0.0 #define EXPP_MAT_MIRRTRANSADD_MAX 1.0 +/* closure values for getColorComponent()/setColorComponent() */ + +#define EXPP_MAT_COMP_R 0 +#define EXPP_MAT_COMP_G 1 +#define EXPP_MAT_COMP_B 2 +#define EXPP_MAT_COMP_SPECR 3 +#define EXPP_MAT_COMP_SPECG 4 +#define EXPP_MAT_COMP_SPECB 5 +#define EXPP_MAT_COMP_MIRR 6 +#define EXPP_MAT_COMP_MIRG 7 +#define EXPP_MAT_COMP_MIRB 8 #define IPOKEY_RGB 0 #define IPOKEY_ALPHA 1 @@ -213,11 +168,8 @@ #define IPOKEY_SIZE 13 #define IPOKEY_ALLMAPPING 11 - - - /*****************************************************************************/ -/* Python API function prototypes for the Material module. */ +/* Python API function prototypes for the Material module. */ /*****************************************************************************/ static PyObject *M_Material_New( PyObject * self, PyObject * args, PyObject * keywords ); @@ -226,11 +178,10 @@ static PyObject *M_Material_Get( PyObject * self, PyObject * args ); /* Not exposed nor used */ Material *GetMaterialByName( char *name ); - /*****************************************************************************/ -/* The following string definitions are used for documentation strings. */ -/* In Python these will be written to the console when doing a */ -/* Blender.Material.__doc__ */ +/* The following string definitions are used for documentation strings. In */ +/* Python these will be written to the console when doing a */ +/* Blender.Material.__doc__ */ /*****************************************************************************/ static char M_Material_doc[] = "The Blender Material module"; @@ -243,7 +194,7 @@ static char M_Material_Get_doc[] = () - return a list of all materials in the current scene."; /*****************************************************************************/ -/* Python method structure definition for Blender.Material module: */ +/* Python method structure definition for Blender.Material module: */ /*****************************************************************************/ struct PyMethodDef M_Material_methods[] = { {"New", ( PyCFunction ) M_Material_New, METH_VARARGS | METH_KEYWORDS, @@ -254,8 +205,8 @@ struct PyMethodDef M_Material_methods[] = { }; /*****************************************************************************/ -/* Function: M_Material_New */ -/* Python equivalent: Blender.Material.New */ +/* Function: M_Material_New */ +/* Python equivalent: Blender.Material.New */ /*****************************************************************************/ static PyObject *M_Material_New( PyObject * self, PyObject * args, PyObject * keywords ) @@ -368,44 +319,34 @@ static PyObject *Material_ModesDict( void ) { PyObject *Modes = PyConstant_New( ); -#undef EXPP_ADDCONST -#define EXPP_ADDCONST(name) \ - PyConstant_Insert(c, #name, PyInt_FromLong(EXPP_MAT_MODE_##name)) - -/* So that: - * EXPP_ADDCONST(TRACEABLE) becomes: - * constant_insert(c, "TRACEABLE", PyInt_FromLong(EXPP_MAT_MODE_TRACEABLE)) - */ - if( Modes ) { BPy_constant *c = ( BPy_constant * ) Modes; - EXPP_ADDCONST( TRACEABLE ); - EXPP_ADDCONST( SHADOW ); - EXPP_ADDCONST( SHADELESS ); - EXPP_ADDCONST( WIRE ); - EXPP_ADDCONST( VCOL_LIGHT ); - EXPP_ADDCONST( HALO ); - EXPP_ADDCONST( ZTRANSP ); - EXPP_ADDCONST( VCOL_PAINT ); - EXPP_ADDCONST( ZINVERT ); - EXPP_ADDCONST( HALORINGS ); - EXPP_ADDCONST( ENV ); - EXPP_ADDCONST( HALOLINES ); - EXPP_ADDCONST( ONLYSHADOW ); - EXPP_ADDCONST( HALOXALPHA ); - EXPP_ADDCONST( HALOSTAR ); - EXPP_ADDCONST( TEXFACE ); - EXPP_ADDCONST( HALOTEX ); - EXPP_ADDCONST( HALOPUNO ); - EXPP_ADDCONST( NOMIST ); - EXPP_ADDCONST( HALOSHADE ); - EXPP_ADDCONST( HALOFLARE ); - EXPP_ADDCONST( RADIO ); - EXPP_ADDCONST( RAYMIRROR ); - EXPP_ADDCONST( ZTRA ); - EXPP_ADDCONST( RAYTRANSP ); - + PyConstant_Insert(c, "TRACEABLE", PyInt_FromLong(MA_TRACEBLE)); + PyConstant_Insert(c, "SHADOW", PyInt_FromLong(MA_SHADOW)); + PyConstant_Insert(c, "SHADELESS", PyInt_FromLong(MA_SHLESS)); + PyConstant_Insert(c, "WIRE", PyInt_FromLong(MA_WIRE)); + PyConstant_Insert(c, "VCOL_LIGHT", PyInt_FromLong(MA_VERTEXCOL)); + PyConstant_Insert(c, "HALO", PyInt_FromLong(MA_HALO)); + PyConstant_Insert(c, "ZTRANSP", PyInt_FromLong(MA_ZTRA)); + PyConstant_Insert(c, "VCOL_PAINT", PyInt_FromLong(MA_VERTEXCOLP)); + PyConstant_Insert(c, "ZINVERT", PyInt_FromLong(MA_ZINV)); + PyConstant_Insert(c, "HALORINGS", PyInt_FromLong(MA_HALO_RINGS)); + PyConstant_Insert(c, "ENV", PyInt_FromLong(MA_ENV)); + PyConstant_Insert(c, "HALOLINES", PyInt_FromLong(MA_HALO_LINES)); + PyConstant_Insert(c, "ONLYSHADOW", PyInt_FromLong(MA_ONLYSHADOW)); + PyConstant_Insert(c, "HALOXALPHA", PyInt_FromLong(MA_HALO_XALPHA)); + PyConstant_Insert(c, "HALOSTAR", PyInt_FromLong(MA_STAR)); + PyConstant_Insert(c, "TEXFACE", PyInt_FromLong(MA_FACETEXTURE)); + PyConstant_Insert(c, "HALOTEX", PyInt_FromLong(MA_HALOTEX)); + PyConstant_Insert(c, "HALOPUNO", PyInt_FromLong(MA_HALOPUNO)); + PyConstant_Insert(c, "NOMIST", PyInt_FromLong(MA_NOMIST)); + PyConstant_Insert(c, "HALOSHADE", PyInt_FromLong(MA_HALO_SHADE)); + PyConstant_Insert(c, "HALOFLARE", PyInt_FromLong(MA_HALO_FLARE)); + PyConstant_Insert(c, "RADIO", PyInt_FromLong(MA_RADIO)); + PyConstant_Insert(c, "RAYMIRROR", PyInt_FromLong(MA_RAYMIRROR)); + PyConstant_Insert(c, "ZTRA", PyInt_FromLong(MA_ZTRA)); + PyConstant_Insert(c, "RAYTRANSP", PyInt_FromLong(MA_RAYTRANSP)); } return Modes; @@ -416,28 +357,19 @@ static PyObject *Material_ShadersDict( void ) { PyObject *Shaders = PyConstant_New( ); -#undef EXPP_ADDCONST -#define EXPP_ADDCONST(name) \ - PyConstant_Insert(c, #name, PyInt_FromLong(EXPP_MAT_SHADER_##name)) - -/* So that: - * EXPP_ADDCONST(DIFFUSE_LAMBERT) becomes: - * constant_insert(c, "TRACEABLE", PyInt_FromLong(EXPP_MAT_SHADER_DIFFUSE_LAMBERT)) - */ - if( Shaders ) { BPy_constant *c = ( BPy_constant * ) Shaders; - EXPP_ADDCONST( DIFFUSE_LAMBERT ); - EXPP_ADDCONST( DIFFUSE_ORENNAYAR ); - EXPP_ADDCONST( DIFFUSE_TOON ); - EXPP_ADDCONST( DIFFUSE_MINNAERT ); - - EXPP_ADDCONST( SPEC_COOKTORR ); - EXPP_ADDCONST( SPEC_PHONG ); - EXPP_ADDCONST( SPEC_BLINN ); - EXPP_ADDCONST( SPEC_TOON ); - EXPP_ADDCONST( SPEC_WARDISO ); + PyConstant_Insert(c, "DIFFUSE_LAMBERT", PyInt_FromLong(MA_DIFF_LAMBERT)); + PyConstant_Insert(c, "DIFFUSE_ORENNAYAR", PyInt_FromLong(MA_DIFF_ORENNAYAR)); + PyConstant_Insert(c, "DIFFUSE_TOON", PyInt_FromLong(MA_DIFF_TOON)); + PyConstant_Insert(c, "DIFFUSE_MINNAERT", PyInt_FromLong(MA_DIFF_MINNAERT)); + PyConstant_Insert(c, "SPEC_COOKTORR", PyInt_FromLong(MA_SPEC_COOKTORR)); + PyConstant_Insert(c, "SPEC_PHONG", PyInt_FromLong(MA_SPEC_PHONG)); + PyConstant_Insert(c, "SPEC_BLINN", PyInt_FromLong(MA_SPEC_BLINN)); + PyConstant_Insert(c, "SPEC_TOON", PyInt_FromLong(MA_SPEC_TOON)); + PyConstant_Insert(c, "SPEC_WARDISO", PyInt_FromLong(MA_SPEC_WARDISO)); + } return Shaders; @@ -451,7 +383,8 @@ PyObject *Material_Init( void ) { PyObject *submodule, *Modes, *Shaders; - Material_Type.ob_type = &PyType_Type; + if( PyType_Ready( &Material_Type ) < 0) + return NULL; Modes = Material_ModesDict( ); Shaders = Material_ShadersDict( ); @@ -481,6 +414,108 @@ PyObject *Material_Init( void ) /*** The Material PyType ***/ /***************************/ +static PyObject *Matr_oldsetAdd( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetAlpha( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetAmb( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetEmit( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetFilter( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetFlareBoost( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetFlareSeed( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetFlareSize( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetFresnelMirr( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetFresnelMirrFac( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetFresnelTrans( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetFresnelTransFac( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetHaloSeed( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetHaloSize( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetHardness( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetIOR( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetName( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetNFlares( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetNLines( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetNRings( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetNStars( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetRayMirr( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetMirrDepth( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetRef( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetSpec( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetSpecTransp( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetSubSize( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetTransDepth( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetZOffset( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetMode( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetIpo( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetRGBCol( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetSpecCol( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetSpecShader( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetMirCol( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetDiffuseShader( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetRoughness( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetSpecSize( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetDiffuseSize( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetSpecSmooth( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetDiffuseSmooth( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetDiffuseDarkness( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetRefracIndex( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetRms( BPy_Material * self, PyObject * args ); +static PyObject *Matr_oldsetTranslucency( BPy_Material * self, PyObject * args ); +; +static int Material_setIpo( BPy_Material * self, PyObject * value ); +static int Material_setName( BPy_Material * self, PyObject * value ); +static int Material_setMode( BPy_Material * self, PyObject * value ); +static int Material_setRGBCol( BPy_Material * self, PyObject * value ); +static int Material_setSpecCol( BPy_Material * self, PyObject * value ); +static int Material_setMirCol( BPy_Material * self, PyObject * value ); +static int Material_setColorComponent( BPy_Material * self, PyObject * value, + void * closure ); +static int Material_setAmb( BPy_Material * self, PyObject * value ); +static int Material_setEmit( BPy_Material * self, PyObject * value ); +static int Material_setSpecTransp( BPy_Material * self, PyObject * value ); +static int Material_setAlpha( BPy_Material * self, PyObject * value ); +static int Material_setRef( BPy_Material * self, PyObject * value ); +static int Material_setSpec( BPy_Material * self, PyObject * value ); +static int Material_setZOffset( BPy_Material * self, PyObject * value ); +static int Material_setAdd( BPy_Material * self, PyObject * value ); +static int Material_setHaloSize( BPy_Material * self, PyObject * value ); +static int Material_setFlareSize( BPy_Material * self, PyObject * value ); +static int Material_setFlareBoost( BPy_Material * self, PyObject * value ); +static int Material_setSubSize( BPy_Material * self, PyObject * value ); +static int Material_setHaloSeed( BPy_Material * self, PyObject * value ); +static int Material_setFlareSeed( BPy_Material * self, PyObject * value ); +static int Material_setHardness( BPy_Material * self, PyObject * value ); +static int Material_setNFlares( BPy_Material * self, PyObject * value ); +static int Material_setNStars( BPy_Material * self, PyObject * value ); +static int Material_setNLines( BPy_Material * self, PyObject * value ); +static int Material_setNRings( BPy_Material * self, PyObject * value ); +static int Material_setRayMirr( BPy_Material * self, PyObject * value ); +static int Material_setMirrDepth( BPy_Material * self, PyObject * value ); +static int Material_setFresnelMirr( BPy_Material * self, PyObject * value ); +static int Material_setFresnelMirrFac( BPy_Material * self, PyObject * value ); +static int Material_setIOR( BPy_Material * self, PyObject * value ); +static int Material_setTransDepth( BPy_Material * self, PyObject * value ); +static int Material_setFresnelTrans( BPy_Material * self, PyObject * value ); +static int Material_setFresnelTransFac( BPy_Material * self, PyObject * value ); +static int Material_setOopsLoc ( BPy_Material * self, PyObject * value ); +static int Material_setOopsSel ( BPy_Material * self, PyObject * value ); +static int Material_setSpecShader( BPy_Material * self, PyObject * value ); +static int Material_setDiffuseShader( BPy_Material * self, PyObject * value ); +static int Material_setRoughness( BPy_Material * self, PyObject * value ); +static int Material_setSpecSize( BPy_Material * self, PyObject * value ); +static int Material_setDiffuseSize( BPy_Material * self, PyObject * value ); +static int Material_setSpecSmooth( BPy_Material * self, PyObject * value ); +static int Material_setDiffuseSmooth( BPy_Material * self, PyObject * value ); +static int Material_setDiffuseDarkness( BPy_Material * self, PyObject * value ); +static int Material_setRefracIndex( BPy_Material * self, PyObject * value ); +static int Material_setRms( BPy_Material * self, PyObject * value ); +static int Material_setFilter( BPy_Material * self, PyObject * value ); +static int Material_setTranslucency( BPy_Material * self, PyObject * value ); + +static PyObject *Material_getColorComponent( BPy_Material * self, + void * closure ); +static PyObject *Material_getOopsLoc( BPy_Material * self ); +static PyObject *Material_getOopsSel( BPy_Material * self ); +static PyObject *Material_getUsers( BPy_Material * self ); + /*****************************************************************************/ /* Python BPy_Material methods declarations: */ /*****************************************************************************/ @@ -533,74 +568,11 @@ static PyObject *Material_getFresnelTransFac( BPy_Material * self ); static PyObject *Material_getFilter( BPy_Material * self ); static PyObject *Material_getTranslucency( BPy_Material * self ); static PyObject *Material_getTextures( BPy_Material * self ); -static PyObject *Material_setIpo( BPy_Material * self, PyObject * args ); static PyObject *Material_clearIpo( BPy_Material * self ); -static PyObject *Material_setName( BPy_Material * self, PyObject * args ); -static PyObject *Material_setMode( BPy_Material * self, PyObject * args ); -static PyObject *Material_setIntMode( BPy_Material * self, PyObject * args ); -static PyObject *Material_setRGBCol( BPy_Material * self, PyObject * args ); -/*static PyObject *Material_setAmbCol(BPy_Material *self, PyObject *args);*/ -static PyObject *Material_setSpecCol( BPy_Material * self, PyObject * args ); -static PyObject *Material_setMirCol( BPy_Material * self, PyObject * args ); -static PyObject *Material_setAmb( BPy_Material * self, PyObject * args ); -static PyObject *Material_setEmit( BPy_Material * self, PyObject * args ); -static PyObject *Material_setAlpha( BPy_Material * self, PyObject * args ); -static PyObject *Material_setRef( BPy_Material * self, PyObject * args ); -static PyObject *Material_setSpec( BPy_Material * self, PyObject * args ); -static PyObject *Material_setSpecTransp( BPy_Material * self, - PyObject * args ); -static PyObject *Material_setAdd( BPy_Material * self, PyObject * args ); -static PyObject *Material_setZOffset( BPy_Material * self, PyObject * args ); -static PyObject *Material_setHaloSize( BPy_Material * self, PyObject * args ); -static PyObject *Material_setHaloSeed( BPy_Material * self, PyObject * args ); -static PyObject *Material_setFlareSize( BPy_Material * self, PyObject * args ); -static PyObject *Material_setFlareSeed( BPy_Material * self, PyObject * args ); -static PyObject *Material_setFlareBoost( BPy_Material * self, - PyObject * args ); -static PyObject *Material_setSubSize( BPy_Material * self, PyObject * args ); -static PyObject *Material_setHardness( BPy_Material * self, PyObject * args ); -static PyObject *Material_setNFlares( BPy_Material * self, PyObject * args ); -static PyObject *Material_setNStars( BPy_Material * self, PyObject * args ); -static PyObject *Material_setNLines( BPy_Material * self, PyObject * args ); -static PyObject *Material_setNRings( BPy_Material * self, PyObject * args ); - -/* Shader */ -static PyObject *Material_setSpecShader( BPy_Material * self, PyObject * args ); -static PyObject *Material_setDiffuseShader( BPy_Material * self, PyObject * args ); -static PyObject *Material_setRoughness( BPy_Material * self, PyObject * args ); -static PyObject *Material_setSpecSize( BPy_Material * self, PyObject * args ); -static PyObject *Material_setDiffuseSize( BPy_Material * self, PyObject * args ); -static PyObject *Material_setSpecSmooth( BPy_Material * self, PyObject * args ); -static PyObject *Material_setDiffuseSmooth( BPy_Material * self, PyObject * args ); -static PyObject *Material_setDiffuseDarkness( BPy_Material * self, PyObject * args ); -static PyObject *Material_setRefracIndex( BPy_Material * self, PyObject * args ); -static PyObject *Material_setRms( BPy_Material * self, PyObject * args ); - -/* ** Mirror and transp ** */ -static PyObject *Material_setRayMirr( BPy_Material * self, PyObject * args ); -static PyObject *Material_setMirrDepth( BPy_Material * self, PyObject * args ); -static PyObject *Material_setFresnelMirr( BPy_Material * self, - PyObject * args ); -static PyObject *Material_setFresnelMirrFac( BPy_Material * self, - PyObject * args ); -static PyObject *Material_setFilter( BPy_Material * self, - PyObject * args ); -static PyObject *Material_setTranslucency( BPy_Material * self, - PyObject * args ); -static PyObject *Material_setIOR( BPy_Material * self, PyObject * args ); -static PyObject *Material_setTransDepth( BPy_Material * self, - PyObject * args ); -static PyObject *Material_setFresnelTrans( BPy_Material * self, - PyObject * args ); -static PyObject *Material_setFresnelTransFac( BPy_Material * self, - PyObject * args ); -/* ** */ + static PyObject *Material_setTexture( BPy_Material * self, PyObject * args ); static PyObject *Material_clearTexture( BPy_Material * self, PyObject * args ); -static PyObject *Material_setColorComponent( BPy_Material * self, char *key, - PyObject * args ); - static PyObject *Material_getScriptLinks(BPy_Material *self, PyObject * args ); static PyObject *Material_addScriptLink(BPy_Material * self, PyObject * args ); static PyObject *Material_clearScriptLinks(BPy_Material *self, PyObject *args); @@ -692,138 +664,126 @@ static PyMethodDef BPy_Material_methods[] = { "() - Return mount mirror"}, {"getMirrDepth", ( PyCFunction ) Material_getMirrDepth, METH_NOARGS, "() - Return amount mirror depth"}, - {"getFresnelMirr", ( PyCFunction ) Material_getFresnelMirr, - METH_NOARGS, + {"getFresnelMirr", ( PyCFunction ) Material_getFresnelMirr, METH_NOARGS, "() - Return fresnel power for refractions"}, - {"getFresnelMirrFac", ( PyCFunction ) Material_getFresnelMirrFac, - METH_NOARGS, + {"getFresnelMirrFac", ( PyCFunction ) Material_getFresnelMirrFac, METH_NOARGS, "() - Return fresnel power for refractions factor"}, - {"getFilter", ( PyCFunction ) Material_getFilter, - METH_NOARGS, + {"getFilter", ( PyCFunction ) Material_getFilter, METH_NOARGS, "() - Return the amount of filtering when transparent raytrace is enabled"}, - {"getTranslucency", ( PyCFunction ) Material_getTranslucency, - METH_NOARGS, + {"getTranslucency", ( PyCFunction ) Material_getTranslucency, METH_NOARGS, "() - Return the Translucency, the amount of diffuse shading of the back side"}, {"getIOR", ( PyCFunction ) Material_getIOR, METH_NOARGS, "() - Return IOR"}, {"getTransDepth", ( PyCFunction ) Material_getTransDepth, METH_NOARGS, "() - Return amount inter-refractions"}, - {"getFresnelTrans", ( PyCFunction ) Material_getFresnelTrans, - METH_NOARGS, + {"getFresnelTrans", ( PyCFunction ) Material_getFresnelTrans, METH_NOARGS, "() - Return fresnel power for refractions"}, - {"getFresnelTransFac", ( PyCFunction ) Material_getFresnelTransFac, - METH_NOARGS, + {"getFresnelTransFac", ( PyCFunction ) Material_getFresnelTransFac, METH_NOARGS, "() - Return fresnel power for refractions factor"}, {"getTextures", ( PyCFunction ) Material_getTextures, METH_NOARGS, "() - Return Material's texture list as a tuple"}, - {"setName", ( PyCFunction ) Material_setName, METH_VARARGS, + {"setName", ( PyCFunction ) Matr_oldsetName, METH_VARARGS, "(s) - Change Material's name"}, - {"setIpo", ( PyCFunction ) Material_setIpo, METH_VARARGS, + {"setIpo", ( PyCFunction ) Matr_oldsetIpo, METH_VARARGS, "(Blender Ipo) - Change Material's Ipo"}, {"clearIpo", ( PyCFunction ) Material_clearIpo, METH_NOARGS, "(Blender Ipo) - Unlink Ipo from this Material"}, {"insertIpoKey", ( PyCFunction ) Material_insertIpoKey, METH_VARARGS, "(Material Ipo Constant) - Insert IPO Key at current frame"}, - {"setMode", ( PyCFunction ) Material_setMode, METH_VARARGS, + {"setMode", ( PyCFunction ) Matr_oldsetMode, METH_VARARGS, "([s[,s]]) - Set Material's mode flag(s)"}, - {"setRGBCol", ( PyCFunction ) Material_setRGBCol, METH_VARARGS, + {"setRGBCol", ( PyCFunction ) Matr_oldsetRGBCol, METH_VARARGS, "(f,f,f or [f,f,f]) - Set Material's rgb color triplet"}, -/* {"setAmbCol", (PyCFunction)Material_setAmbCol, METH_VARARGS, +/* {"setAmbCol", (PyCFunction)Matr_oldsetAmbCol, METH_VARARGS, "(f,f,f or [f,f,f]) - Set Material's ambient color"},*/ - {"setSpecCol", ( PyCFunction ) Material_setSpecCol, METH_VARARGS, + {"setSpecCol", ( PyCFunction ) Matr_oldsetSpecCol, METH_VARARGS, "(f,f,f or [f,f,f]) - Set Material's specular color"}, /* Shader spesific settings */ - {"setSpecShader", ( PyCFunction ) Material_setSpecShader, METH_VARARGS, + {"setSpecShader", ( PyCFunction ) Matr_oldsetSpecShader, METH_VARARGS, "(i) - Set the Material's specular shader" }, - {"setDiffuseShader", ( PyCFunction ) Material_setDiffuseShader, METH_VARARGS, + {"setDiffuseShader", ( PyCFunction ) Matr_oldsetDiffuseShader, METH_VARARGS, "(i) - Set the Material's diffuse shader" }, - {"setRoughness", ( PyCFunction ) Material_setRoughness, METH_VARARGS, + {"setRoughness", ( PyCFunction ) Matr_oldsetRoughness, METH_VARARGS, "(f) - Set the Material's Roughness (applies to the \"Oren Nayar\" Diffuse Shader only)" }, - {"setSpecSize", ( PyCFunction ) Material_setSpecSize, METH_VARARGS, + {"setSpecSize", ( PyCFunction ) Matr_oldsetSpecSize, METH_VARARGS, "(f) - Set the Material's size of specular area (applies to the \"Toon\" Specular Shader only)" }, - {"setDiffuseSize", ( PyCFunction ) Material_setDiffuseSize, METH_VARARGS, + {"setDiffuseSize", ( PyCFunction ) Matr_oldsetDiffuseSize, METH_VARARGS, "(f) - Set the Material's size of diffuse area (applies to the \"Toon\" Diffuse Shader only)" }, - {"setSpecSmooth", ( PyCFunction ) Material_setSpecSmooth, METH_VARARGS, + {"setSpecSmooth", ( PyCFunction ) Matr_oldsetSpecSmooth, METH_VARARGS, "(f) - Set the Material's smoothing of specular area (applies to the \"Toon\" Specular Shader only)" }, - {"setDiffuseSmooth", ( PyCFunction ) Material_setDiffuseSmooth, METH_VARARGS, + {"setDiffuseSmooth", ( PyCFunction ) Matr_oldsetDiffuseSmooth, METH_VARARGS, "(f) - Set the Material's smoothing of diffuse area (applies to the \"Toon\" Diffuse Shader only)" }, - {"setDiffuseDarkness", ( PyCFunction ) Material_setDiffuseDarkness, METH_VARARGS, + {"setDiffuseDarkness", ( PyCFunction ) Matr_oldsetDiffuseDarkness, METH_VARARGS, "(f) - Set the Material's diffuse darkness (applies to the \"Minnaert\" Diffuse Shader only)" }, - {"setRefracIndex", ( PyCFunction ) Material_setRefracIndex, METH_VARARGS, + {"setRefracIndex", ( PyCFunction ) Matr_oldsetRefracIndex, METH_VARARGS, "(f) - Set the Material's Index of Refraction (applies to the \"Blinn\" Specular Shader only)" }, - {"setRms", ( PyCFunction ) Material_setRms, METH_VARARGS, + {"setRms", ( PyCFunction ) Matr_oldsetRms, METH_VARARGS, "(f) - Set the Material's standard deviation of surface slope (applies to the \"WardIso\" Specular Shader only)" }, /* End shader settings */ - {"setMirCol", ( PyCFunction ) Material_setMirCol, METH_VARARGS, + {"setMirCol", ( PyCFunction ) Matr_oldsetMirCol, METH_VARARGS, "(f,f,f or [f,f,f]) - Set Material's mirror color"}, - {"setAmb", ( PyCFunction ) Material_setAmb, METH_VARARGS, + {"setAmb", ( PyCFunction ) Matr_oldsetAmb, METH_VARARGS, "(f) - Set how much the Material's color is affected" " by \nthe global ambient colors - [0.0, 1.0]"}, - {"setEmit", ( PyCFunction ) Material_setEmit, METH_VARARGS, + {"setEmit", ( PyCFunction ) Matr_oldsetEmit, METH_VARARGS, "(f) - Set Material's emitting light intensity - [0.0, 1.0]"}, - {"setAlpha", ( PyCFunction ) Material_setAlpha, METH_VARARGS, + {"setAlpha", ( PyCFunction ) Matr_oldsetAlpha, METH_VARARGS, "(f) - Set Material's alpha (transparency) - [0.0, 1.0]"}, - {"setRef", ( PyCFunction ) Material_setRef, METH_VARARGS, + {"setRef", ( PyCFunction ) Matr_oldsetRef, METH_VARARGS, "(f) - Set Material's reflectivity - [0.0, 1.0]"}, - {"setSpec", ( PyCFunction ) Material_setSpec, METH_VARARGS, + {"setSpec", ( PyCFunction ) Matr_oldsetSpec, METH_VARARGS, "(f) - Set Material's specularity - [0.0, 2.0]"}, - {"setSpecTransp", ( PyCFunction ) Material_setSpecTransp, METH_VARARGS, + {"setSpecTransp", ( PyCFunction ) Matr_oldsetSpecTransp, METH_VARARGS, "(f) - Set Material's specular transparency - [0.0, 1.0]"}, - {"setAdd", ( PyCFunction ) Material_setAdd, METH_VARARGS, + {"setAdd", ( PyCFunction ) Matr_oldsetAdd, METH_VARARGS, "(f) - Set Material's glow factor - [0.0, 1.0]"}, - {"setZOffset", ( PyCFunction ) Material_setZOffset, METH_VARARGS, + {"setZOffset", ( PyCFunction ) Matr_oldsetZOffset, METH_VARARGS, "(f) - Set Material's artificial offset - [0.0, 10.0]"}, - {"setHaloSize", ( PyCFunction ) Material_setHaloSize, METH_VARARGS, + {"setHaloSize", ( PyCFunction ) Matr_oldsetHaloSize, METH_VARARGS, "(f) - Set Material's halo size - [0.0, 100.0]"}, - {"setHaloSeed", ( PyCFunction ) Material_setHaloSeed, METH_VARARGS, + {"setHaloSeed", ( PyCFunction ) Matr_oldsetHaloSeed, METH_VARARGS, "(i) - Set Material's halo seed - [0, 255]"}, - {"setFlareSize", ( PyCFunction ) Material_setFlareSize, METH_VARARGS, + {"setFlareSize", ( PyCFunction ) Matr_oldsetFlareSize, METH_VARARGS, "(f) - Set Material's factor: (flare size)/(halo size) - [0.1, 25.0]"}, - {"setFlareSeed", ( PyCFunction ) Material_setFlareSeed, METH_VARARGS, + {"setFlareSeed", ( PyCFunction ) Matr_oldsetFlareSeed, METH_VARARGS, "(i) - Set Material's flare seed - [0, 255]"}, - {"setFlareBoost", ( PyCFunction ) Material_setFlareBoost, METH_VARARGS, + {"setFlareBoost", ( PyCFunction ) Matr_oldsetFlareBoost, METH_VARARGS, "(f) - Set Material's flare boost - [0.1, 10.0]"}, - {"setSubSize", ( PyCFunction ) Material_setSubSize, METH_VARARGS, + {"setSubSize", ( PyCFunction ) Matr_oldsetSubSize, METH_VARARGS, "(f) - Set Material's dimension of subflare," " dots and circles - [0.1, 25.0]"}, - {"setHardness", ( PyCFunction ) Material_setHardness, METH_VARARGS, + {"setHardness", ( PyCFunction ) Matr_oldsetHardness, METH_VARARGS, "(i) - Set Material's hardness - [1, 255 (127 if halo mode is ON)]"}, - {"setNFlares", ( PyCFunction ) Material_setNFlares, METH_VARARGS, + {"setNFlares", ( PyCFunction ) Matr_oldsetNFlares, METH_VARARGS, "(i) - Set Material's number of flares in halo - [1, 32]"}, - {"setNStars", ( PyCFunction ) Material_setNStars, METH_VARARGS, + {"setNStars", ( PyCFunction ) Matr_oldsetNStars, METH_VARARGS, "(i) - Set Material's number of stars in halo - [3, 50]"}, - {"setNLines", ( PyCFunction ) Material_setNLines, METH_VARARGS, + {"setNLines", ( PyCFunction ) Matr_oldsetNLines, METH_VARARGS, "(i) - Set Material's number of lines in halo - [0, 250]"}, - {"setNRings", ( PyCFunction ) Material_setNRings, METH_VARARGS, + {"setNRings", ( PyCFunction ) Matr_oldsetNRings, METH_VARARGS, "(i) - Set Material's number of rings in halo - [0, 24]"}, - {"setRayMirr", ( PyCFunction ) Material_setRayMirr, METH_VARARGS, + {"setRayMirr", ( PyCFunction ) Matr_oldsetRayMirr, METH_VARARGS, "(f) - Set amount mirror - [0.0, 1.0]"}, - {"setMirrDepth", ( PyCFunction ) Material_setMirrDepth, METH_VARARGS, + {"setMirrDepth", ( PyCFunction ) Matr_oldsetMirrDepth, METH_VARARGS, "(i) - Set amount inter-reflections - [0, 10]"}, - {"setFresnelMirr", ( PyCFunction ) Material_setFresnelMirr, - METH_VARARGS, + {"setFresnelMirr", ( PyCFunction ) Matr_oldsetFresnelMirr, METH_VARARGS, "(f) - Set fresnel power for mirror - [0.0, 5.0]"}, - {"setFresnelMirrFac", ( PyCFunction ) Material_setFresnelMirrFac, - METH_VARARGS, + {"setFresnelMirrFac", ( PyCFunction ) Matr_oldsetFresnelMirrFac, METH_VARARGS, "(f) - Set blend fac for mirror fresnel - [1.0, 5.0]"}, - {"setFilter", ( PyCFunction ) Material_setFilter, - METH_VARARGS, + {"setFilter", ( PyCFunction ) Matr_oldsetFilter, METH_VARARGS, "(f) - Set the amount of filtering when transparent raytrace is enabled"}, - {"setTranslucency", ( PyCFunction ) Material_setTranslucency, - METH_VARARGS, + {"setTranslucency", ( PyCFunction ) Matr_oldsetTranslucency, METH_VARARGS, "(f) - Set the Translucency, the amount of diffuse shading of the back side"}, - {"setIOR", ( PyCFunction ) Material_setIOR, METH_VARARGS, + {"setIOR", ( PyCFunction ) Matr_oldsetIOR, METH_VARARGS, "(f) - Set IOR - [1.0, 3.0]"}, - {"setTransDepth", ( PyCFunction ) Material_setTransDepth, METH_VARARGS, + {"setTransDepth", ( PyCFunction ) Matr_oldsetTransDepth, METH_VARARGS, "(i) - Set amount inter-refractions - [0, 10]"}, - {"setFresnelTrans", ( PyCFunction ) Material_setFresnelTrans, - METH_VARARGS, + {"setFresnelTrans", ( PyCFunction ) Matr_oldsetFresnelTrans, METH_VARARGS, "(f) - Set fresnel power for refractions - [0.0, 5.0]"}, - {"setFresnelTransFac", ( PyCFunction ) Material_setFresnelTransFac, - METH_VARARGS, - "(f) - Set fresnel power for refractions factot- [0.0, 5.0]"}, + {"setFresnelTransFac", ( PyCFunction ) Matr_oldsetFresnelTransFac, METH_VARARGS, + "(f) - Set fresnel power for refractions factor- [0.0, 5.0]"}, {"setTexture", ( PyCFunction ) Material_setTexture, METH_VARARGS, "(n,tex,texco=0,mapto=0) - Set numbered texture to tex"}, {"clearTexture", ( PyCFunction ) Material_clearTexture, METH_VARARGS, @@ -837,47 +797,337 @@ static PyMethodDef BPy_Material_methods[] = { "(text, evt) - Add a new material scriptlink.\n" "(text) - string: an existing Blender Text name;\n" "(evt) string: FrameChanged, Redraw or Render."}, - {"clearScriptLinks", ( PyCFunction ) Material_clearScriptLinks, - METH_VARARGS, + {"clearScriptLinks", ( PyCFunction ) Material_clearScriptLinks, METH_VARARGS, "() - Delete all scriptlinks from this material.\n" "([s1<,s2,s3...>]) - Delete specified scriptlinks from this material."}, {NULL, NULL, 0, NULL} }; /*****************************************************************************/ +/* Python attributes get/set structure: */ +/*****************************************************************************/ + +static PyGetSetDef BPy_Material_getseters[] = { + {"add", + (getter)Material_getAdd, (setter)Material_setAdd, + "Strength of the add effect", + NULL}, + {"alpha", + (getter)Material_getAlpha, (setter)Material_setAlpha, + "Alpha setting ", + NULL}, + {"amb", + (getter)Material_getAmb, (setter)Material_setAmb, + "Amount of global ambient color material receives", + NULL}, + {"diffuseDarkness", + (getter)Material_getDiffuseDarkness, (setter)Material_setDiffuseDarkness, + "Material's diffuse darkness (\"Minnaert\" diffuse shader only)", + NULL}, + {"diffuseShader", + (getter)Material_getDiffuseShader, (setter)Material_setDiffuseShader, + "Diffuse shader type", + NULL}, + {"diffuseSize", + (getter)Material_getDiffuseSize, (setter)Material_setDiffuseSize, + "Material's diffuse area size (\"Toon\" diffuse shader only)", + NULL}, + {"diffuseSmooth", + (getter)Material_getDiffuseSmooth, (setter)Material_setDiffuseSmooth, + "Material's diffuse area smoothing (\"Toon\" diffuse shader only)", + NULL}, + {"emit", + (getter)Material_getEmit, (setter)Material_setEmit, + "Amount of light the material emits", + NULL}, + {"filter", + (getter)Material_getFilter, (setter)Material_setFilter, + "Amount of filtering when transparent raytrace is enabled", + NULL}, + {"flareBoost", + (getter)Material_getFlareBoost, (setter)Material_setFlareBoost, + "Flare's extra strength", + NULL}, + {"flareSeed", + (getter)Material_getFlareSeed, (setter)Material_setFlareSeed, + "Offset in the flare seed table", + NULL}, + {"flareSize", + (getter)Material_getFlareSize, (setter)Material_setFlareSize, + "Ratio of flare size to halo size", + NULL}, + {"fresnelDepth", + (getter)Material_getFresnelMirr, (setter)Material_setFresnelMirr, + "Power of Fresnel for mirror reflection", + NULL}, + {"fresnelDepthFac", + (getter)Material_getFresnelMirrFac, (setter)Material_setFresnelMirrFac, + "Blending factor for Fresnel mirror", + NULL}, + {"fresnelTrans", + (getter)Material_getFresnelTrans, (setter)Material_setFresnelTrans, + "Power of Fresnel for transparency", + NULL}, + {"fresnelTransFac", + (getter)Material_getFresnelTransFac, (setter)Material_setFresnelTransFac, + "Blending factor for Fresnel transparency", + NULL}, + {"haloSeed", + (getter)Material_getHaloSeed, (setter)Material_setHaloSeed, + "Randomizes halo ring dimension and line location", + NULL}, + {"haloSize", + (getter)Material_getHaloSize, (setter)Material_setHaloSize, + "Dimension of the halo", + NULL}, + {"hard", + (getter)Material_getHardness, (setter)Material_setHardness, + "Specularity hardness", + NULL}, + {"IOR", + (getter)Material_getIOR, (setter)Material_setIOR, + "Angular index of refraction for raytrace", + NULL}, + {"ipo", + (getter)Material_getIpo, (setter)Material_setIpo, + "Material Ipo data", + NULL}, + {"mirCol", + (getter)Material_getMirCol, (setter)Material_setMirCol, + "Mirror RGB color triplet", + NULL}, + {"mirR", + (getter)Material_getColorComponent, (setter)Material_setColorComponent, + "Mirror color red component", + (void *) EXPP_MAT_COMP_MIRR }, + {"mirG", + (getter)Material_getColorComponent, (setter)Material_setColorComponent, + "Mirror color green component", + (void *) EXPP_MAT_COMP_MIRG }, + {"mirB", + (getter)Material_getColorComponent, (setter)Material_setColorComponent, + "Mirror color blue component", + (void *) EXPP_MAT_COMP_MIRB }, + {"mode", + (getter)Material_getMode, (setter)Material_setMode, + "Material mode bitmask", + NULL}, + {"name", + (getter)Material_getName, (setter)Material_setName, + "Material data name", + NULL}, + {"nFlares", + (getter)Material_getNFlares, (setter)Material_setNFlares, + "Number of subflares with halo", + NULL}, + {"nLines", + (getter)Material_getNLines, (setter)Material_setNLines, + "Number of star-shaped lines with halo", + NULL}, + {"nRings", + (getter)Material_getNRings, (setter)Material_setNRings, + "Number of rings with halo", + NULL}, + {"nStars", + (getter)Material_getNStars, (setter)Material_setNStars, + "Number of star points with halo", + NULL}, + {"oopsLoc", + (getter)Material_getOopsLoc, (setter)Material_setOopsLoc, + "Material OOPs location", + NULL}, + {"oopsSel", + (getter)Material_getOopsSel, (setter)Material_setOopsSel, + "Material OOPs selection flag", + NULL}, + {"rayMirr", + (getter)Material_getRayMirr, (setter)Material_setRayMirr, + "Mirror reflection amount for raytrace", + NULL}, + {"rayMirrDepth", + (getter)Material_getMirrDepth, (setter)Material_setMirrDepth, + "Amount of raytrace inter-reflections", + NULL}, + {"ref", + (getter)Material_getRef, (setter)Material_setRef, + "Amount of reflections (for shader)", + NULL}, + {"refracIndex", + (getter)Material_getRefracIndex, (setter)Material_setRefracIndex, + "Material's Index of Refraction (applies to the \"Blinn\" Specular Shader only", + NULL}, + {"rgbCol", + (getter)Material_getRGBCol, (setter)Material_setRGBCol, + "Diffuse RGB color triplet", + NULL}, + {"rms", + (getter)Material_getRms, (setter)Material_setRms, + "Material's surface slope standard deviation (\"WardIso\" specular shader only)", + NULL}, + {"roughness", + (getter)Material_getRoughness, (setter)Material_setRoughness, + "Material's roughness (\"Oren Nayar\" diffuse shader only)", + NULL}, + {"spec", + (getter)Material_getSpec, (setter)Material_setSpec, + "Degree of specularity", + NULL}, + {"specCol", + (getter)Material_getSpecCol, (setter)Material_setSpecCol, + "Specular RGB color triplet", + NULL}, + {"specR", + (getter)Material_getColorComponent, (setter)Material_setColorComponent, + "Specular color red component", + (void *) EXPP_MAT_COMP_SPECR }, + {"specG", + (getter)Material_getColorComponent, (setter)Material_setColorComponent, + "Specular color green component", + (void *) EXPP_MAT_COMP_SPECG }, + {"specB", + (getter)Material_getColorComponent, (setter)Material_setColorComponent, + "Specular color blue component", + (void *) EXPP_MAT_COMP_SPECB }, + {"specTransp", + (getter)Material_getSpecTransp, (setter)Material_setSpecTransp, + "Makes specular areas opaque on transparent materials", + NULL}, + {"specShader", + (getter)Material_getSpecShader, (setter)Material_setSpecShader, + "Specular shader type", + NULL}, + {"specSize", + (getter)Material_getSpecSize, (setter)Material_setSpecSize, + "Material's specular area size (\"Toon\" specular shader only)", + NULL}, + {"specSmooth", + (getter)Material_getSpecSmooth, (setter)Material_setSpecSmooth, + "Sets the smoothness of specular toon area", + NULL}, + {"subSize", + (getter)Material_getSubSize, (setter)Material_setSubSize, + "Dimension of subflares, dots and circles", + NULL}, + {"transDepth", + (getter)Material_getTransDepth, (setter)Material_setTransDepth, + "Amount of refractions for raytrace", + NULL}, + {"translucency", + (getter)Material_getTranslucency, (setter)Material_setTranslucency, + "Amount of diffuse shading of the back side", + NULL}, + {"zOffset", + (getter)Material_getZOffset, (setter)Material_setZOffset, + "Artificial offset in the Z buffer (for Ztransp option)", + NULL}, + {"R", + (getter)Material_getColorComponent, (setter)Material_setColorComponent, + "Diffuse color red component", + (void *) EXPP_MAT_COMP_R }, + {"G", + (getter)Material_getColorComponent, (setter)Material_setColorComponent, + "Diffuse color green component", + (void *) EXPP_MAT_COMP_G }, + {"B", + (getter)Material_getColorComponent, (setter)Material_setColorComponent, + "Diffuse color blue component", + (void *) EXPP_MAT_COMP_B }, + {"users", + (getter)Material_getUsers, (setter)NULL, + "Number of material users", + NULL}, + {NULL,NULL,NULL,NULL,NULL} /* Sentinel */ +}; + +/*****************************************************************************/ /* Python Material_Type callback function prototypes: */ /*****************************************************************************/ static void Material_dealloc( BPy_Material * self ); -static int Material_setAttr( BPy_Material * self, char *name, PyObject * v ); -static PyObject *Material_getAttr( BPy_Material * self, char *name ); static PyObject *Material_repr( BPy_Material * self ); /*****************************************************************************/ -/* Python Material_Type structure definition: */ +/* Python Material_Type structure definition: */ /*****************************************************************************/ PyTypeObject Material_Type = { - PyObject_HEAD_INIT( NULL ) - 0, /* ob_size */ - "Blender Material", /* tp_name */ - sizeof( BPy_Material ), /* tp_basicsize */ - 0, /* tp_itemsize */ - /* methods */ - ( destructor ) Material_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - ( getattrfunc ) Material_getAttr, /* tp_getattr */ - ( setattrfunc ) Material_setAttr, /* tp_setattr */ - 0, /* tp_compare */ - ( reprfunc ) Material_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_as_hash */ - 0, 0, 0, 0, 0, 0, - 0, /* tp_doc */ - 0, 0, 0, 0, 0, 0, - BPy_Material_methods, /* tp_methods */ - 0, /* tp_members */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* up to tp_del to avoid a warning */ + PyObject_HEAD_INIT( NULL ) /* required py macro */ + 0, /* ob_size */ + /* For printing, in format "<module>.<name>" */ + "Blender Material", /* char *tp_name; */ + sizeof( BPy_Material ), /* int tp_basicsize; */ + 0, /* tp_itemsize; For allocation */ + + /* Methods to implement standard operations */ + + ( destructor ) Material_dealloc,/* destructor tp_dealloc; */ + NULL, /* printfunc tp_print; */ + NULL, /* getattrfunc tp_getattr; */ + NULL, /* setattrfunc tp_setattr; */ + NULL, /* cmpfunc tp_compare; */ + ( reprfunc ) Material_repr, /* reprfunc tp_repr; */ + + /* Method suites for standard classes */ + + NULL, /* PyNumberMethods *tp_as_number; */ + NULL, /* PySequenceMethods *tp_as_sequence; */ + NULL, /* PyMappingMethods *tp_as_mapping; */ + + /* More standard operations (here for binary compatibility) */ + + NULL, /* hashfunc tp_hash; */ + NULL, /* ternaryfunc tp_call; */ + NULL, /* reprfunc tp_str; */ + NULL, /* getattrofunc tp_getattro; */ + NULL, /* setattrofunc tp_setattro; */ + + /* Functions to access object as input/output buffer */ + NULL, /* PyBufferProcs *tp_as_buffer; */ + + /*** Flags to define presence of optional/expanded features ***/ + Py_TPFLAGS_DEFAULT, /* long tp_flags; */ + + NULL, /* char *tp_doc; Documentation string */ + /*** Assigned meaning in release 2.0 ***/ + /* call function for all accessible objects */ + NULL, /* traverseproc tp_traverse; */ + + /* delete references to contained objects */ + NULL, /* inquiry tp_clear; */ + + /*** Assigned meaning in release 2.1 ***/ + /*** rich comparisons ***/ + NULL, /* richcmpfunc tp_richcompare; */ + + /*** weak reference enabler ***/ + 0, /* long tp_weaklistoffset; */ + + /*** Added in release 2.2 ***/ + /* Iterators */ + NULL, /* getiterfunc tp_iter; */ + NULL, /* iternextfunc tp_iternext; */ + + /*** Attribute descriptor and subclassing stuff ***/ + BPy_Material_methods, /* struct PyMethodDef *tp_methods; */ + NULL, /* struct PyMemberDef *tp_members; */ + BPy_Material_getseters, /* struct PyGetSetDef *tp_getset; */ + NULL, /* struct _typeobject *tp_base; */ + NULL, /* PyObject *tp_dict; */ + NULL, /* descrgetfunc tp_descr_get; */ + NULL, /* descrsetfunc tp_descr_set; */ + 0, /* long tp_dictoffset; */ + NULL, /* initproc tp_init; */ + NULL, /* allocfunc tp_alloc; */ + NULL, /* newfunc tp_new; */ + /* Low-level free-memory routine */ + NULL, /* freefunc tp_free; */ + /* For PyObject_IS_GC */ + NULL, /* inquiry tp_is_gc; */ + NULL, /* PyObject *tp_bases; */ + /* method resolution order */ + NULL, /* PyObject *tp_mro; */ + NULL, /* PyObject *tp_cache; */ + NULL, /* PyObject *tp_subclasses; */ + NULL, /* PyObject *tp_weaklist; */ + NULL }; /*****************************************************************************/ @@ -1513,59 +1763,56 @@ static PyObject *Material_getTextures( BPy_Material * self ) return tuple; } -PyObject *Material_setIpo( BPy_Material * self, PyObject * args ) +/* + * this should accept a Py_None argument and just delete the Ipo link + * (as Lamp_clearIpo() does) + */ + +static int Material_setIpo( BPy_Material * self, PyObject * value ) { - PyObject *pyipo = 0; Ipo *ipo = NULL; - Ipo *oldipo; + Ipo *oldipo = self->material->ipo; + ID *id; - if( !PyArg_ParseTuple( args, "O!", &Ipo_Type, &pyipo ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected Ipo as argument" ); + /* if parameter is not None, check for valid Ipo */ - ipo = Ipo_FromPyObject( pyipo ); + if ( value != Py_None ) { + if ( !Ipo_CheckPyObject( value ) ) + return EXPP_ReturnIntError( PyExc_RuntimeError, + "expected an Ipo object" ); - if( !ipo ) - return EXPP_ReturnPyObjError( PyExc_RuntimeError, - "null ipo!" ); + ipo = Ipo_FromPyObject( value ); - if( ipo->blocktype != ID_MA ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "this ipo is not a Material type ipo" ); + if( !ipo ) + return EXPP_ReturnIntError( PyExc_RuntimeError, + "null ipo!" ); - oldipo = self->material->ipo; - if( oldipo ) { - ID *id = &oldipo->id; - if( id->us > 0 ) - id->us--; + if( ipo->blocktype != ID_MA ) + return EXPP_ReturnIntError( PyExc_TypeError, + "Ipo is not a material data Ipo" ); } - ( ( ID * ) & ipo->id )->us++; - - self->material->ipo = ipo; - - Py_INCREF( Py_None ); - return Py_None; -} - -static PyObject *Material_clearIpo( BPy_Material * self ) -{ - Material *mat = self->material; - Ipo *ipo = ( Ipo * ) mat->ipo; + /* if already linked to Ipo, delete link */ - if( ipo ) { - ID *id = &ipo->id; + if ( oldipo ) { + id = &oldipo->id; if( id->us > 0 ) id->us--; - mat->ipo = NULL; + } - return EXPP_incr_ret_True(); + /* assign new Ipo and increment user count, or set to NULL if deleting */ + + self->material->ipo = ipo; + if ( ipo ) { + id = &ipo->id; + id->us++; } - return EXPP_incr_ret_False(); /* no ipo found */ + return 0; } + /* * Material_insertIpoKey( key ) * inserts Material IPO key at current frame @@ -1645,779 +1892,408 @@ static PyObject *Material_insertIpoKey( BPy_Material * self, PyObject * args ) return EXPP_incr_ret( Py_None ); } - -static PyObject *Material_setName( BPy_Material * self, PyObject * args ) +static int Material_setName( BPy_Material * self, PyObject * value ) { char *name; char buf[21]; - if( !PyArg_ParseTuple( args, "s", &name ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected string argument" ) ); + name = PyString_AsString ( value ); + if( !name ) + return EXPP_ReturnIntError( PyExc_TypeError, + "expected string argument" ); PyOS_snprintf( buf, sizeof( buf ), "%s", name ); rename_id( &self->material->id, buf ); - Py_INCREF( Py_None ); - return Py_None; -} - -/* Possible modes are traceable, shadow, shadeless, wire, vcolLight, - * vcolPaint, halo, ztransp, zinvert, haloRings, env, haloLines, - * onlyShadow, xalpha, star, faceTexture, haloTex, haloPuno, noMist, - * haloShaded, haloFlare */ -static PyObject *Material_setMode( BPy_Material * self, PyObject * args ) -{ - unsigned int i, flag = 0, ok = 0; - - char *m[28] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL - }; - - /* - * check for a single integer argument; do a quick check for now - * that the value is not larger than double the highest flag bit - */ - - if ( (PySequence_Size( args ) == 1) - && PyInt_Check ( PySequence_Fast_GET_ITEM ( args , 0 ) ) - && PyArg_ParseTuple( args, "i", &flag ) - && flag < (EXPP_MAT_MODE_RAYMIRROR >> 1) ) { - ok = 1; - - /* - * check for either an empty argument list, or up to 22 strings - */ - - } else if( PyArg_ParseTuple( args, "|ssssssssssssssssssssssssssss", - &m[0], &m[1], &m[2], &m[3], &m[4], &m[5], &m[6], - &m[7], &m[8], &m[9], &m[10], &m[11], &m[12], - &m[13], &m[14], &m[15], &m[16], &m[17], &m[18], - &m[19], &m[20], &m[21], &m[22], &m[23], &m[24], - &m[25], &m[26], &m[27] ) ) { - for( i = 0; i < 28; i++ ) { - if( m[i] == NULL ) - break; - if( strcmp( m[i], "Traceable" ) == 0 ) - flag |= EXPP_MAT_MODE_TRACEABLE; - else if( strcmp( m[i], "Shadow" ) == 0 ) - flag |= EXPP_MAT_MODE_SHADOW; - else if( strcmp( m[i], "Shadeless" ) == 0 ) - flag |= EXPP_MAT_MODE_SHADELESS; - else if( strcmp( m[i], "Wire" ) == 0 ) - flag |= EXPP_MAT_MODE_WIRE; - else if( strcmp( m[i], "VColLight" ) == 0 ) - flag |= EXPP_MAT_MODE_VCOL_LIGHT; - else if( strcmp( m[i], "VColPaint" ) == 0 ) - flag |= EXPP_MAT_MODE_VCOL_PAINT; - else if( strcmp( m[i], "Halo" ) == 0 ) - flag |= EXPP_MAT_MODE_HALO; - else if( strcmp( m[i], "ZTransp" ) == 0 ) - flag |= EXPP_MAT_MODE_ZTRANSP; - else if( strcmp( m[i], "ZInvert" ) == 0 ) - flag |= EXPP_MAT_MODE_ZINVERT; - else if( strcmp( m[i], "HaloRings" ) == 0 ) - flag |= EXPP_MAT_MODE_HALORINGS; - else if( strcmp( m[i], "HaloLines" ) == 0 ) - flag |= EXPP_MAT_MODE_HALOLINES; - else if( strcmp( m[i], "OnlyShadow" ) == 0 ) - flag |= EXPP_MAT_MODE_ONLYSHADOW; - else if( strcmp( m[i], "HaloXAlpha" ) == 0 ) - flag |= EXPP_MAT_MODE_HALOXALPHA; - else if( strcmp( m[i], "HaloStar" ) == 0 ) - flag |= EXPP_MAT_MODE_HALOSTAR; - else if( strcmp( m[i], "TexFace" ) == 0 ) - flag |= EXPP_MAT_MODE_TEXFACE; - else if( strcmp( m[i], "HaloTex" ) == 0 ) - flag |= EXPP_MAT_MODE_HALOTEX; - else if( strcmp( m[i], "HaloPuno" ) == 0 ) - flag |= EXPP_MAT_MODE_HALOPUNO; - else if( strcmp( m[i], "NoMist" ) == 0 ) - flag |= EXPP_MAT_MODE_NOMIST; - else if( strcmp( m[i], "HaloShaded" ) == 0 ) - flag |= EXPP_MAT_MODE_HALOSHADE; - else if( strcmp( m[i], "HaloFlare" ) == 0 ) - flag |= EXPP_MAT_MODE_HALOFLARE; - else if( strcmp( m[i], "Radio" ) == 0 ) - flag |= EXPP_MAT_MODE_RADIO; - /* ** Mirror ** */ - else if( strcmp( m[i], "RayMirr" ) == 0 ) - flag |= EXPP_MAT_MODE_RAYMIRROR; - else if( strcmp( m[i], "ZTransp" ) == 0 ) - flag |= EXPP_MAT_MODE_ZTRA; - else if( strcmp( m[i], "RayTransp" ) == 0 ) - flag |= EXPP_MAT_MODE_RAYTRANSP; - else if( strcmp( m[i], "OnlyShadow" ) == 0 ) - flag |= EXPP_MAT_MODE_ONLYSHADOW; - else if( strcmp( m[i], "NoMist" ) == 0 ) - flag |= EXPP_MAT_MODE_NOMIST; - else if( strcmp( m[i], "Env" ) == 0 ) - flag |= EXPP_MAT_MODE_ENV; - /* ** */ - else - return ( EXPP_ReturnPyObjError( PyExc_AttributeError, - "unknown Material mode argument" ) ); - } - ok = 1; + return 0; +} + +static int Material_setMode( BPy_Material * self, PyObject * value ) +{ + int param; + int bitmask = MA_TRACEBLE + | MA_SHADOW + | MA_SHLESS + | MA_WIRE + | MA_VERTEXCOL + | MA_VERTEXCOLP + | MA_HALO + | MA_ZTRA + | MA_ZINV + | MA_HALO_RINGS + | MA_HALO_LINES + | MA_ONLYSHADOW + | MA_HALO_XALPHA + | MA_STAR + | MA_FACETEXTURE + | MA_HALOTEX + | MA_HALOPUNO + | MA_NOMIST + | MA_HALO_SHADE + | MA_HALO_FLARE + | MA_RADIO + | MA_RAYMIRROR + | MA_ZTRA + | MA_RAYTRANSP + | MA_ONLYSHADOW + | MA_NOMIST + | MA_ENV; + + if( !PyInt_CheckExact ( value ) ) { + char errstr[128]; + sprintf ( errstr , "expected int bitmask of 0x%08x", bitmask ); + return EXPP_ReturnIntError( PyExc_TypeError, errstr ); } + param = PyInt_AS_LONG ( value ); - /* if neither input method worked, then throw an exception */ - - if ( ok == 0 ) - return ( EXPP_ReturnPyObjError - ( PyExc_AttributeError, - "expected nothing, an integer or up to 22 string argument(s)" ) ); - - /* update the mode flag, return None */ - - self->material->mode = flag; - - Py_INCREF( Py_None ); - return Py_None; -} - -/* Another helper function, for the same reason. - * (See comment before Material_setIntType above). */ -static PyObject *Material_setIntMode( BPy_Material * self, PyObject * args ) -{ - int value; - - if( !PyArg_ParseTuple( args, "i", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument" ) ); + if ( ( param & bitmask ) != param ) + return EXPP_ReturnIntError( PyExc_ValueError, + "invalid bit(s) set in mask" ); - self->material->mode = value; + self->material->mode = param; - Py_INCREF( Py_None ); - return Py_None; + return 0; } -static PyObject *Material_setRGBCol( BPy_Material * self, PyObject * args ) +static int Material_setRGBCol( BPy_Material * self, PyObject * value ) { - return rgbTuple_setCol( self->col, args ); + return rgbTuple_setCol( self->col, value ); } /* -static PyObject *Material_setAmbCol (BPy_Material *self, PyObject *args) +static PyObject *Material_setAmbCol (BPy_Material *self, PyObject * value ) { - return rgbTuple_setCol(self->amb, args); + return rgbTuple_setCol(self->amb, value); } */ -static PyObject *Material_setSpecCol( BPy_Material * self, PyObject * args ) + +static int Material_setSpecCol( BPy_Material * self, PyObject * value ) { - return rgbTuple_setCol( self->spec, args ); + return rgbTuple_setCol( self->spec, value ); } -static PyObject *Material_setMirCol( BPy_Material * self, PyObject * args ) +static int Material_setMirCol( BPy_Material * self, PyObject * value ) { - return rgbTuple_setCol( self->mir, args ); + return rgbTuple_setCol( self->mir, value ); } - -static PyObject *Material_setSpecShader( BPy_Material * self, PyObject * args ) +static int Material_setColorComponent( BPy_Material * self, PyObject * value, + void * closure ) { - int value; + float param; - if( !PyArg_ParseTuple( args, "i", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument" ) ); + if( !PyNumber_Check ( value ) ) + return EXPP_ReturnIntError( PyExc_TypeError, + "expected float argument in [0.0,1.0]" ); - self->material->spec_shader = (short)EXPP_ClampInt( value, EXPP_MAT_SPEC_SHADER_MIN, - EXPP_MAT_SPEC_SHADER_MAX ); - - Py_INCREF( Py_None ); - return Py_None; + param = PyFloat_AsDouble( value ); + param = EXPP_ClampFloat( param, EXPP_MAT_COL_MIN, EXPP_MAT_COL_MAX ); + + switch ( (int)closure ) { + case EXPP_MAT_COMP_R: + self->material->r = param; + return 0; + case EXPP_MAT_COMP_G: + self->material->g = param; + return 0; + case EXPP_MAT_COMP_B: + self->material->b = param; + return 0; + case EXPP_MAT_COMP_SPECR: + self->material->specr = param; + return 0; + case EXPP_MAT_COMP_SPECG: + self->material->specg = param; + return 0; + case EXPP_MAT_COMP_SPECB: + self->material->specb = param; + return 0; + case EXPP_MAT_COMP_MIRR: + self->material->mirr = param; + return 0; + case EXPP_MAT_COMP_MIRG: + self->material->mirg = param; + return 0; + case EXPP_MAT_COMP_MIRB: + self->material->mirb = param; + return 0; + } + return EXPP_ReturnIntError( PyExc_RuntimeError, + "unknown color component specified" ); } -static PyObject *Material_setDiffuseShader( BPy_Material * self, PyObject * args ) +static int Material_setAmb( BPy_Material * self, PyObject * value ) { - int value; - - if( !PyArg_ParseTuple( args, "i", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument" ) ); - - self->material->diff_shader = (short)EXPP_ClampInt( value, EXPP_MAT_DIFFUSE_SHADER_MIN, - EXPP_MAT_DIFFUSE_SHADER_MAX ); - - Py_INCREF( Py_None ); - return Py_None; + return EXPP_setFloatClamped ( value, &self->material->amb, + EXPP_MAT_AMB_MIN, + EXPP_MAT_AMB_MAX ); } - -static PyObject *Material_setRoughness( BPy_Material * self, PyObject * args ) +static int Material_setEmit( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 3.14]" ) ); - - self->material->roughness = EXPP_ClampFloat( value, EXPP_MAT_ROUGHNESS_MIN, - EXPP_MAT_ROUGHNESS_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->emit, + EXPP_MAT_EMIT_MIN, + EXPP_MAT_EMIT_MAX ); } - -static PyObject *Material_setSpecSize( BPy_Material * self, PyObject * args ) +static int Material_setSpecTransp( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 1.53]" ) ); - - self->material->param[2] = EXPP_ClampFloat( value, EXPP_MAT_SPECSIZE_MIN, - EXPP_MAT_SPECSIZE_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->spectra, + EXPP_MAT_SPECTRA_MIN, + EXPP_MAT_SPECTRA_MAX ); } - -static PyObject *Material_setDiffuseSize( BPy_Material * self, PyObject * args ) +static int Material_setAlpha( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 3.14]" ) ); - - self->material->param[0] = EXPP_ClampFloat( value, EXPP_MAT_DIFFUSESIZE_MIN, - EXPP_MAT_DIFFUSESIZE_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->alpha, + EXPP_MAT_ALPHA_MIN, + EXPP_MAT_ALPHA_MAX ); } - -static PyObject *Material_setSpecSmooth( BPy_Material * self, PyObject * args ) +static int Material_setRef( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 1.0]" ) ); - - self->material->param[3] = EXPP_ClampFloat( value, EXPP_MAT_SPECSMOOTH_MIN, - EXPP_MAT_SPECSMOOTH_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->ref, + EXPP_MAT_REF_MIN, + EXPP_MAT_REF_MAX ); } - -static PyObject *Material_setDiffuseSmooth( BPy_Material * self, PyObject * args ) +static int Material_setSpec( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 1.0]" ) ); - - self->material->param[1] = EXPP_ClampFloat( value, EXPP_MAT_DIFFUSESMOOTH_MIN, - EXPP_MAT_DIFFUSESMOOTH_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->spec, + EXPP_MAT_SPEC_MIN, + EXPP_MAT_SPEC_MAX ); } - -static PyObject *Material_setDiffuseDarkness( BPy_Material * self, PyObject * args ) +static int Material_setZOffset( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 2.0]" ) ); - - self->material->darkness = EXPP_ClampFloat( value, EXPP_MAT_DIFFUSE_DARKNESS_MIN, - EXPP_MAT_DIFFUSE_DARKNESS_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->zoffs, + EXPP_MAT_ZOFFS_MIN, + EXPP_MAT_ZOFFS_MAX ); } - -static PyObject *Material_setRefracIndex( BPy_Material * self, PyObject * args ) +static int Material_setAdd( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [1.0, 10.0]" ) ); - - self->material->refrac = EXPP_ClampFloat( value, EXPP_MAT_REFRACINDEX_MIN, - EXPP_MAT_REFRACINDEX_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->add, + EXPP_MAT_ADD_MIN, + EXPP_MAT_ADD_MAX ); } - -static PyObject *Material_setRms( BPy_Material * self, PyObject * args ) +static int Material_setHaloSize( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 0.4]" ) ); - - self->material->rms = EXPP_ClampFloat( value, EXPP_MAT_RMS_MIN, - EXPP_MAT_RMS_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->hasize, + EXPP_MAT_HALOSIZE_MIN, + EXPP_MAT_HALOSIZE_MAX ); } - -static PyObject *Material_setColorComponent( BPy_Material * self, char *key, - PyObject * args ) -{ /* for compatibility with old bpython */ - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 1.0]" ) ); - - value = EXPP_ClampFloat( value, EXPP_MAT_COL_MIN, EXPP_MAT_COL_MAX ); - - if( !strcmp( key, "R" ) ) - self->material->r = value; - else if( !strcmp( key, "G" ) ) - self->material->g = value; - else if( !strcmp( key, "B" ) ) - self->material->b = value; - else if( !strcmp( key, "specR" ) ) - self->material->specr = value; - else if( !strcmp( key, "specG" ) ) - self->material->specg = value; - else if( !strcmp( key, "specB" ) ) - self->material->specb = value; - - return EXPP_incr_ret( Py_None ); +static int Material_setFlareSize( BPy_Material * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->material->flaresize, + EXPP_MAT_FLARESIZE_MIN, + EXPP_MAT_FLARESIZE_MAX ); } -static PyObject *Material_setAmb( BPy_Material * self, PyObject * args ) +static int Material_setFlareBoost( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 1.0]" ) ); - - self->material->amb = EXPP_ClampFloat( value, EXPP_MAT_AMB_MIN, - EXPP_MAT_AMB_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->flareboost, + EXPP_MAT_FLAREBOOST_MIN, + EXPP_MAT_FLAREBOOST_MAX ); } -static PyObject *Material_setEmit( BPy_Material * self, PyObject * args ) +static int Material_setSubSize( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 1.0]" ) ); - - self->material->emit = EXPP_ClampFloat( value, EXPP_MAT_EMIT_MIN, - EXPP_MAT_EMIT_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->subsize, + EXPP_MAT_SUBSIZE_MIN, + EXPP_MAT_SUBSIZE_MAX ); } -static PyObject *Material_setSpecTransp( BPy_Material * self, PyObject * args ) +static int Material_setHaloSeed( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 1.0]" ) ); - - self->material->spectra = EXPP_ClampFloat( value, EXPP_MAT_SPECTRA_MIN, - EXPP_MAT_SPECTRA_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setIValueClamped ( value, &self->material->seed1, + EXPP_MAT_HALOSEED_MIN, + EXPP_MAT_HALOSEED_MAX, 'b' ); } -static PyObject *Material_setAlpha( BPy_Material * self, PyObject * args ) +static int Material_setFlareSeed( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 1.0]" ) ); - - self->material->alpha = EXPP_ClampFloat( value, EXPP_MAT_ALPHA_MIN, - EXPP_MAT_ALPHA_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setIValueClamped ( value, &self->material->seed2, + EXPP_MAT_FLARESEED_MIN, + EXPP_MAT_FLARESEED_MAX, 'b' ); } -static PyObject *Material_setRef( BPy_Material * self, PyObject * args ) +static int Material_setHardness( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 1.0]" ) ); - - self->material->ref = EXPP_ClampFloat( value, EXPP_MAT_REF_MIN, - EXPP_MAT_REF_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setIValueClamped ( value, &self->material->har, + EXPP_MAT_HARD_MIN, + EXPP_MAT_HARD_MAX, 'h' ); } -static PyObject *Material_setSpec( BPy_Material * self, PyObject * args ) +static int Material_setNFlares( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 2.0]" ) ); - - self->material->spec = EXPP_ClampFloat( value, EXPP_MAT_SPEC_MIN, - EXPP_MAT_SPEC_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setIValueClamped ( value, &self->material->flarec, + EXPP_MAT_NFLARES_MIN, + EXPP_MAT_NFLARES_MAX, 'h' ); } -static PyObject *Material_setZOffset( BPy_Material * self, PyObject * args ) +static int Material_setNStars( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 10.0]" ) ); - - self->material->zoffs = EXPP_ClampFloat( value, EXPP_MAT_ZOFFS_MIN, - EXPP_MAT_ZOFFS_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setIValueClamped ( value, &self->material->starc, + EXPP_MAT_NSTARS_MIN, + EXPP_MAT_NSTARS_MAX, 'h' ); } -static PyObject *Material_setAdd( BPy_Material * self, PyObject * args ) +static int Material_setNLines( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 1.0]" ) ); - - self->material->add = EXPP_ClampFloat( value, EXPP_MAT_ADD_MIN, - EXPP_MAT_ADD_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setIValueClamped ( value, &self->material->linec, + EXPP_MAT_NLINES_MIN, + EXPP_MAT_NLINES_MAX, 'h' ); } -static PyObject *Material_setHaloSize( BPy_Material * self, PyObject * args ) +static int Material_setNRings( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 100.0]" ) ); - - self->material->hasize = EXPP_ClampFloat( value, EXPP_MAT_HALOSIZE_MIN, - EXPP_MAT_HALOSIZE_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setIValueClamped ( value, &self->material->ringc, + EXPP_MAT_NRINGS_MIN, + EXPP_MAT_NRINGS_MAX, 'h' ); } -static PyObject *Material_setFlareSize( BPy_Material * self, PyObject * args ) +static int Material_setRayMirr( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.1, 25.0]" ) ); - - self->material->flaresize = - EXPP_ClampFloat( value, EXPP_MAT_FLARESIZE_MIN, - EXPP_MAT_FLARESIZE_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->ray_mirror, + EXPP_MAT_RAYMIRR_MIN, + EXPP_MAT_RAYMIRR_MAX ); } -static PyObject *Material_setFlareBoost( BPy_Material * self, PyObject * args ) +static int Material_setMirrDepth( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.1, 10.0]" ) ); - - self->material->flareboost = - EXPP_ClampFloat( value, EXPP_MAT_FLAREBOOST_MIN, - EXPP_MAT_FLAREBOOST_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setIValueClamped ( value, &self->material->ray_depth, + EXPP_MAT_MIRRDEPTH_MIN, + EXPP_MAT_MIRRDEPTH_MAX, 'h' ); } -static PyObject *Material_setSubSize( BPy_Material * self, PyObject * args ) +static int Material_setFresnelMirr( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.1, 25.0]" ) ); - - self->material->subsize = EXPP_ClampFloat( value, EXPP_MAT_SUBSIZE_MIN, - EXPP_MAT_SUBSIZE_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->fresnel_mir, + EXPP_MAT_FRESNELMIRR_MIN, + EXPP_MAT_FRESNELMIRR_MAX ); } -static PyObject *Material_setHaloSeed( BPy_Material * self, PyObject * args ) +static int Material_setFresnelMirrFac( BPy_Material * self, PyObject * value ) { - short value; - - if( !PyArg_ParseTuple( args, "h", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument in [1, 255]" ) ); - - self->material->seed1 = (char)EXPP_ClampInt( value, EXPP_MAT_HALOSEED_MIN, - EXPP_MAT_HALOSEED_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->fresnel_mir_i, + EXPP_MAT_FRESNELMIRRFAC_MIN, + EXPP_MAT_FRESNELMIRRFAC_MAX ); } -static PyObject *Material_setFlareSeed( BPy_Material * self, PyObject * args ) +static int Material_setIOR( BPy_Material * self, PyObject * value ) { - short value; - - if( !PyArg_ParseTuple( args, "h", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument in [1, 255]" ) ); - - self->material->seed2 = (char)EXPP_ClampInt( value, EXPP_MAT_FLARESEED_MIN, - EXPP_MAT_FLARESEED_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->ang, + EXPP_MAT_IOR_MIN, + EXPP_MAT_IOR_MAX ); } - -static PyObject *Material_setHardness( BPy_Material * self, PyObject * args ) +static int Material_setTransDepth( BPy_Material * self, PyObject * value ) { - short value; - - if( !PyArg_ParseTuple( args, "h", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument in [1, 255]" ) ); - - self->material->har = (short)EXPP_ClampInt( value, EXPP_MAT_HARD_MIN, - EXPP_MAT_HARD_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setIValueClamped ( value, &self->material->ray_depth_tra, + EXPP_MAT_TRANSDEPTH_MIN, + EXPP_MAT_TRANSDEPTH_MAX, 'h' ); } -static PyObject *Material_setNFlares( BPy_Material * self, PyObject * args ) +static int Material_setFresnelTrans( BPy_Material * self, PyObject * value ) { - short value; - - if( !PyArg_ParseTuple( args, "h", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument in [1, 32]" ) ); - - self->material->flarec = (short)EXPP_ClampInt( value, EXPP_MAT_NFLARES_MIN, - EXPP_MAT_NFLARES_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->fresnel_tra, + EXPP_MAT_FRESNELTRANS_MIN, + EXPP_MAT_FRESNELTRANS_MAX ); } -static PyObject *Material_setNStars( BPy_Material * self, PyObject * args ) +static int Material_setFresnelTransFac( BPy_Material * self, PyObject * value ) { - short value; - - if( !PyArg_ParseTuple( args, "h", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument in [3, 50]" ) ); - - self->material->starc = (short)EXPP_ClampInt( value, EXPP_MAT_NSTARS_MIN, - EXPP_MAT_NSTARS_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->fresnel_tra_i, + EXPP_MAT_FRESNELTRANSFAC_MIN, + EXPP_MAT_FRESNELTRANSFAC_MAX ); } -static PyObject *Material_setNLines( BPy_Material * self, PyObject * args ) +static int Material_setSpecShader( BPy_Material * self, PyObject * value ) { - short value; - - if( !PyArg_ParseTuple( args, "h", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument in [0, 250]" ) ); - - self->material->linec = (short)EXPP_ClampInt( value, EXPP_MAT_NLINES_MIN, - EXPP_MAT_NLINES_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setIValueRange( value, &self->material->spec_shader, + MA_SPEC_COOKTORR, + MA_SPEC_WARDISO, 'h' ); } -static PyObject *Material_setNRings( BPy_Material * self, PyObject * args ) +static int Material_setDiffuseShader( BPy_Material * self, PyObject * value ) { - short value; - - if( !PyArg_ParseTuple( args, "h", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument in [0, 24]" ) ); - - self->material->ringc = (short)EXPP_ClampInt( value, EXPP_MAT_NRINGS_MIN, - EXPP_MAT_NRINGS_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setIValueRange( value, &self->material->diff_shader, + MA_DIFF_LAMBERT, + MA_DIFF_MINNAERT, 'h' ); } -static PyObject *Material_setRayMirr( BPy_Material * self, PyObject * args ) +static int Material_setRoughness( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 1.0]" ) ); - - self->material->ray_mirror = - EXPP_ClampFloat( value, EXPP_MAT_RAYMIRR_MIN, - EXPP_MAT_RAYMIRR_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->roughness, + EXPP_MAT_ROUGHNESS_MIN, + EXPP_MAT_ROUGHNESS_MAX ); } -static PyObject *Material_setMirrDepth( BPy_Material * self, PyObject * args ) +static int Material_setSpecSize( BPy_Material * self, PyObject * value ) { - int value; - - if( !PyArg_ParseTuple( args, "i", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0, 10]" ) ); - - self->material->ray_depth = - (short)EXPP_ClampInt( value, EXPP_MAT_MIRRDEPTH_MIN, - EXPP_MAT_MIRRDEPTH_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->param[2], + EXPP_MAT_SPECSIZE_MIN, + EXPP_MAT_SPECSIZE_MAX ); } -static PyObject *Material_setFresnelMirr( BPy_Material * self, - PyObject * args ) +static int Material_setDiffuseSize( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 5.0]" ) ); - - self->material->fresnel_mir = - EXPP_ClampFloat( value, EXPP_MAT_FRESNELMIRR_MIN, - EXPP_MAT_FRESNELMIRR_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->param[0], + EXPP_MAT_DIFFUSESIZE_MIN, + EXPP_MAT_DIFFUSESIZE_MAX ); } -static PyObject *Material_setFresnelMirrFac( BPy_Material * self, - PyObject * args ) +static int Material_setSpecSmooth( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 5.0]" ) ); - - self->material->fresnel_mir_i = - EXPP_ClampFloat( value, EXPP_MAT_FRESNELMIRRFAC_MIN, - EXPP_MAT_FRESNELMIRRFAC_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->param[3], + EXPP_MAT_SPECSMOOTH_MIN, + EXPP_MAT_SPECSMOOTH_MAX ); } -static PyObject *Material_setFilter( BPy_Material * self, - PyObject * args ) +static int Material_setDiffuseSmooth( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 1.0]" ) ); - - self->material->filter = - EXPP_ClampFloat( value, EXPP_MAT_FILTER_MIN, - EXPP_MAT_FILTER_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->param[1], + EXPP_MAT_DIFFUSESMOOTH_MIN, + EXPP_MAT_DIFFUSESMOOTH_MAX ); } -static PyObject *Material_setTranslucency( BPy_Material * self, - PyObject * args ) +static int Material_setDiffuseDarkness( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 1.0]" ) ); - - self->material->translucency = - EXPP_ClampFloat( value, EXPP_MAT_TRANSLUCENCY_MIN, - EXPP_MAT_TRANSLUCENCY_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->darkness, + EXPP_MAT_DIFFUSE_DARKNESS_MIN, + EXPP_MAT_DIFFUSE_DARKNESS_MAX ); } -static PyObject *Material_setIOR( BPy_Material * self, PyObject * args ) +static int Material_setRefracIndex( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 5.0]" ) ); - - self->material->ang = EXPP_ClampFloat( value, EXPP_MAT_IOR_MIN, - EXPP_MAT_IOR_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->refrac, + EXPP_MAT_REFRACINDEX_MIN, + EXPP_MAT_REFRACINDEX_MAX ); } -static PyObject *Material_setTransDepth( BPy_Material * self, PyObject * args ) +static int Material_setRms( BPy_Material * self, PyObject * value ) { - int value; - - if( !PyArg_ParseTuple( args, "i", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0, 10]" ) ); - - self->material->ray_depth_tra = - (short)EXPP_ClampInt( value, EXPP_MAT_TRANSDEPTH_MIN, - EXPP_MAT_TRANSDEPTH_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->rms, + EXPP_MAT_RMS_MIN, + EXPP_MAT_RMS_MAX ); } -static PyObject *Material_setFresnelTrans( BPy_Material * self, - PyObject * args ) +static int Material_setFilter( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 5.0]" ) ); - - self->material->fresnel_tra = - EXPP_ClampFloat( value, EXPP_MAT_FRESNELTRANS_MIN, - EXPP_MAT_FRESNELTRANS_MAX ); - - return EXPP_incr_ret( Py_None ); + return EXPP_setFloatClamped ( value, &self->material->filter, + EXPP_MAT_FILTER_MIN, + EXPP_MAT_FILTER_MAX ); } -static PyObject *Material_setFresnelTransFac( BPy_Material * self, - PyObject * args ) +static int Material_setTranslucency( BPy_Material * self, PyObject * value ) { - float value; - - if( !PyArg_ParseTuple( args, "f", &value ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected float argument in [0.0, 5.0]" ) ); - - self->material->fresnel_tra_i = - EXPP_ClampFloat( value, EXPP_MAT_FRESNELTRANSFAC_MIN, - EXPP_MAT_FRESNELTRANSFAC_MAX ); - - return EXPP_incr_ret( Py_None ); - + return EXPP_setFloatClamped ( value, &self->material->translucency, + EXPP_MAT_TRANSLUCENCY_MIN, + EXPP_MAT_TRANSLUCENCY_MAX ); } static PyObject *Material_setTexture( BPy_Material * self, PyObject * args ) @@ -2510,6 +2386,9 @@ static PyObject *Material_getScriptLinks( BPy_Material * self, slink = &( mat )->scriptlink; + /* can't this just return? EXP_getScriptLinks() returns a PyObject* + * or NULL anyway */ + ret = EXPP_getScriptLinks( slink, args, 0 ); if( ret ) @@ -2519,395 +2398,6 @@ static PyObject *Material_getScriptLinks( BPy_Material * self, } /*****************************************************************************/ -/* Function: Material_getAttr */ -/* Description: This is a callback function for the BPy_Material type. It is */ -/* the function that accesses BPy_Material "member variables" */ -/* and methods. */ -/*****************************************************************************/ -static PyObject *Material_getAttr( BPy_Material * self, char *name ) -{ - PyObject *attr = Py_None; - - if( strcmp( name, "name" ) == 0 ) - attr = PyString_FromString( self->material->id.name + 2 ); - else if( strcmp( name, "mode" ) == 0 ) - attr = PyInt_FromLong( self->material->mode ); - else if( strcmp( name, "rgbCol" ) == 0 ) - attr = Material_getRGBCol( self ); -/* else if (strcmp(name, "ambCol") == 0) - attr = Material_getAmbCol(self);*/ - else if( strcmp( name, "specCol" ) == 0 ) - attr = Material_getSpecCol( self ); - else if( strcmp( name, "mirCol" ) == 0 ) - attr = Material_getMirCol( self ); - else if( strcmp( name, "R" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material->r ); - else if( strcmp( name, "G" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material->g ); - else if( strcmp( name, "B" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material->b ); - else if( strcmp( name, "specR" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material->specr ); - else if( strcmp( name, "specG" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material->specg ); - else if( strcmp( name, "specB" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material->specb ); - else if( strcmp( name, "amb" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material->amb ); - else if( strcmp( name, "emit" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material->emit ); - else if( strcmp( name, "alpha" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material->alpha ); - else if( strcmp( name, "ref" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material->ref ); - else if( strcmp( name, "spec" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material->spec ); - else if( strcmp( name, "specTransp" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - spectra ); - else if( strcmp( name, "add" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material->add ); - else if( strcmp( name, "zOffset" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material->zoffs ); - else if( strcmp( name, "haloSize" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material->hasize ); - else if( strcmp( name, "haloSeed" ) == 0 ) - attr = PyInt_FromLong( ( long ) self->material->seed1 ); - else if( strcmp( name, "flareSize" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - flaresize ); - else if( strcmp( name, "flareBoost" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - flareboost ); - else if( strcmp( name, "flareSeed" ) == 0 ) - attr = PyInt_FromLong( ( long ) self->material->seed2 ); - else if( strcmp( name, "subSize" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - subsize ); - else if( strcmp( name, "hard" ) == 0 ) - attr = PyInt_FromLong( ( long ) self->material->har ); - else if( strcmp( name, "nFlares" ) == 0 ) - attr = PyInt_FromLong( ( long ) self->material->flarec ); - else if( strcmp( name, "nStars" ) == 0 ) - attr = PyInt_FromLong( ( long ) self->material->starc ); - else if( strcmp( name, "nLines" ) == 0 ) - attr = PyInt_FromLong( ( long ) self->material->linec ); - else if( strcmp( name, "nRings" ) == 0 ) - attr = PyInt_FromLong( ( long ) self->material->ringc ); - else if( strcmp( name, "rayMirr" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - ray_mirror ); - else if( strcmp( name, "rayMirrDepth" ) == 0 ) - attr = PyInt_FromLong( ( long ) self->material->ray_depth ); - else if( strcmp( name, "fresnelDepth" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - fresnel_mir ); - else if( strcmp( name, "fresnelDepthFac" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - fresnel_mir_i ); - else if( strcmp( name, "filter" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - filter ); - else if( strcmp( name, "translucency" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - translucency ); - else if( strcmp( name, "IOR" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material->ang ); - else if( strcmp( name, "transDepth" ) == 0 ) - attr = PyInt_FromLong( ( long ) self->material-> - ray_depth_tra ); - else if( strcmp( name, "fresnelTrans" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - fresnel_tra ); - else if( strcmp( name, "fresnelTransFac" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - fresnel_tra_i ); - else if( strcmp( name, "users" ) == 0 ) - attr = PyInt_FromLong( ( long ) self->material-> - id.us ); - /* Shader settings*/ - else if( strcmp( name, "specShader" ) == 0 ) - attr = PyInt_FromLong( ( long ) self->material-> - spec_shader ); - else if( strcmp( name, "diffuseShader" ) == 0 ) - attr = PyInt_FromLong( ( long ) self->material-> - diff_shader ); - else if( strcmp( name, "roughness" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - roughness ); - else if( strcmp( name, "specSize" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - param[2] ); - else if( strcmp( name, "diffuseSize" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - param[0] ); - else if( strcmp( name, "specSmooth" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - param[3] ); - else if( strcmp( name, "diffuseSmooth" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - param[1] ); - else if( strcmp( name, "diffuseDarkness" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - darkness ); - else if( strcmp( name, "refracIndex" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - refrac ); - else if( strcmp( name, "rms" ) == 0 ) - attr = PyFloat_FromDouble( ( double ) self->material-> - rms ); - - else if (strcmp(name, "oopsLoc") == 0) { - if (G.soops) { - Oops *oops= G.soops->oops.first; - while(oops) { - if(oops->type==ID_MA) { - if ((Material *)oops->id == self->material) { - return (Py_BuildValue ("ff", oops->x, oops->y)); - } - } - oops= oops->next; - } - } - Py_INCREF (Py_None); - return (Py_None); - } - /* Select in the oops view only since its a mesh */ - else if (strcmp(name, "oopsSel") == 0) { - if (G.soops) { - Oops *oops= G.soops->oops.first; - while(oops) { - if(oops->type==ID_MA) { - if ((Material *)oops->id == self->material) { - if (oops->flag & SELECT) - return EXPP_incr_ret_True(); - else - return EXPP_incr_ret_False(); - } - } - oops= oops->next; - } - } - Py_INCREF (Py_None); - return (Py_None); - } - else if( strcmp( name, "__members__" ) == 0 ) { - attr = /* 30 items */ - Py_BuildValue - ( "[s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s, s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s]", - "name", "mode", "rgbCol", "specCol", "mirCol", "R", - "G", "B", "alpha", "amb", "emit", "ref", - "spec", "specTransp", "add", "zOffset", "haloSize", "haloSeed", - "flareSize", "flareBoost", "flareSeed", "subSize", "hard", "nFlares", - "nStars", "nLines", "nRings", "rayMirr", "rayMirrDepth", "fresnelDepth", - "fresnelDepthFac", "IOR", "transDepth", - "fresnelTrans", "fresnelTransFac", "users", - "oopsLoc", "oopsSel", "filter", "translucency", "shader", "roughness", - "specSize", "diffuseSize", "specSmooth", - "diffuseSmooth", "diffuseDarkness", "refracIndex", "rms"); - } - - if( !attr ) - return ( EXPP_ReturnPyObjError( PyExc_MemoryError, - "couldn't create PyObject" ) ); - - if( attr != Py_None ) - return attr; /* member attribute found, return it */ - - /* not an attribute, search the methods table */ - return Py_FindMethod( BPy_Material_methods, ( PyObject * ) self, - name ); -} - -/****************************************************************************/ -/* Function: Material_setAttr */ -/* Description: This is a callback function for the BPy_Material type. */ -/* It is the function that sets Material attributes (member */ -/* variables). */ -/****************************************************************************/ -static int Material_setAttr( BPy_Material * self, char *name, - PyObject * value ) -{ - PyObject *valtuple; - PyObject *error = NULL; - -/* We're playing a trick on the Python API users here. Even if they use - * Material.member = val instead of Material.setMember(val), we end up using - * the function anyway, since it already has error checking, clamps to the - * right interval and updates the Blender Material structure when necessary. - */ - -/* First we put "value" in a tuple, because we want to pass it to functions - * that only accept PyTuples. */ - valtuple = Py_BuildValue( "(O)", value ); - - if( !valtuple ) /* everything OK with our PyObject? */ - return EXPP_ReturnIntError( PyExc_MemoryError, - "MaterialSetAttr: couldn't create PyTuple" ); - -/* Now we just compare "name" with all possible BPy_Material member variables */ - if( strcmp( name, "name" ) == 0 ) - error = Material_setName( self, valtuple ); - else if( strcmp( name, "mode" ) == 0 ) - error = Material_setIntMode( self, valtuple ); /* special case */ - else if( strcmp( name, "rgbCol" ) == 0 ) - error = Material_setRGBCol( self, valtuple ); -/* else if (strcmp (name, "ambCol") == 0) - error = Material_setAmbCol (self, valtuple);*/ - else if( strcmp( name, "specCol" ) == 0 ) - error = Material_setSpecCol( self, valtuple ); - else if( strcmp( name, "mirCol" ) == 0 ) - error = Material_setMirCol( self, valtuple ); - else if( strcmp( name, "R" ) == 0 ) - error = Material_setColorComponent( self, "R", valtuple ); - else if( strcmp( name, "G" ) == 0 ) - error = Material_setColorComponent( self, "G", valtuple ); - else if( strcmp( name, "B" ) == 0 ) - error = Material_setColorComponent( self, "B", valtuple ); - else if( strcmp( name, "specR" ) == 0 ) - error = Material_setColorComponent( self, "specR", valtuple ); - else if( strcmp( name, "specG" ) == 0 ) - error = Material_setColorComponent( self, "specG", valtuple ); - else if( strcmp( name, "specB" ) == 0 ) - error = Material_setColorComponent( self, "specB", valtuple ); - else if( strcmp( name, "amb" ) == 0 ) - error = Material_setAmb( self, valtuple ); - else if( strcmp( name, "emit" ) == 0 ) - error = Material_setEmit( self, valtuple ); - else if( strcmp( name, "alpha" ) == 0 ) - error = Material_setAlpha( self, valtuple ); - else if( strcmp( name, "ref" ) == 0 ) - error = Material_setRef( self, valtuple ); - else if( strcmp( name, "spec" ) == 0 ) - error = Material_setSpec( self, valtuple ); - else if( strcmp( name, "specTransp" ) == 0 ) - error = Material_setSpecTransp( self, valtuple ); - else if( strcmp( name, "add" ) == 0 ) - error = Material_setAdd( self, valtuple ); - else if( strcmp( name, "zOffset" ) == 0 ) - error = Material_setZOffset( self, valtuple ); - else if( strcmp( name, "haloSize" ) == 0 ) - error = Material_setHaloSize( self, valtuple ); - else if( strcmp( name, "haloSeed" ) == 0 ) - error = Material_setHaloSeed( self, valtuple ); - else if( strcmp( name, "flareSize" ) == 0 ) - error = Material_setFlareSize( self, valtuple ); - else if( strcmp( name, "flareBoost" ) == 0 ) - error = Material_setFlareBoost( self, valtuple ); - else if( strcmp( name, "flareSeed" ) == 0 ) - error = Material_setFlareSeed( self, valtuple ); - else if( strcmp( name, "subSize" ) == 0 ) - error = Material_setSubSize( self, valtuple ); - else if( strcmp( name, "hard" ) == 0 ) - error = Material_setHardness( self, valtuple ); - else if( strcmp( name, "nFlares" ) == 0 ) - error = Material_setNFlares( self, valtuple ); - else if( strcmp( name, "nStars" ) == 0 ) - error = Material_setNStars( self, valtuple ); - else if( strcmp( name, "nLines" ) == 0 ) - error = Material_setNLines( self, valtuple ); - else if( strcmp( name, "nRings" ) == 0 ) - error = Material_setNRings( self, valtuple ); - else if( strcmp( name, "rayMirr" ) == 0 ) - error = Material_setRayMirr( self, valtuple ); - else if( strcmp( name, "rayMirrDepth" ) == 0 ) - error = Material_setMirrDepth( self, valtuple ); - else if( strcmp( name, "fresnelDepth" ) == 0 ) - error = Material_setFresnelMirr( self, valtuple ); - else if( strcmp( name, "fresnelDepthFac" ) == 0 ) - error = Material_setFresnelMirrFac( self, valtuple ); - else if( strcmp( name, "filter" ) == 0 ) - error = Material_setFilter( self, valtuple ); - else if( strcmp( name, "translucency" ) == 0 ) - error = Material_setTranslucency( self, valtuple ); - else if( strcmp( name, "IOR" ) == 0 ) - error = Material_setIOR( self, valtuple ); - else if( strcmp( name, "transDepth" ) == 0 ) - error = Material_setTransDepth( self, valtuple ); - else if( strcmp( name, "fresnelTrans" ) == 0 ) - error = Material_setFresnelTrans( self, valtuple ); - else if( strcmp( name, "fresnelTransFac" ) == 0 ) - error = Material_setFresnelTransFac( self, valtuple ); - /* Shader settings */ - else if( strcmp( name, "specShader" ) == 0 ) - error = Material_setSpecShader( self, valtuple ); - else if( strcmp( name, "diffuseShader" ) == 0 ) - error = Material_setDiffuseShader( self, valtuple ); - else if( strcmp( name, "roughness" ) == 0 ) - error = Material_setRoughness( self, valtuple ); - else if( strcmp( name, "specSize" ) == 0 ) - error = Material_setSpecSize( self, valtuple ); - else if( strcmp( name, "diffuseSize" ) == 0 ) - error = Material_setDiffuseSize( self, valtuple ); - else if( strcmp( name, "specSmooth" ) == 0 ) - error = Material_setSpecSmooth( self, valtuple ); - else if( strcmp( name, "diffuseSmooth" ) == 0 ) - error = Material_setDiffuseSmooth( self, valtuple ); - else if( strcmp( name, "diffuseDarkness" ) == 0 ) - error = Material_setDiffuseDarkness( self, valtuple ); - else if( strcmp( name, "refracIndex" ) == 0 ) - error = Material_setRefracIndex( self, valtuple ); - else if( strcmp( name, "rms" ) == 0 ) - error = Material_setRms( self, valtuple ); - else if (strcmp (name, "oopsLoc") == 0) { - if (G.soops) { - Oops *oops= G.soops->oops.first; - while(oops) { - if(oops->type==ID_MA) { - if ((Material *)oops->id == self->material) { - if (!PyArg_ParseTuple (value, "ff", &(oops->x),&(oops->y))) - PyErr_SetString(PyExc_AttributeError, - "expected two floats as arguments"); - break; - } - } - oops= oops->next; - } - if (!oops) - PyErr_SetString(PyExc_RuntimeError, - "couldn't find oopsLoc data for this material!"); - else error = EXPP_incr_ret (Py_None); - } - } - /* Select in the oops view only since its a mesh */ - else if (strcmp (name, "oopsSel") == 0) { - int sel; - if (!PyArg_Parse (value, "i", &sel)) - PyErr_SetString (PyExc_TypeError, "expected an integer, 0 or 1"); - else if (G.soops) { - Oops *oops= G.soops->oops.first; - while(oops) { - if(oops->type==ID_MA) { - if ((Material *)oops->id == self->material) { - if(sel == 0) oops->flag &= ~SELECT; - else oops->flag |= SELECT; - break; - } - } - oops= oops->next; - } - error = EXPP_incr_ret (Py_None); - } - } - else { /* Error */ - Py_DECREF( valtuple ); - return ( EXPP_ReturnIntError( PyExc_AttributeError, name ) ); - } - -/* valtuple won't be returned to the caller, so we need to DECREF it */ - Py_DECREF( valtuple ); - - if( error != Py_None ) - return -1; - -/* Py_None was incref'ed by the called Material_set* function. We probably - * don't need to decref Py_None (!), but since Python/C API manual tells us - * to treat it like any other PyObject regarding ref counting ... */ - Py_DECREF( Py_None ); - return 0; /* normal exit */ -} - -/*****************************************************************************/ /* Function: Material_repr */ /* Description: This is a callback function for the BPy_Material type. It */ /* builds a meaninful string to represent material objects. */ @@ -3077,3 +2567,496 @@ void EXPP_incr_mats_us( Material ** matlist, int len ) return; } + +static PyObject *Material_getColorComponent( BPy_Material * self, + void * closure ) +{ + PyObject *attr = NULL; + + switch ( (int)closure ) { + case EXPP_MAT_COMP_R: + attr = PyFloat_FromDouble( ( double ) self->material->r ); + break; + case EXPP_MAT_COMP_G: + attr = PyFloat_FromDouble( ( double ) self->material->g ); + break; + case EXPP_MAT_COMP_B: + attr = PyFloat_FromDouble( ( double ) self->material->b ); + break; + case EXPP_MAT_COMP_SPECR: + attr = PyFloat_FromDouble( ( double ) self->material->specr ); + break; + case EXPP_MAT_COMP_SPECG: + attr = PyFloat_FromDouble( ( double ) self->material->specg ); + break; + case EXPP_MAT_COMP_SPECB: + attr = PyFloat_FromDouble( ( double ) self->material->specb ); + break; + case EXPP_MAT_COMP_MIRR: + attr = PyFloat_FromDouble( ( double ) self->material->mirr ); + break; + case EXPP_MAT_COMP_MIRG: + attr = PyFloat_FromDouble( ( double ) self->material->mirg ); + break; + case EXPP_MAT_COMP_MIRB: + attr = PyFloat_FromDouble( ( double ) self->material->mirb ); + break; + default: + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "unknown color component specified" ); + } + + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "PyFloat_FromDouble() failed" ); + return attr; +} + +static PyObject *Material_getOopsLoc ( BPy_Material * self ) +{ + if( G.soops ) { + Oops *oops = G.soops->oops.first; + while( oops ) { + if( oops->type == ID_MA && (Material *)oops->id == self->material ) + return Py_BuildValue( "ff", oops->x, oops->y ); + oops = oops->next; + } + } + Py_INCREF( Py_None ); + return Py_None; +} + +static PyObject *Material_getOopsSel ( BPy_Material * self ) +{ + if( G.soops ) { + Oops *oops= G.soops->oops.first; + while( oops ) { + if( oops->type == ID_MA + && (Material *)oops->id == self->material ) { + if( oops->flag & SELECT ) + return EXPP_incr_ret_True(); + else + return EXPP_incr_ret_False(); + } + oops = oops->next; + } + } + Py_INCREF( Py_None ); + return Py_None; +} + +static int Material_setOopsLoc ( BPy_Material * self, PyObject * value ) +{ + if( G.soops ) { + Oops *oops= G.soops->oops.first; + while( oops ) { + if( oops->type == ID_MA ) { + if ( (Material *)oops->id == self->material ) { + if ( PyArg_ParseTuple( value, "ff", &(oops->x),&(oops->y))) + return 0; + else + return EXPP_ReturnIntError( PyExc_AttributeError, + "expected two floats as arguments" ); + } + } + oops = oops->next; + } + return EXPP_ReturnIntError( PyExc_RuntimeError, + "couldn't find oopsLoc data for material" ); + } + return 0; +} + +static int Material_setOopsSel ( BPy_Material * self, PyObject * value ) +{ + int param; + + if( !PyInt_CheckExact ( value ) ) + return EXPP_ReturnIntError( PyExc_TypeError, + "expected an integer, 0 or 1" ); + + param = PyInt_AS_LONG ( value ); + if( param < 0 || param > 1 ) + return EXPP_ReturnIntError( PyExc_TypeError, + "expected an integer, 0 or 1" ); + + if( G.soops ) { + Oops *oops = G.soops->oops.first; + while( oops ) { + if( oops->type==ID_MA ) { + if( (Material *)oops->id == self->material ) { + if( !param ) + oops->flag &= ~SELECT; + else + oops->flag |= SELECT; + return 0; + } + } + oops= oops->next; + } + } + return 0; +} + +static PyObject *Material_getUsers( BPy_Material * self ) +{ + return PyInt_FromLong( self->material->id.us ); +} + +/* #####DEPRECATED###### */ + +static PyObject *Matr_oldsetAdd( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setAdd ); +} + +static PyObject *Matr_oldsetAlpha( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setAlpha ); +} + +static PyObject *Matr_oldsetAmb( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setAmb ); +} + +static PyObject *Matr_oldsetDiffuseDarkness( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setDiffuseDarkness ); +} + +static PyObject *Matr_oldsetDiffuseShader( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setDiffuseShader ); +} + +static PyObject *Matr_oldsetDiffuseSize( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setDiffuseSize ); +} + +static PyObject *Matr_oldsetDiffuseSmooth( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setDiffuseSmooth ); +} + +static PyObject *Matr_oldsetEmit( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setEmit ); +} + +static PyObject *Matr_oldsetFilter( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFilter ); +} + +static PyObject *Matr_oldsetFlareBoost( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFlareBoost ); +} + +static PyObject *Matr_oldsetFlareSeed( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFlareSeed ); +} + +static PyObject *Matr_oldsetFlareSize( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFlareSize ); +} + +static PyObject *Matr_oldsetFresnelMirr( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFresnelMirr ); +} + +static PyObject *Matr_oldsetFresnelMirrFac( BPy_Material * self, + PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFresnelMirrFac ); +} + +static PyObject *Matr_oldsetFresnelTrans( BPy_Material * self, + PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFresnelTrans ); +} + +static PyObject *Matr_oldsetFresnelTransFac( BPy_Material * self, + PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setFresnelTransFac ); +} + +static PyObject *Matr_oldsetHaloSeed( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setHaloSeed ); +} + +static PyObject *Matr_oldsetHaloSize( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setHaloSize ); +} + +static PyObject *Matr_oldsetHardness( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setHardness ); +} + +static PyObject *Matr_oldsetIOR( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setIOR ); +} + +static PyObject *Matr_oldsetName( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setName ); +} + +static PyObject *Matr_oldsetNFlares( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setNFlares ); +} + +static PyObject *Matr_oldsetNLines( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setNLines ); +} + +static PyObject *Matr_oldsetNRings( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setNRings ); +} + +static PyObject *Matr_oldsetNStars( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setNStars ); +} + +static PyObject *Matr_oldsetRayMirr( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setRayMirr ); +} + +static PyObject *Matr_oldsetRoughness( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setRoughness ); +} + +static PyObject *Matr_oldsetMirrDepth( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setMirrDepth ); +} + +static PyObject *Matr_oldsetRef( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setRef ); +} + +static PyObject *Matr_oldsetRefracIndex( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setRefracIndex ); +} + +static PyObject *Matr_oldsetRms( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setRms ); +} + +static PyObject *Matr_oldsetSpec( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setSpec ); +} + +static PyObject *Matr_oldsetSpecShader( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setSpecShader ); +} + +static PyObject *Matr_oldsetSpecSize( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setSpecSize ); +} + +static PyObject *Matr_oldsetSpecSmooth( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setSpecSmooth ); +} + +static PyObject *Matr_oldsetSpecTransp( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setSpecTransp ); +} + +static PyObject *Matr_oldsetSubSize( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setSubSize ); +} + +static PyObject *Matr_oldsetTranslucency( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setTranslucency ); +} + +static PyObject *Matr_oldsetTransDepth( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setTransDepth ); +} + +static PyObject *Matr_oldsetZOffset( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setZOffset ); +} + +static PyObject *Matr_oldsetRGBCol( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setRGBCol ); +} + +static PyObject *Matr_oldsetSpecCol( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setSpecCol ); +} + +static PyObject *Matr_oldsetMirCol( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setMirCol ); +} + + +/* Possible modes are traceable, shadow, shadeless, wire, vcolLight, + * vcolPaint, halo, ztransp, zinvert, haloRings, env, haloLines, + * onlyShadow, xalpha, star, faceTexture, haloTex, haloPuno, noMist, + * haloShaded, haloFlare */ + +static PyObject *Matr_oldsetMode( BPy_Material * self, PyObject * args ) +{ + unsigned int i, flag = 0, ok = 0; + PyObject *value, *error; + char *m[28] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL + }; + + /* + * check for a single integer argument; do a quick check for now + * that the value is not larger than double the highest flag bit + */ + + if ( (PySequence_Size( args ) == 1) + && PyInt_Check ( PySequence_Fast_GET_ITEM ( args , 0 ) ) + && PyArg_ParseTuple( args, "i", &flag ) + && flag < (MA_RAYMIRROR >> 1) ) { + ok = 1; + + /* + * check for either an empty argument list, or up to 28 strings + */ + + } else if( PyArg_ParseTuple( args, "|ssssssssssssssssssssssssssss", + &m[0], &m[1], &m[2], &m[3], &m[4], &m[5], &m[6], + &m[7], &m[8], &m[9], &m[10], &m[11], &m[12], + &m[13], &m[14], &m[15], &m[16], &m[17], &m[18], + &m[19], &m[20], &m[21], &m[22], &m[23], &m[24], + &m[25], &m[26], &m[27] ) ) { + for( i = 0; i < 28; i++ ) { + if( m[i] == NULL ) + break; + if( strcmp( m[i], "Traceable" ) == 0 ) + flag |= MA_TRACEBLE; + else if( strcmp( m[i], "Shadow" ) == 0 ) + flag |= MA_SHADOW; + else if( strcmp( m[i], "Shadeless" ) == 0 ) + flag |= MA_SHLESS; + else if( strcmp( m[i], "Wire" ) == 0 ) + flag |= MA_WIRE; + else if( strcmp( m[i], "VColLight" ) == 0 ) + flag |= MA_VERTEXCOL; + else if( strcmp( m[i], "VColPaint" ) == 0 ) + flag |= MA_VERTEXCOLP; + else if( strcmp( m[i], "Halo" ) == 0 ) + flag |= MA_HALO; + else if( strcmp( m[i], "ZTransp" ) == 0 ) + flag |= MA_ZTRA; + else if( strcmp( m[i], "ZInvert" ) == 0 ) + flag |= MA_ZINV; + else if( strcmp( m[i], "HaloRings" ) == 0 ) + flag |= MA_HALO_RINGS; + else if( strcmp( m[i], "HaloLines" ) == 0 ) + flag |= MA_HALO_LINES; + else if( strcmp( m[i], "OnlyShadow" ) == 0 ) + flag |= MA_ONLYSHADOW; + else if( strcmp( m[i], "HaloXAlpha" ) == 0 ) + flag |= MA_HALO_XALPHA; + else if( strcmp( m[i], "HaloStar" ) == 0 ) + flag |= MA_STAR; + else if( strcmp( m[i], "TexFace" ) == 0 ) + flag |= MA_FACETEXTURE; + else if( strcmp( m[i], "HaloTex" ) == 0 ) + flag |= MA_HALOTEX; + else if( strcmp( m[i], "HaloPuno" ) == 0 ) + flag |= MA_HALOPUNO; + else if( strcmp( m[i], "NoMist" ) == 0 ) + flag |= MA_NOMIST; + else if( strcmp( m[i], "HaloShaded" ) == 0 ) + flag |= MA_HALO_SHADE; + else if( strcmp( m[i], "HaloFlare" ) == 0 ) + flag |= MA_HALO_FLARE; + else if( strcmp( m[i], "Radio" ) == 0 ) + flag |= MA_RADIO; + /* ** Mirror ** */ + else if( strcmp( m[i], "RayMirr" ) == 0 ) + flag |= MA_RAYMIRROR; + else if( strcmp( m[i], "ZTransp" ) == 0 ) + flag |= MA_ZTRA; + else if( strcmp( m[i], "RayTransp" ) == 0 ) + flag |= MA_RAYTRANSP; + else if( strcmp( m[i], "OnlyShadow" ) == 0 ) + flag |= MA_ONLYSHADOW; + else if( strcmp( m[i], "NoMist" ) == 0 ) + flag |= MA_NOMIST; + else if( strcmp( m[i], "Env" ) == 0 ) + flag |= MA_ENV; + else + return ( EXPP_ReturnPyObjError( PyExc_AttributeError, + "unknown Material mode argument" ) ); + } + ok = 1; + } + + /* if neither input method worked, then throw an exception */ + + if ( ok == 0 ) + return ( EXPP_ReturnPyObjError + ( PyExc_AttributeError, + "expected nothing, an integer or up to 22 string argument(s)" ) ); + /* build tuple, call wrapper */ + + value = Py_BuildValue( "(i)", flag ); + error = EXPP_setterWrapper( (void *)self, value, (setter)Material_setMode ); + Py_DECREF ( value ); + return error; +} + +static PyObject *Matr_oldsetIpo( BPy_Material * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, (setter)Material_setIpo ); +} + +/* + * clearIpo() returns True/False depending on whether material has an Ipo + */ + +static PyObject *Material_clearIpo( BPy_Material * self ) +{ + /* if Ipo defined, delete it and return true */ + + if( self->material->ipo ) { + PyObject *value = Py_BuildValue( "(O)", Py_None ); + EXPP_setterWrapper( (void *)self, value, (setter)Material_setIpo ); + Py_DECREF ( value ); + return EXPP_incr_ret_True(); + } + return EXPP_incr_ret_False(); /* no ipo found */ +} diff --git a/source/blender/python/api2_2x/Texture.c b/source/blender/python/api2_2x/Texture.c index 86e6ecc63ee..1a73e04e971 100644 --- a/source/blender/python/api2_2x/Texture.c +++ b/source/blender/python/api2_2x/Texture.c @@ -1,5 +1,6 @@ /* * $Id$ + * * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or @@ -24,7 +25,7 @@ * * This is a new part of Blender. * - * Contributor(s): Alex Mole, Nathan Letwory, Joilnen B. Leite + * Contributor(s): Alex Mole, Nathan Letwory, Joilnen B. Leite, Ken Hughes * * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ @@ -41,54 +42,108 @@ #include "Image.h" #include "Ipo.h" #include "constant.h" +#include "blendef.h" +#include "render.h" #include "gen_utils.h" - /*****************************************************************************/ /* Blender.Texture constants */ /*****************************************************************************/ #define EXPP_TEX_TYPE_NONE 0 -#define EXPP_TEX_TYPE_CLOUDS TEX_CLOUDS -#define EXPP_TEX_TYPE_WOOD TEX_WOOD -#define EXPP_TEX_TYPE_MARBLE TEX_MARBLE -#define EXPP_TEX_TYPE_MAGIC TEX_MAGIC -#define EXPP_TEX_TYPE_BLEND TEX_BLEND -#define EXPP_TEX_TYPE_STUCCI TEX_STUCCI -#define EXPP_TEX_TYPE_NOISE TEX_NOISE -#define EXPP_TEX_TYPE_IMAGE TEX_IMAGE -#define EXPP_TEX_TYPE_PLUGIN TEX_PLUGIN -#define EXPP_TEX_TYPE_ENVMAP TEX_ENVMAP -#define EXPP_TEX_TYPE_MUSGRAVE TEX_MUSGRAVE -#define EXPP_TEX_TYPE_VORONOI TEX_VORONOI -#define EXPP_TEX_TYPE_DISTNOISE TEX_DISTNOISE #define EXPP_TEX_TYPE_MIN EXPP_TEX_TYPE_NONE -#define EXPP_TEX_TYPE_MAX EXPP_TEX_TYPE_DISTNOISE +#define EXPP_TEX_TYPE_MAX TEX_DISTNOISE + +#define EXPP_TEX_ANIMFRAME_MIN 0 +#define EXPP_TEX_ANIMFRAME_MAX ((int)MAXFRAMEF) +#define EXPP_TEX_ANIMLEN_MIN 0 +#define EXPP_TEX_ANIMLEN_MAX ((int)(MAXFRAMEF)/2) +#define EXPP_TEX_ANIMMONSTART_MIN 0 +#define EXPP_TEX_ANIMMONSTART_MAX ((int)MAXFRAMEF) +#define EXPP_TEX_ANIMMONDUR_MIN 0 +#define EXPP_TEX_ANIMMONDUR_MAX 250 +#define EXPP_TEX_ANIMOFFSET_MIN -((int)(MAXFRAMEF)/2) +#define EXPP_TEX_ANIMOFFSET_MAX ((int)(MAXFRAMEF)/2) +#define EXPP_TEX_ANIMSTART_MIN 0 +#define EXPP_TEX_ANIMSTART_MAX ((int)(MAXFRAMEF)/2) +#define EXPP_TEX_FIEIMA_MIN 1 +#define EXPP_TEX_FIEIMA_MAX 200 +#define EXPP_TEX_NOISEDEPTH_MIN 0 +#define EXPP_TEX_NOISEDEPTH_MAX 6 +/* max depth is different for magic type textures */ +#define EXPP_TEX_NOISEDEPTH_MAX_MAGIC 10 +#define EXPP_TEX_REPEAT_MIN 1 +#define EXPP_TEX_REPEAT_MAX 512 + +#define EXPP_TEX_FILTERSIZE_MIN 0.1f +#define EXPP_TEX_FILTERSIZE_MAX 25.0f +#define EXPP_TEX_NOISESIZE_MIN 0.0001f +#define EXPP_TEX_NOISESIZE_MAX 2.0f +#define EXPP_TEX_BRIGHTNESS_MIN 0.0f +#define EXPP_TEX_BRIGHTNESS_MAX 2.0f +#define EXPP_TEX_CONTRAST_MIN 0.01f +#define EXPP_TEX_CONTRAST_MAX 5.0f +#define EXPP_TEX_CROP_MIN -10.0f +#define EXPP_TEX_CROP_MAX 10.0f +#define EXPP_TEX_RGBCOL_MIN 0.0f +#define EXPP_TEX_RGBCOL_MAX 2.0f +#define EXPP_TEX_TURBULENCE_MIN 0.0f +#define EXPP_TEX_TURBULENCE_MAX 200.0f +#define EXPP_TEX_MH_G_MIN 0.0001f +#define EXPP_TEX_MH_G_MAX 2.0f +#define EXPP_TEX_LACUNARITY_MIN 0.0f +#define EXPP_TEX_LACUNARITY_MAX 6.0f +#define EXPP_TEX_OCTS_MIN 0.0f +#define EXPP_TEX_OCTS_MAX 8.0f +#define EXPP_TEX_ISCALE_MIN 0.0f +#define EXPP_TEX_ISCALE_MAX 10.0f +#define EXPP_TEX_EXP_MIN 0.010f +#define EXPP_TEX_EXP_MAX 10.0f +#define EXPP_TEX_WEIGHT1_MIN -2.0f +#define EXPP_TEX_WEIGHT1_MAX 2.0f +#define EXPP_TEX_WEIGHT2_MIN -2.0f +#define EXPP_TEX_WEIGHT2_MAX 2.0f +#define EXPP_TEX_WEIGHT3_MIN -2.0f +#define EXPP_TEX_WEIGHT3_MAX 2.0f +#define EXPP_TEX_WEIGHT4_MIN -2.0f +#define EXPP_TEX_WEIGHT4_MAX 2.0f +#define EXPP_TEX_DISTAMNT_MIN 0.0f +#define EXPP_TEX_DISTAMNT_MAX 10.0f /* i can't find these defined anywhere- they're just taken from looking at */ /* the button creation code in source/blender/src/buttons_shading.c */ +/* cloud stype */ #define EXPP_TEX_STYPE_CLD_DEFAULT 0 #define EXPP_TEX_STYPE_CLD_COLOR 1 +/* wood stype */ #define EXPP_TEX_STYPE_WOD_BANDS 0 #define EXPP_TEX_STYPE_WOD_RINGS 1 #define EXPP_TEX_STYPE_WOD_BANDNOISE 2 #define EXPP_TEX_STYPE_WOD_RINGNOISE 3 +/* magic stype */ #define EXPP_TEX_STYPE_MAG_DEFAULT 0 +/* marble stype */ #define EXPP_TEX_STYPE_MBL_SOFT 0 #define EXPP_TEX_STYPE_MBL_SHARP 1 #define EXPP_TEX_STYPE_MBL_SHARPER 2 +/* blend stype */ #define EXPP_TEX_STYPE_BLN_LIN 0 #define EXPP_TEX_STYPE_BLN_QUAD 1 #define EXPP_TEX_STYPE_BLN_EASE 2 #define EXPP_TEX_STYPE_BLN_DIAG 3 #define EXPP_TEX_STYPE_BLN_SPHERE 4 #define EXPP_TEX_STYPE_BLN_HALO 5 +/* stucci stype */ #define EXPP_TEX_STYPE_STC_PLASTIC 0 #define EXPP_TEX_STYPE_STC_WALLIN 1 #define EXPP_TEX_STYPE_STC_WALLOUT 2 +/* noise stype */ #define EXPP_TEX_STYPE_NSE_DEFAULT 0 +/* image stype */ #define EXPP_TEX_STYPE_IMG_DEFAULT 0 +/* plug-in stype */ #define EXPP_TEX_STYPE_PLG_DEFAULT 0 +/* envmap stype */ #define EXPP_TEX_STYPE_ENV_STATIC 0 #define EXPP_TEX_STYPE_ENV_ANIM 1 #define EXPP_TEX_STYPE_ENV_LOAD 2 @@ -99,77 +154,18 @@ #define EXPP_TEX_STYPE_MUS_FBM 3 #define EXPP_TEX_STYPE_MUS_HTERRAIN 4 /* voronoi stype */ -#define EXPP_TEX_STYPE_VN_INT 0 -#define EXPP_TEX_STYPE_VN_COL1 1 -#define EXPP_TEX_STYPE_VN_COL2 2 -#define EXPP_TEX_STYPE_VN_COL3 3 - -#define EXPP_TEX_FLAG_COLORBAND TEX_COLORBAND -#define EXPP_TEX_FLAG_FLIPBLEND TEX_FLIPBLEND -#define EXPP_TEX_FLAG_NEGALPHA TEX_NEGALPHA - -#define EXPP_TEX_IMAGEFLAG_INTERPOL TEX_INTERPOL -#define EXPP_TEX_IMAGEFLAG_USEALPHA TEX_USEALPHA -#define EXPP_TEX_IMAGEFLAG_MIPMAP TEX_MIPMAP -#define EXPP_TEX_IMAGEFLAG_FIELDS TEX_FIELDS -#define EXPP_TEX_IMAGEFLAG_ROT90 TEX_IMAROT -#define EXPP_TEX_IMAGEFLAG_CALCALPHA TEX_CALCALPHA -#define EXPP_TEX_IMAGEFLAG_CYCLIC TEX_ANIMCYCLIC -#define EXPP_TEX_IMAGEFLAG_MOVIE TEX_ANIM5 -#define EXPP_TEX_IMAGEFLAG_STFIELD TEX_STD_FIELD -#define EXPP_TEX_IMAGEFLAG_ANTI TEX_ANTIALI -#define EXPP_TEX_IMAGEFLAG_NORMALMAP TEX_NORMALMAP - -#define EXPP_TEX_EXTEND_EXTEND TEX_EXTEND -#define EXPP_TEX_EXTEND_CLIP TEX_CLIP -#define EXPP_TEX_EXTEND_REPEAT TEX_REPEAT -#define EXPP_TEX_EXTEND_CLIPCUBE TEX_CLIPCUBE - -#define EXPP_TEX_EXTEND_MIN EXPP_TEX_EXTEND_EXTEND -#define EXPP_TEX_EXTEND_MAX EXPP_TEX_EXTEND_CLIPCUBE - -#define EXPP_TEX_TEXCO_ORCO TEXCO_ORCO -#define EXPP_TEX_TEXCO_REFL TEXCO_REFL -#define EXPP_TEX_TEXCO_NOR TEXCO_NORM -#define EXPP_TEX_TEXCO_GLOB TEXCO_GLOB -#define EXPP_TEX_TEXCO_UV TEXCO_UV -#define EXPP_TEX_TEXCO_OBJECT TEXCO_OBJECT -#define EXPP_TEX_TEXCO_WIN TEXCO_WINDOW -#define EXPP_TEX_TEXCO_VIEW TEXCO_VIEW -#define EXPP_TEX_TEXCO_STICK TEXCO_STICKY - -#define EXPP_TEX_MAPTO_COL MAP_COL -#define EXPP_TEX_MAPTO_NOR MAP_NORM -#define EXPP_TEX_MAPTO_CSP MAP_COLSPEC -#define EXPP_TEX_MAPTO_CMIR MAP_COLMIR -#define EXPP_TEX_MAPTO_REF MAP_REF -#define EXPP_TEX_MAPTO_SPEC MAP_SPEC -#define EXPP_TEX_MAPTO_HARD MAP_HAR -#define EXPP_TEX_MAPTO_ALPHA MAP_ALPHA -#define EXPP_TEX_MAPTO_EMIT MAP_EMIT -#define EXPP_TEX_MAPTO_RAYMIR MAP_RAYMIRR -#define EXPP_TEX_MAPTO_DISP MAP_DISPLACE -#define EXPP_TEX_MAPTO_TRANSLU MAP_TRANSLU -#define EXPP_TEX_MAPTO_AMB MAP_AMB - -#define EXPP_TEX_STYPE_DN_BLENDER TEX_BLENDER -#define EXPP_TEX_STYPE_DN_PERLIN TEX_STDPERLIN -#define EXPP_TEX_STYPE_DN_IMPROVEPERLIN TEX_NEWPERLIN -#define EXPP_TEX_STYPE_DN_VORONOIF1 TEX_VORONOI_F1 -#define EXPP_TEX_STYPE_DN_VORONOIF2 TEX_VORONOI_F2 -#define EXPP_TEX_STYPE_DN_VORONOIF3 TEX_VORONOI_F3 -#define EXPP_TEX_STYPE_DN_VORONOIF4 TEX_VORONOI_F4 -#define EXPP_TEX_STYPE_DN_VORONOIF2F1 TEX_VORONOI_F2F1 -#define EXPP_TEX_STYPE_DN_VORONOICRACKLE TEX_VORONOI_CRACKLE -#define EXPP_TEX_STYPE_DN_CELLNOISE TEX_CELLNOISE - -#define EXPP_TEX_STYPE_VN_TEX_DISTANCE TEX_DISTANCE -#define EXPP_TEX_STYPE_VN_TEX_DISTANCE_SQUARED TEX_DISTANCE_SQUARED -#define EXPP_TEX_STYPE_VN_TEX_MANHATTAN TEX_MANHATTAN -#define EXPP_TEX_STYPE_VN_TEX_CHEBYCHEV TEX_CHEBYCHEV -#define EXPP_TEX_STYPE_VN_TEX_MINKOVSKY_HALF TEX_MINKOVSKY_HALF -#define EXPP_TEX_STYPE_VN_TEX_MINKOVSKY_FOUR TEX_MINKOVSKY_FOUR -#define EXPP_TEX_STYPE_VN_TEX_MINKOVSKY TEX_MINKOVSKY +#define EXPP_TEX_STYPE_VN_INT 0 +#define EXPP_TEX_STYPE_VN_COL1 1 +#define EXPP_TEX_STYPE_VN_COL2 2 +#define EXPP_TEX_STYPE_VN_COL3 3 + +#define EXPP_TEX_EXTEND_MIN TEX_EXTEND +#define EXPP_TEX_EXTEND_MAX TEX_CHECKER + +#define EXPP_TEX_NOISE_SINE 0 +#define EXPP_TEX_NOISE_SAW 1 +#define EXPP_TEX_NOISE_TRI 2 +#define EXPP_TEX_NOISEBASIS2 0xffff /****************************************************************************/ /* Texture String->Int maps */ @@ -177,50 +173,56 @@ static const EXPP_map_pair tex_type_map[] = { {"None", EXPP_TEX_TYPE_NONE}, - {"Clouds", EXPP_TEX_TYPE_CLOUDS}, - {"Wood", EXPP_TEX_TYPE_WOOD}, - {"Marble", EXPP_TEX_TYPE_MARBLE}, - {"Magic", EXPP_TEX_TYPE_MAGIC}, - {"Blend", EXPP_TEX_TYPE_BLEND}, - {"Stucci", EXPP_TEX_TYPE_STUCCI}, - {"Noise", EXPP_TEX_TYPE_NOISE}, - {"Image", EXPP_TEX_TYPE_IMAGE}, - {"Plugin", EXPP_TEX_TYPE_PLUGIN}, - {"EnvMap", EXPP_TEX_TYPE_ENVMAP}, - {"Musgrave", EXPP_TEX_TYPE_MUSGRAVE}, - {"Voronoi", EXPP_TEX_TYPE_VORONOI}, - {"DistortedNoise", EXPP_TEX_TYPE_DISTNOISE}, + {"Clouds", TEX_CLOUDS}, + {"Wood", TEX_WOOD}, + {"Marble", TEX_MARBLE}, + {"Magic", TEX_MAGIC}, + {"Blend", TEX_BLEND}, + {"Stucci", TEX_STUCCI}, + {"Noise", TEX_NOISE}, + {"Image", TEX_IMAGE}, + {"Plugin", TEX_PLUGIN}, + {"EnvMap", TEX_ENVMAP}, + {"Musgrave", TEX_MUSGRAVE}, + {"Voronoi", TEX_VORONOI}, + {"DistortedNoise", TEX_DISTNOISE}, {NULL, 0} }; static const EXPP_map_pair tex_flag_map[] = { - /* we don't support this yet! */ -/* { "ColorBand", EXPP_TEX_FLAG_COLORBAND }, */ - {"FlipBlend", EXPP_TEX_FLAG_FLIPBLEND}, - {"NegAlpha", EXPP_TEX_FLAG_NEGALPHA}, +/* NOTE "CheckerOdd" and "CheckerEven" are new */ +#if 0 + {"ColorBand", TEX_COLORBAND }, +#endif + {"FlipBlend", TEX_FLIPBLEND}, + {"NegAlpha", TEX_NEGALPHA}, + {"CheckerOdd",TEX_CHECKER_ODD}, + {"CheckerEven",TEX_CHECKER_EVEN}, {NULL, 0} }; static const EXPP_map_pair tex_imageflag_map[] = { - {"InterPol", EXPP_TEX_IMAGEFLAG_INTERPOL}, - {"UseAlpha", EXPP_TEX_IMAGEFLAG_USEALPHA}, - {"MipMap", EXPP_TEX_IMAGEFLAG_MIPMAP}, - {"Fields", EXPP_TEX_IMAGEFLAG_FIELDS}, - {"Rot90", EXPP_TEX_IMAGEFLAG_ROT90}, - {"CalcAlpha", EXPP_TEX_IMAGEFLAG_CALCALPHA}, - {"Cyclic", EXPP_TEX_IMAGEFLAG_CYCLIC}, - {"Movie", EXPP_TEX_IMAGEFLAG_MOVIE}, - {"StField", EXPP_TEX_IMAGEFLAG_STFIELD}, - {"Anti", EXPP_TEX_IMAGEFLAG_ANTI}, - {"NormalMap", EXPP_TEX_IMAGEFLAG_NORMALMAP}, + {"InterPol", TEX_INTERPOL}, + {"UseAlpha", TEX_USEALPHA}, + {"MipMap", TEX_MIPMAP}, + {"Fields", TEX_FIELDS}, + {"Rot90", TEX_IMAROT}, + {"CalcAlpha", TEX_CALCALPHA}, + {"Cyclic", TEX_ANIMCYCLIC}, + {"Movie", TEX_ANIM5}, + {"StField", TEX_STD_FIELD}, + {"Anti", TEX_ANTIALI}, + {"NormalMap", TEX_NORMALMAP}, {NULL, 0} }; static const EXPP_map_pair tex_extend_map[] = { - {"Extend", EXPP_TEX_EXTEND_EXTEND}, - {"Clip", EXPP_TEX_EXTEND_CLIP}, - {"ClipCube", EXPP_TEX_EXTEND_CLIPCUBE}, - {"Repeat", EXPP_TEX_EXTEND_REPEAT}, + {"Extend", TEX_EXTEND}, + {"Clip", TEX_CLIP}, + {"ClipCube", TEX_CLIPCUBE}, + {"Repeat", TEX_REPEAT}, +/* NOTE "Checker" is new */ + {"Checker", TEX_CHECKER}, {NULL, 0} }; @@ -287,16 +289,16 @@ static const EXPP_map_pair tex_stype_musg_map[] = { static const EXPP_map_pair tex_stype_distortednoise_map[] = { {"Default", 0}, - {"BlenderOriginal", EXPP_TEX_STYPE_DN_BLENDER}, - {"OriginalPerlin", EXPP_TEX_STYPE_DN_PERLIN}, - {"ImprovedPerlin", EXPP_TEX_STYPE_DN_IMPROVEPERLIN}, - {"VoronoiF1", EXPP_TEX_STYPE_DN_VORONOIF1}, - {"VoronoiF2", EXPP_TEX_STYPE_DN_VORONOIF2}, - {"VoronoiF3", EXPP_TEX_STYPE_DN_VORONOIF3}, - {"VoronoiF4", EXPP_TEX_STYPE_DN_VORONOIF4}, - {"VoronoiF2-F1", EXPP_TEX_STYPE_DN_VORONOIF2F1}, - {"VoronoiCrackle", EXPP_TEX_STYPE_DN_VORONOICRACKLE}, - {"CellNoise", EXPP_TEX_STYPE_DN_CELLNOISE}, + {"BlenderOriginal", TEX_BLENDER}, + {"OriginalPerlin", TEX_STDPERLIN}, + {"ImprovedPerlin", TEX_NEWPERLIN}, + {"VoronoiF1", TEX_VORONOI_F1}, + {"VoronoiF2", TEX_VORONOI_F2}, + {"VoronoiF3", TEX_VORONOI_F3}, + {"VoronoiF4", TEX_VORONOI_F4}, + {"VoronoiF2-F1", TEX_VORONOI_F2F1}, + {"VoronoiCrackle", TEX_VORONOI_CRACKLE}, + {"CellNoise", TEX_CELLNOISE}, {NULL, 0} }; @@ -311,13 +313,13 @@ static const EXPP_map_pair tex_stype_voronoi_map[] = { static const EXPP_map_pair tex_distance_voronoi_map[] = { {"Default", 0}, - {"Distance", EXPP_TEX_STYPE_VN_TEX_DISTANCE}, - {"DistanceSquared", EXPP_TEX_STYPE_VN_TEX_DISTANCE_SQUARED}, - {"Manhattan", EXPP_TEX_STYPE_VN_TEX_MANHATTAN}, - {"Chebychev", EXPP_TEX_STYPE_VN_TEX_CHEBYCHEV}, - {"MinkovskyHalf", EXPP_TEX_STYPE_VN_TEX_MINKOVSKY_HALF}, - {"MinkovskyFour", EXPP_TEX_STYPE_VN_TEX_MINKOVSKY_FOUR}, - {"Minkovsky", EXPP_TEX_STYPE_VN_TEX_MINKOVSKY}, + {"Distance", TEX_DISTANCE}, + {"DistanceSquared", TEX_DISTANCE_SQUARED}, + {"Manhattan", TEX_MANHATTAN}, + {"Chebychev", TEX_CHEBYCHEV}, + {"MinkovskyHalf", TEX_MINKOVSKY_HALF}, + {"MinkovskyFour", TEX_MINKOVSKY_FOUR}, + {"Minkovsky", TEX_MINKOVSKY}, {NULL, 0} }; @@ -339,7 +341,6 @@ static const EXPP_map_pair *tex_stype_map[] = { tex_distance_voronoi_map }; - /*****************************************************************************/ /* Python API function prototypes for the Texture module. */ /*****************************************************************************/ @@ -378,17 +379,73 @@ struct PyMethodDef M_Texture_methods[] = { /* Python BPy_Texture methods declarations: */ /*****************************************************************************/ #define GETFUNC(name) static PyObject *Texture_##name(BPy_Texture *self) -#define SETFUNC(name) static PyObject *Texture_##name(BPy_Texture *self, \ +#define OLDSETFUNC(name) static PyObject *Texture_old##name(BPy_Texture *self, \ PyObject *args) - +#define SETFUNC(name) static int Texture_##name(BPy_Texture *self, \ + PyObject *value) +#if 0 GETFUNC( getExtend ); GETFUNC( getImage ); GETFUNC( getName ); GETFUNC( getType ); GETFUNC( getSType ); -GETFUNC( getIpo ); GETFUNC( clearIpo ); -SETFUNC( setIpo ); +#endif + +GETFUNC( oldgetSType ); +GETFUNC( oldgetType ); + +GETFUNC( clearIpo ); +GETFUNC( getAnimFrames ); +GETFUNC( getAnimLength ); +GETFUNC( getAnimMontage ); +GETFUNC( getAnimOffset ); +GETFUNC( getAnimStart ); +GETFUNC( getBrightness ); +GETFUNC( getContrast ); +GETFUNC( getCrop ); +GETFUNC( getDistAmnt ); +GETFUNC( getDistMetric ); +GETFUNC( getExp ); +GETFUNC( getExtend ); +GETFUNC( getIntExtend ); +GETFUNC( getFieldsPerImage ); +GETFUNC( getFilterSize ); +GETFUNC( getFlags ); +GETFUNC( getHFracDim ); +GETFUNC( getImage ); +GETFUNC( getIpo ); +GETFUNC( getIScale ); +GETFUNC( getLacunarity ); +GETFUNC( getName ); +GETFUNC( getNoiseBasis ); +GETFUNC( getNoiseDepth ); +GETFUNC( getNoiseSize ); +GETFUNC( getNoiseType ); +GETFUNC( getOcts ); +GETFUNC( getRepeat ); +GETFUNC( getRGBCol ); +GETFUNC( getSType ); +GETFUNC( getTurbulence ); +GETFUNC( getType ); +GETFUNC( getWeight1 ); +GETFUNC( getWeight2 ); +GETFUNC( getWeight3 ); +GETFUNC( getWeight4 ); +GETFUNC( getUsers ); + +OLDSETFUNC( setDistMetric ); +OLDSETFUNC( setDistNoise ); /* special case used for ".noisebasis = ... */ +OLDSETFUNC( setExtend ); +OLDSETFUNC( setFlags ); +OLDSETFUNC( setImage ); +OLDSETFUNC( setImageFlags ); +OLDSETFUNC( setIpo ); +OLDSETFUNC( setName ); +OLDSETFUNC( setNoiseBasis ); +OLDSETFUNC( setSType ); +OLDSETFUNC( setType ); + SETFUNC( setAnimFrames ); SETFUNC( setAnimLength ); SETFUNC( setAnimMontage ); @@ -397,30 +454,40 @@ SETFUNC( setAnimStart ); SETFUNC( setBrightness ); SETFUNC( setContrast ); SETFUNC( setCrop ); -SETFUNC( setExtend ); -SETFUNC( setIntExtend ); /* special case used for ".extend = ..." */ +SETFUNC( setDistAmnt ); +SETFUNC( setDistMetric ); +SETFUNC( setExp ); +SETFUNC( setIntExtend ); SETFUNC( setFieldsPerImage ); SETFUNC( setFilterSize ); SETFUNC( setFlags ); -SETFUNC( setIntFlags ); /* special case used for ".flags = ..." */ +SETFUNC( setHFracDim ); SETFUNC( setImage ); -SETFUNC( setImageFlags ); -SETFUNC( setIntImageFlags ); /* special case used for ".imageFlags = ..." */ +SETFUNC( setIpo ); +SETFUNC( setIScale ); +SETFUNC( setLacunarity ); SETFUNC( setName ); +SETFUNC( setNoiseBasis ); SETFUNC( setNoiseDepth ); SETFUNC( setNoiseSize ); SETFUNC( setNoiseType ); -SETFUNC( setNoiseBasis ); /* special case used for ".noisebasis or noisebasis2 = ... */ -SETFUNC( setDistNoise ); /* special case used for ".noisebasis = ... */ +SETFUNC( setOcts ); SETFUNC( setRepeat ); SETFUNC( setRGBCol ); SETFUNC( setSType ); -SETFUNC( setIntSType ); /* special case used for ".stype = ..." */ -SETFUNC( setType ); -SETFUNC( setIntType ); /* special case used for ".type = ..." */ SETFUNC( setTurbulence ); -SETFUNC( setDistMetric ); -SETFUNC( setDistAmnt ); +SETFUNC( setType ); +SETFUNC( setWeight1 ); +SETFUNC( setWeight2 ); +SETFUNC( setWeight3 ); +SETFUNC( setWeight4 ); + +static PyObject *Texture_getImageFlags( BPy_Texture *self, void *type ); +static PyObject *Texture_getNoiseBasis2( BPy_Texture *self, void *type ); +static int Texture_setImageFlags( BPy_Texture *self, PyObject *args, + void *type ); +static int Texture_setNoiseBasis2( BPy_Texture *self, PyObject *args, + void *type ); /*****************************************************************************/ /* Python BPy_Texture methods table: */ @@ -433,74 +500,345 @@ static PyMethodDef BPy_Texture_methods[] = { "() - Return Texture Image"}, {"getName", ( PyCFunction ) Texture_getName, METH_NOARGS, "() - Return Texture name"}, - {"getSType", ( PyCFunction ) Texture_getSType, METH_NOARGS, + {"getSType", ( PyCFunction ) Texture_oldgetSType, METH_NOARGS, "() - Return Texture stype as string"}, - {"getType", ( PyCFunction ) Texture_getType, METH_NOARGS, + {"getType", ( PyCFunction ) Texture_oldgetType, METH_NOARGS, "() - Return Texture type as string"}, {"getIpo", ( PyCFunction ) Texture_getIpo, METH_NOARGS, "() - Return Texture Ipo"}, - {"setIpo", ( PyCFunction ) Texture_setIpo, METH_VARARGS, + {"setIpo", ( PyCFunction ) Texture_oldsetIpo, METH_VARARGS, "(Blender Ipo) - Set Texture Ipo"}, {"clearIpo", ( PyCFunction ) Texture_clearIpo, METH_NOARGS, "() - Unlink Ipo from this Texture."}, - {"setExtend", ( PyCFunction ) Texture_setExtend, METH_VARARGS, + {"setExtend", ( PyCFunction ) Texture_oldsetExtend, METH_VARARGS, "(s) - Set Texture extend mode"}, - {"setFlags", ( PyCFunction ) Texture_setFlags, METH_VARARGS, - "(f1,f2,f3) - Set Texture flags"}, - {"setImage", ( PyCFunction ) Texture_setImage, METH_VARARGS, + {"setFlags", ( PyCFunction ) Texture_oldsetFlags, METH_VARARGS, + "(f1,f2,f3,f4,f5) - Set Texture flags"}, + {"setImage", ( PyCFunction ) Texture_oldsetImage, METH_VARARGS, "(Blender Image) - Set Texture Image"}, - {"setImageFlags", ( PyCFunction ) Texture_setImageFlags, METH_VARARGS, + {"setImageFlags", ( PyCFunction ) Texture_oldsetImageFlags, METH_VARARGS, "(s,s,s,s,...) - Set Texture image flags"}, - {"setName", ( PyCFunction ) Texture_setName, METH_VARARGS, + {"setName", ( PyCFunction ) Texture_oldsetName, METH_VARARGS, "(s) - Set Texture name"}, - {"setSType", ( PyCFunction ) Texture_setSType, METH_VARARGS, + {"setSType", ( PyCFunction ) Texture_oldsetSType, METH_VARARGS, "(s) - Set Texture stype"}, - {"setType", ( PyCFunction ) Texture_setType, METH_VARARGS, + {"setType", ( PyCFunction ) Texture_oldsetType, METH_VARARGS, "(s) - Set Texture type"}, - {"setNoiseBasis", ( PyCFunction ) Texture_setNoiseBasis, METH_VARARGS, + {"setNoiseBasis", ( PyCFunction ) Texture_oldsetNoiseBasis, METH_VARARGS, "(s) - Set Noise basis"}, - {"setDistNoise", ( PyCFunction ) Texture_setDistNoise, METH_VARARGS, + {"setDistNoise", ( PyCFunction ) Texture_oldsetDistNoise, METH_VARARGS, "(s) - Set Dist Noise"}, - {"setDistMetric", ( PyCFunction ) Texture_setDistMetric, METH_VARARGS, + {"setDistMetric", ( PyCFunction ) Texture_oldsetDistMetric, METH_VARARGS, "(s) - Set Dist Metric"}, {NULL, NULL, 0, NULL} }; /*****************************************************************************/ +/* Python Texture_Type attributes get/set structure: */ +/*****************************************************************************/ +static PyGetSetDef BPy_Texture_getseters[] = { + {"animFrames", + (getter)Texture_getAnimFrames, (setter)Texture_setAnimFrames, + "Number of frames of a movie to use", + NULL}, + {"animLength", + (getter)Texture_getAnimLength, (setter)Texture_setAnimLength, + "Number of frames of a movie to use (0 for all)", + NULL}, + {"animMontage", + (getter)Texture_getAnimMontage, (setter)Texture_setAnimMontage, + "Montage mode, start frames and durations", + NULL}, + {"animOffset", + (getter)Texture_getAnimOffset, (setter)Texture_setAnimOffset, + "Offsets the number of the first movie frame to use", + NULL}, + {"animStart", + (getter)Texture_getAnimStart, (setter)Texture_setAnimStart, + "Starting frame of the movie to use", + NULL}, + {"brightness", + (getter)Texture_getBrightness, (setter)Texture_setBrightness, + "Changes the brightness of a texture's color", + NULL}, + {"contrast", + (getter)Texture_getContrast, (setter)Texture_setContrast, + "Changes the contrast of a texture's color", + NULL}, + {"crop", + (getter)Texture_getCrop, (setter)Texture_setCrop, + "Sets the cropping extents (for image textures)", + NULL}, + {"distAmnt", + (getter)Texture_getDistAmnt, (setter)Texture_setDistAmnt, + "Amount of distortion (for distorted noise textures)", + NULL}, + {"distMetric", + (getter)Texture_getDistMetric, (setter)Texture_setDistMetric, + "The distance metric (for Voronoi textures)", + NULL}, + {"exp", + (getter)Texture_getExp, (setter)Texture_setExp, + "Minkovsky exponent (for Minkovsky Voronoi textures)", + NULL}, + {"extend", + (getter)Texture_getIntExtend, (setter)Texture_setIntExtend, + "Texture's 'Extend' mode (for image textures)", + NULL}, + {"fieldsPerImage", + (getter)Texture_getFieldsPerImage, (setter)Texture_setFieldsPerImage, + "Number of fields per rendered frame", + NULL}, + {"filterSize", + (getter)Texture_getFilterSize, (setter)Texture_setFilterSize, + "The filter size (for image and envmap textures)", + NULL}, + {"flags", + (getter)Texture_getFlags, (setter)Texture_setFlags, + "Texture's 'Flag' bits", + NULL}, + {"hFracDim", + (getter)Texture_getHFracDim, (setter)Texture_setHFracDim, + "Highest fractional dimension (for Musgrave textures)", + NULL}, + {"imageFlags", + (getter)Texture_getImageFlags, (setter)Texture_setImageFlags, + "Texture's 'ImageFlags' bits", + NULL}, + {"image", + (getter)Texture_getImage, (setter)Texture_setImage, + "Texture's image object", + NULL}, + {"ipo", + (getter)Texture_getIpo, (setter)Texture_setIpo, + "Texture Ipo data", + NULL}, + {"iScale", + (getter)Texture_getIScale, (setter)Texture_setIScale, + "Intensity output scale (for Musgrave and Voronoi textures)", + NULL}, + {"lacunarity", + (getter)Texture_getLacunarity, (setter)Texture_setLacunarity, + "Gap between succesive frequencies (for Musgrave textures)", + NULL}, + {"name", + (getter)Texture_getName, (setter)Texture_setName, + "Texture data name", + NULL}, + {"noiseBasis", + (getter)Texture_getNoiseBasis, (setter)Texture_setNoiseBasis, + "Noise basis type (wood, stucci, marble, clouds, Musgrave, distorted noise)", + NULL}, + {"noiseBasis2", + (getter)Texture_getNoiseBasis2, (setter)Texture_setNoiseBasis2, + "Additional noise basis type (wood, marble, distorted noise)", + (void *)EXPP_TEX_NOISEBASIS2}, + {"noiseDepth", + (getter)Texture_getNoiseDepth, (setter)Texture_setNoiseDepth, + "Noise depth (magic, marble, clouds)", + NULL}, + {"noiseSize", + (getter)Texture_getNoiseSize, (setter)Texture_setNoiseSize, + "Noise size (wood, stucci, marble, clouds, Musgrave, distorted noise, Voronoi)", + NULL}, +/* NOTE for API rewrite: should use dict constants instead of strings */ + {"noiseType", + (getter)Texture_getNoiseType, (setter)Texture_setNoiseType, + "Noise type (for wood, stucci, marble, clouds textures)", + NULL}, + {"octs", + (getter)Texture_getOcts, (setter)Texture_setOcts, + "Number of frequencies (for Musgrave textures)", + NULL}, + {"repeat", + (getter)Texture_getRepeat, (setter)Texture_setRepeat, + "Repetition multiplier (for image textures)", + NULL}, + {"rgbCol", + (getter)Texture_getRGBCol, (setter)Texture_setRGBCol, + "RGB color tuple", + NULL}, + {"stype", + (getter)Texture_getSType, (setter)Texture_setSType, + "Texture's 'SType' mode", + NULL}, + {"turbulence", + (getter)Texture_getTurbulence, (setter)Texture_setTurbulence, + "Turbulence (for magic, wood, stucci, marble textures)", + NULL}, + {"type", + (getter)Texture_getType, (setter)Texture_setType, + "Texture's 'Type' mode", + NULL}, + {"users", + (getter)Texture_getUsers, (setter)NULL, + "Number of texture users", + NULL}, + {"weight1", + (getter)Texture_getWeight1, (setter)Texture_setWeight1, + "Weight 1 (for Voronoi textures)", + NULL}, + {"weight2", + (getter)Texture_getWeight2, (setter)Texture_setWeight2, + "Weight 2 (for Voronoi textures)", + NULL}, + {"weight3", + (getter)Texture_getWeight3, (setter)Texture_setWeight3, + "Weight 3 (for Voronoi textures)", + NULL}, + {"weight4", + (getter)Texture_getWeight4, (setter)Texture_setWeight4, + "Weight 4 (for Voronoi textures)", + NULL}, + {"sine", + (getter)Texture_getNoiseBasis2, (setter)Texture_setNoiseBasis2, + "Produce bands using sine wave (marble, wood textures)", + (void *)EXPP_TEX_NOISE_SINE}, + {"saw", + (getter)Texture_getNoiseBasis2, (setter)Texture_setNoiseBasis2, + "Produce bands using saw wave (marble, wood textures)", + (void *)EXPP_TEX_NOISE_SAW}, + {"tri", + (getter)Texture_getNoiseBasis2, (setter)Texture_setNoiseBasis2, + "Produce bands using triangle wave (marble, wood textures)", + (void *)EXPP_TEX_NOISE_TRI}, + {"interpol", + (getter)Texture_getImageFlags, (setter)Texture_setImageFlags, + "Interpolate image's pixels to fit texture mapping enabled ('ImageFlags')", + (void *)TEX_INTERPOL}, + {"useAlpha", + (getter)Texture_getImageFlags, (setter)Texture_setImageFlags, + "Use of image's alpha channel enabled ('ImageFlags')", + (void *)TEX_USEALPHA}, + {"calcAlpha", + (getter)Texture_getImageFlags, (setter)Texture_setImageFlags, + "Calculation of image's alpha channel enabled ('ImageFlags')", + (void *)TEX_CALCALPHA}, + {"mipmap", + (getter)Texture_getImageFlags, (setter)Texture_setImageFlags, + "Mipmaps enabled ('ImageFlags')", + (void *)TEX_MIPMAP}, + {"fields", + (getter)Texture_getImageFlags, (setter)Texture_setImageFlags, + "Use of image's fields enabled ('ImageFlags')", + (void *)TEX_FIELDS}, + {"rot90", + (getter)Texture_getImageFlags, (setter)Texture_setImageFlags, + "X/Y flip for rendering enabled ('ImageFlags')", + (void *)TEX_IMAROT}, + {"cyclic", + (getter)Texture_getImageFlags, (setter)Texture_setImageFlags, + "Looping of animated frames enabled ('ImageFlags')", + (void *)TEX_ANIMCYCLIC}, + {"movie", + (getter)Texture_getImageFlags, (setter)Texture_setImageFlags, + "Movie frames as images enabled ('ImageFlags')", + (void *)TEX_ANIM5}, + {"anti", + (getter)Texture_getImageFlags, (setter)Texture_setImageFlags, + "Image anti-aliasing enabled ('ImageFlags')", + (void *)TEX_ANTIALI}, + {"stField", + (getter)Texture_getImageFlags, (setter)Texture_setImageFlags, + "Standard field deinterlacing enabled ('ImageFlags')", + (void *)TEX_STD_FIELD}, + {"normalMap", + (getter)Texture_getImageFlags, (setter)Texture_setImageFlags, + "Use of image RGB values for normal mapping enabled ('ImageFlags')", + (void *)TEX_NORMALMAP}, + {NULL,NULL,NULL,NULL,NULL} /* Sentinel */ +}; + +/*****************************************************************************/ /* Python Texture_Type callback function prototypes: */ /*****************************************************************************/ static void Texture_dealloc( BPy_Texture * self ); -static int Texture_setAttr( BPy_Texture * self, char *name, PyObject * v ); static int Texture_compare( BPy_Texture * a, BPy_Texture * b ); -static PyObject *Texture_getAttr( BPy_Texture * self, char *name ); static PyObject *Texture_repr( BPy_Texture * self ); - /*****************************************************************************/ /* Python Texture_Type structure definition: */ /*****************************************************************************/ PyTypeObject Texture_Type = { - PyObject_HEAD_INIT( NULL ) 0, /* ob_size */ - "Blender Texture", /* tp_name */ - sizeof( BPy_Texture ), /* tp_basicsize */ - 0, /* tp_itemsize */ - /* methods */ - ( destructor ) Texture_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - ( getattrfunc ) Texture_getAttr, /* tp_getattr */ - ( setattrfunc ) Texture_setAttr, /* tp_setattr */ - ( cmpfunc ) Texture_compare, /* tp_compare */ - ( reprfunc ) Texture_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_as_hash */ - 0, 0, 0, 0, 0, 0, - 0, /* tp_doc */ - 0, 0, 0, 0, 0, 0, - BPy_Texture_methods, /* tp_methods */ - 0, /* tp_members */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + PyObject_HEAD_INIT( NULL ) /* required py macro */ + 0, /* ob_size */ + /* For printing, in format "<module>.<name>" */ + "Blender Texture", /* char *tp_name; */ + sizeof( BPy_Texture ), /* int tp_basicsize; */ + 0, /* tp_itemsize; For allocation */ + + /* Methods to implement standard operations */ + + ( destructor ) Texture_dealloc,/* destructor tp_dealloc; */ + NULL, /* printfunc tp_print; */ + NULL, /* getattrfunc tp_getattr; */ + NULL, /* setattrfunc tp_setattr; */ + ( cmpfunc ) Texture_compare, /* cmpfunc tp_compare; */ + ( reprfunc ) Texture_repr, /* reprfunc tp_repr; */ + + /* Method suites for standard classes */ + + NULL, /* PyNumberMethods *tp_as_number; */ + NULL, /* PySequenceMethods *tp_as_sequence; */ + NULL, /* PyMappingMethods *tp_as_mapping; */ + + /* More standard operations (here for binary compatibility) */ + + NULL, /* hashfunc tp_hash; */ + NULL, /* ternaryfunc tp_call; */ + NULL, /* reprfunc tp_str; */ + NULL, /* getattrofunc tp_getattro; */ + NULL, /* setattrofunc tp_setattro; */ + + /* Functions to access object as input/output buffer */ + NULL, /* PyBufferProcs *tp_as_buffer; */ + + /*** Flags to define presence of optional/expanded features ***/ + Py_TPFLAGS_DEFAULT, /* long tp_flags; */ + + NULL, /* char *tp_doc; Documentation string */ + /*** Assigned meaning in release 2.0 ***/ + /* call function for all accessible objects */ + NULL, /* traverseproc tp_traverse; */ + + /* delete references to contained objects */ + NULL, /* inquiry tp_clear; */ + + /*** Assigned meaning in release 2.1 ***/ + /*** rich comparisons ***/ + NULL, /* richcmpfunc tp_richcompare; */ + + /*** weak reference enabler ***/ + 0, /* long tp_weaklistoffset; */ + + /*** Added in release 2.2 ***/ + /* Iterators */ + NULL, /* getiterfunc tp_iter; */ + NULL, /* iternextfunc tp_iternext; */ + + /*** Attribute descriptor and subclassing stuff ***/ + BPy_Texture_methods, /* struct PyMethodDef *tp_methods; */ + NULL, /* struct PyMemberDef *tp_members; */ + BPy_Texture_getseters, /* struct PyGetSetDef *tp_getset; */ + NULL, /* struct _typeobject *tp_base; */ + NULL, /* PyObject *tp_dict; */ + NULL, /* descrgetfunc tp_descr_get; */ + NULL, /* descrsetfunc tp_descr_set; */ + 0, /* long tp_dictoffset; */ + NULL, /* initproc tp_init; */ + NULL, /* allocfunc tp_alloc; */ + NULL, /* newfunc tp_new; */ + /* Low-level free-memory routine */ + NULL, /* freefunc tp_free; */ + /* For PyObject_IS_GC */ + NULL, /* inquiry tp_is_gc; */ + NULL, /* PyObject *tp_bases; */ + /* method resolution order */ + NULL, /* PyObject *tp_mro; */ + NULL, /* PyObject *tp_cache; */ + NULL, /* PyObject *tp_subclasses; */ + NULL, /* PyObject *tp_weaklist; */ + NULL }; static PyObject *M_Texture_New( PyObject * self, PyObject * args, @@ -597,213 +935,266 @@ static PyObject *M_Texture_Get( PyObject * self, PyObject * args ) } } +static int Texture_compare( BPy_Texture * a, BPy_Texture * b ) +{ + return ( a->texture == b->texture ) ? 0 : -1; +} + +static PyObject *Texture_repr( BPy_Texture * self ) +{ + return PyString_FromFormat( "[Texture \"%s\"]", + self->texture->id.name + 2 ); +} -#undef EXPP_ADDCONST -#define EXPP_ADDCONST(name) \ - PyConstant_Insert(d, #name, PyInt_FromLong(EXPP_TEX_TYPE_##name)) +static void Texture_dealloc( BPy_Texture * self ) +{ + PyObject_DEL( self ); +} static PyObject *M_Texture_TypesDict( void ) { PyObject *Types = PyConstant_New( ); if( Types ) { BPy_constant *d = ( BPy_constant * ) Types; - - EXPP_ADDCONST( NONE ); - EXPP_ADDCONST( CLOUDS ); - EXPP_ADDCONST( WOOD ); - EXPP_ADDCONST( MARBLE ); - EXPP_ADDCONST( MAGIC ); - EXPP_ADDCONST( BLEND ); - EXPP_ADDCONST( STUCCI ); - EXPP_ADDCONST( NOISE ); - EXPP_ADDCONST( IMAGE ); - EXPP_ADDCONST( PLUGIN ); - EXPP_ADDCONST( ENVMAP ); - EXPP_ADDCONST( MUSGRAVE ); - EXPP_ADDCONST( VORONOI ); - EXPP_ADDCONST( DISTNOISE ); + PyConstant_Insert(d, "NONE", PyInt_FromLong(EXPP_TEX_TYPE_NONE)); + PyConstant_Insert(d, "CLOUDS", PyInt_FromLong(TEX_CLOUDS)); + PyConstant_Insert(d, "WOOD", PyInt_FromLong(TEX_WOOD)); + PyConstant_Insert(d, "MARBLE", PyInt_FromLong(TEX_MARBLE)); + PyConstant_Insert(d, "MAGIC", PyInt_FromLong(TEX_MAGIC)); + PyConstant_Insert(d, "BLEND", PyInt_FromLong(TEX_BLEND)); + PyConstant_Insert(d, "STUCCI", PyInt_FromLong(TEX_STUCCI)); + PyConstant_Insert(d, "NOISE", PyInt_FromLong(TEX_NOISE)); + PyConstant_Insert(d, "IMAGE", PyInt_FromLong(TEX_IMAGE)); + PyConstant_Insert(d, "PLUGIN", PyInt_FromLong(TEX_PLUGIN)); + PyConstant_Insert(d, "ENVMAP", PyInt_FromLong(TEX_ENVMAP)); + PyConstant_Insert(d, "MUSGRAVE", PyInt_FromLong(TEX_MUSGRAVE)); + PyConstant_Insert(d, "VORONOI", PyInt_FromLong(TEX_VORONOI)); + PyConstant_Insert(d, "DISTNOISE", PyInt_FromLong(TEX_DISTNOISE)); } return Types; } -#undef EXPP_ADDCONST -#define EXPP_ADDCONST(name) \ - PyConstant_Insert(d, #name, PyInt_FromLong(EXPP_TEX_STYPE_##name)) - static PyObject *M_Texture_STypesDict( void ) { PyObject *STypes = PyConstant_New( ); if( STypes ) { BPy_constant *d = ( BPy_constant * ) STypes; - EXPP_ADDCONST( CLD_DEFAULT ); - EXPP_ADDCONST( CLD_COLOR ); - EXPP_ADDCONST( WOD_BANDS ); - EXPP_ADDCONST( WOD_RINGS ); - EXPP_ADDCONST( WOD_BANDNOISE ); - EXPP_ADDCONST( WOD_RINGNOISE ); - EXPP_ADDCONST( MAG_DEFAULT ); - EXPP_ADDCONST( MBL_SOFT ); - EXPP_ADDCONST( MBL_SHARP ); - EXPP_ADDCONST( MBL_SHARPER ); - EXPP_ADDCONST( BLN_LIN ); - EXPP_ADDCONST( BLN_QUAD ); - EXPP_ADDCONST( BLN_EASE ); - EXPP_ADDCONST( BLN_DIAG ); - EXPP_ADDCONST( BLN_SPHERE ); - EXPP_ADDCONST( BLN_HALO ); - EXPP_ADDCONST( STC_PLASTIC ); - EXPP_ADDCONST( STC_WALLIN ); - EXPP_ADDCONST( STC_WALLOUT ); - EXPP_ADDCONST( NSE_DEFAULT ); - EXPP_ADDCONST( IMG_DEFAULT ); - EXPP_ADDCONST( PLG_DEFAULT ); - EXPP_ADDCONST( ENV_STATIC ); - EXPP_ADDCONST( ENV_ANIM ); - EXPP_ADDCONST( ENV_LOAD ); - EXPP_ADDCONST( MUS_MFRACTAL ); - EXPP_ADDCONST( MUS_RIDGEDMF ); - EXPP_ADDCONST( MUS_HYBRIDMF ); - EXPP_ADDCONST( MUS_FBM ); - EXPP_ADDCONST( MUS_HTERRAIN ); - EXPP_ADDCONST( DN_BLENDER ); - EXPP_ADDCONST( DN_PERLIN ); - EXPP_ADDCONST( DN_IMPROVEPERLIN ); - EXPP_ADDCONST( DN_VORONOIF1 ); - EXPP_ADDCONST( DN_VORONOIF2 ); - EXPP_ADDCONST( DN_VORONOIF3 ); - EXPP_ADDCONST( DN_VORONOIF4 ); - EXPP_ADDCONST( DN_VORONOIF2F1 ); - EXPP_ADDCONST( DN_VORONOICRACKLE ); - EXPP_ADDCONST( DN_CELLNOISE ); - EXPP_ADDCONST( VN_INT ); - EXPP_ADDCONST( VN_COL1 ); - EXPP_ADDCONST( VN_COL2 ); - EXPP_ADDCONST( VN_COL3 ); - EXPP_ADDCONST( VN_TEX_DISTANCE ); - EXPP_ADDCONST( VN_TEX_DISTANCE_SQUARED ); - EXPP_ADDCONST( VN_TEX_MANHATTAN ); - EXPP_ADDCONST( VN_TEX_CHEBYCHEV ); - EXPP_ADDCONST( VN_TEX_MINKOVSKY_HALF ); - EXPP_ADDCONST( VN_TEX_MINKOVSKY_FOUR ); - EXPP_ADDCONST( VN_TEX_MINKOVSKY ); + PyConstant_Insert(d, "CLD_DEFAULT", + PyInt_FromLong(EXPP_TEX_STYPE_CLD_DEFAULT)); + PyConstant_Insert(d, "CLD_COLOR", + PyInt_FromLong(EXPP_TEX_STYPE_CLD_COLOR)); + PyConstant_Insert(d, "WOD_BANDS", + PyInt_FromLong(EXPP_TEX_STYPE_WOD_BANDS)); + PyConstant_Insert(d, "WOD_RINGS", + PyInt_FromLong(EXPP_TEX_STYPE_WOD_RINGS)); + PyConstant_Insert(d, "WOD_BANDNOISE", + PyInt_FromLong(EXPP_TEX_STYPE_WOD_BANDNOISE)); + PyConstant_Insert(d, "WOD_RINGNOISE", + PyInt_FromLong(EXPP_TEX_STYPE_WOD_RINGNOISE)); + PyConstant_Insert(d, "MAG_DEFAULT", + PyInt_FromLong(EXPP_TEX_STYPE_MAG_DEFAULT)); + PyConstant_Insert(d, "MBL_SOFT", + PyInt_FromLong(EXPP_TEX_STYPE_MBL_SOFT)); + PyConstant_Insert(d, "MBL_SHARP", + PyInt_FromLong(EXPP_TEX_STYPE_MBL_SHARP)); + PyConstant_Insert(d, "MBL_SHARPER", + PyInt_FromLong(EXPP_TEX_STYPE_MBL_SHARPER)); + PyConstant_Insert(d, "BLN_LIN", + PyInt_FromLong(EXPP_TEX_STYPE_BLN_LIN)); + PyConstant_Insert(d, "BLN_QUAD", + PyInt_FromLong(EXPP_TEX_STYPE_BLN_QUAD)); + PyConstant_Insert(d, "BLN_EASE", + PyInt_FromLong(EXPP_TEX_STYPE_BLN_EASE)); + PyConstant_Insert(d, "BLN_DIAG", + PyInt_FromLong(EXPP_TEX_STYPE_BLN_DIAG)); + PyConstant_Insert(d, "BLN_SPHERE", + PyInt_FromLong(EXPP_TEX_STYPE_BLN_SPHERE)); + PyConstant_Insert(d, "BLN_HALO", + PyInt_FromLong(EXPP_TEX_STYPE_BLN_HALO)); + PyConstant_Insert(d, "STC_PLASTIC", + PyInt_FromLong(EXPP_TEX_STYPE_STC_PLASTIC)); + PyConstant_Insert(d, "STC_WALLIN", + PyInt_FromLong(EXPP_TEX_STYPE_STC_WALLIN)); + PyConstant_Insert(d, "STC_WALLOUT", + PyInt_FromLong(EXPP_TEX_STYPE_STC_WALLOUT)); + PyConstant_Insert(d, "NSE_DEFAULT", + PyInt_FromLong(EXPP_TEX_STYPE_NSE_DEFAULT)); + PyConstant_Insert(d, "IMG_DEFAULT", + PyInt_FromLong(EXPP_TEX_STYPE_IMG_DEFAULT)); + PyConstant_Insert(d, "PLG_DEFAULT", + PyInt_FromLong(EXPP_TEX_STYPE_PLG_DEFAULT)); + PyConstant_Insert(d, "ENV_STATIC", + PyInt_FromLong(EXPP_TEX_STYPE_ENV_STATIC)); + PyConstant_Insert(d, "ENV_ANIM", + PyInt_FromLong(EXPP_TEX_STYPE_ENV_ANIM)); + PyConstant_Insert(d, "ENV_LOAD", + PyInt_FromLong(EXPP_TEX_STYPE_ENV_LOAD)); + PyConstant_Insert(d, "MUS_MFRACTAL", + PyInt_FromLong(EXPP_TEX_STYPE_MUS_MFRACTAL)); + PyConstant_Insert(d, "MUS_RIDGEDMF", + PyInt_FromLong(EXPP_TEX_STYPE_MUS_RIDGEDMF)); + PyConstant_Insert(d, "MUS_HYBRIDMF", + PyInt_FromLong(EXPP_TEX_STYPE_MUS_HYBRIDMF)); + PyConstant_Insert(d, "MUS_FBM", + PyInt_FromLong(EXPP_TEX_STYPE_MUS_FBM)); + PyConstant_Insert(d, "MUS_HTERRAIN", + PyInt_FromLong(EXPP_TEX_STYPE_MUS_HTERRAIN)); + PyConstant_Insert(d, "DN_BLENDER", + PyInt_FromLong(TEX_BLENDER)); + PyConstant_Insert(d, "DN_PERLIN", + PyInt_FromLong(TEX_STDPERLIN)); + PyConstant_Insert(d, "DN_IMPROVEPERLIN", + PyInt_FromLong(TEX_NEWPERLIN)); + PyConstant_Insert(d, "DN_VORONOIF1", + PyInt_FromLong(TEX_VORONOI_F1)); + PyConstant_Insert(d, "DN_VORONOIF2", + PyInt_FromLong(TEX_VORONOI_F2)); + PyConstant_Insert(d, "DN_VORONOIF3", + PyInt_FromLong(TEX_VORONOI_F3)); + PyConstant_Insert(d, "DN_VORONOIF4", + PyInt_FromLong(TEX_VORONOI_F4)); + PyConstant_Insert(d, "DN_VORONOIF2F1", + PyInt_FromLong(TEX_VORONOI_F2F1)); + PyConstant_Insert(d, "DN_VORONOICRACKLE", + PyInt_FromLong(TEX_VORONOI_CRACKLE)); + PyConstant_Insert(d, "DN_CELLNOISE", + PyInt_FromLong(TEX_CELLNOISE)); + PyConstant_Insert(d, "VN_INT", + PyInt_FromLong(EXPP_TEX_STYPE_VN_INT)); + PyConstant_Insert(d, "VN_COL1", + PyInt_FromLong(EXPP_TEX_STYPE_VN_COL1)); + PyConstant_Insert(d, "VN_COL2", + PyInt_FromLong(EXPP_TEX_STYPE_VN_COL2)); + PyConstant_Insert(d, "VN_COL3", + PyInt_FromLong(EXPP_TEX_STYPE_VN_COL3)); + PyConstant_Insert(d, "VN_TEX_DISTANCE", + PyInt_FromLong(TEX_DISTANCE)); + PyConstant_Insert(d, "VN_TEX_DISTANCE_SQUARED", + PyInt_FromLong(TEX_DISTANCE_SQUARED)); + PyConstant_Insert(d, "VN_TEX_MANHATTAN", + PyInt_FromLong(TEX_MANHATTAN)); + PyConstant_Insert(d, "VN_TEX_CHEBYCHEV", + PyInt_FromLong(TEX_CHEBYCHEV)); + PyConstant_Insert(d, "VN_TEX_MINKOVSKY_HALF", + PyInt_FromLong(TEX_MINKOVSKY_HALF)); + PyConstant_Insert(d, "VN_TEX_MINKOVSKY_FOUR", + PyInt_FromLong(TEX_MINKOVSKY_FOUR)); + PyConstant_Insert(d, "VN_TEX_MINKOVSKY", + PyInt_FromLong(TEX_MINKOVSKY)); + } return STypes; } -#undef EXPP_ADDCONST -#define EXPP_ADDCONST(name) \ - PyConstant_Insert(d, #name, PyInt_FromLong(EXPP_TEX_TEXCO_##name)) - static PyObject *M_Texture_TexCoDict( void ) { PyObject *TexCo = PyConstant_New( ); if( TexCo ) { BPy_constant *d = ( BPy_constant * ) TexCo; - - EXPP_ADDCONST( ORCO ); - EXPP_ADDCONST( REFL ); - EXPP_ADDCONST( NOR ); - EXPP_ADDCONST( GLOB ); - EXPP_ADDCONST( UV ); - EXPP_ADDCONST( OBJECT ); - EXPP_ADDCONST( WIN ); - EXPP_ADDCONST( VIEW ); - EXPP_ADDCONST( STICK ); + PyConstant_Insert(d, "ORCO", PyInt_FromLong(TEXCO_ORCO)); + PyConstant_Insert(d, "REFL", PyInt_FromLong(TEXCO_REFL)); + PyConstant_Insert(d, "NOR", PyInt_FromLong(TEXCO_NORM)); + PyConstant_Insert(d, "GLOB", PyInt_FromLong(TEXCO_GLOB)); + PyConstant_Insert(d, "UV", PyInt_FromLong(TEXCO_UV)); + PyConstant_Insert(d, "OBJECT", PyInt_FromLong(TEXCO_OBJECT)); + PyConstant_Insert(d, "WIN", PyInt_FromLong(TEXCO_WINDOW)); + PyConstant_Insert(d, "VIEW", PyInt_FromLong(TEXCO_VIEW)); + PyConstant_Insert(d, "STICK", PyInt_FromLong(TEXCO_STICKY)); } return TexCo; } - -#undef EXPP_ADDCONST -#define EXPP_ADDCONST(name) \ - PyConstant_Insert(d, #name, PyInt_FromLong(EXPP_TEX_MAPTO_##name)) - static PyObject *M_Texture_MapToDict( void ) { PyObject *MapTo = PyConstant_New( ); if( MapTo ) { BPy_constant *d = ( BPy_constant * ) MapTo; - - EXPP_ADDCONST( COL ); - EXPP_ADDCONST( NOR ); - EXPP_ADDCONST( CSP ); - EXPP_ADDCONST( CMIR ); - EXPP_ADDCONST( REF ); - EXPP_ADDCONST( SPEC ); - EXPP_ADDCONST( HARD ); - EXPP_ADDCONST( ALPHA ); - EXPP_ADDCONST( EMIT ); - EXPP_ADDCONST( RAYMIR ); - EXPP_ADDCONST( AMB ); - EXPP_ADDCONST( TRANSLU ); - EXPP_ADDCONST( DISP ); + PyConstant_Insert(d, "COL", PyInt_FromLong(MAP_COL)); + PyConstant_Insert(d, "NOR", PyInt_FromLong(MAP_NORM)); + PyConstant_Insert(d, "CSP", PyInt_FromLong(MAP_COLSPEC)); + PyConstant_Insert(d, "CMIR", PyInt_FromLong(MAP_COLMIR)); + PyConstant_Insert(d, "REF", PyInt_FromLong(MAP_REF)); + PyConstant_Insert(d, "SPEC", PyInt_FromLong(MAP_SPEC)); + PyConstant_Insert(d, "HARD", PyInt_FromLong(MAP_HAR)); + PyConstant_Insert(d, "ALPHA", PyInt_FromLong(MAP_ALPHA)); + PyConstant_Insert(d, "EMIT", PyInt_FromLong(MAP_EMIT)); + PyConstant_Insert(d, "RAYMIR", PyInt_FromLong(MAP_RAYMIRR)); + PyConstant_Insert(d, "AMB", PyInt_FromLong(MAP_AMB)); + PyConstant_Insert(d, "TRANSLU", PyInt_FromLong(MAP_TRANSLU)); + PyConstant_Insert(d, "DISP", PyInt_FromLong(MAP_DISPLACE)); } return MapTo; } - -#undef EXPP_ADDCONST -#define EXPP_ADDCONST(name) \ - PyConstant_Insert(d, #name, PyInt_FromLong(EXPP_TEX_FLAG_##name)) - static PyObject *M_Texture_FlagsDict( void ) { PyObject *Flags = PyConstant_New( ); if( Flags ) { BPy_constant *d = ( BPy_constant * ) Flags; - - EXPP_ADDCONST( COLORBAND ); - EXPP_ADDCONST( FLIPBLEND ); - EXPP_ADDCONST( NEGALPHA ); + PyConstant_Insert(d, "COLORBAND", PyInt_FromLong(TEX_COLORBAND)); + PyConstant_Insert(d, "FLIPBLEND", PyInt_FromLong(TEX_FLIPBLEND)); + PyConstant_Insert(d, "NEGALPHA", PyInt_FromLong(TEX_NEGALPHA)); + PyConstant_Insert(d, "CHECKER_ODD", PyInt_FromLong(TEX_CHECKER_ODD)); + PyConstant_Insert(d, "CHECKER_EVEN", PyInt_FromLong(TEX_CHECKER_EVEN)); } return Flags; } - -#undef EXPP_ADDCONST -#define EXPP_ADDCONST(name) \ - PyConstant_Insert(d, #name, PyInt_FromLong(EXPP_TEX_EXTEND_##name)) - static PyObject *M_Texture_ExtendModesDict( void ) { PyObject *ExtendModes = PyConstant_New( ); if( ExtendModes ) { BPy_constant *d = ( BPy_constant * ) ExtendModes; - - EXPP_ADDCONST( EXTEND ); - EXPP_ADDCONST( CLIP ); - EXPP_ADDCONST( CLIPCUBE ); - EXPP_ADDCONST( REPEAT ); + PyConstant_Insert(d, "EXTEND", PyInt_FromLong(TEX_EXTEND)); + PyConstant_Insert(d, "CLIP", PyInt_FromLong(TEX_CLIP)); + PyConstant_Insert(d, "CLIPCUBE", PyInt_FromLong(TEX_CLIPCUBE)); + PyConstant_Insert(d, "REPEAT", PyInt_FromLong(TEX_REPEAT)); } return ExtendModes; } - -#undef EXPP_ADDCONST -#define EXPP_ADDCONST(name) \ - PyConstant_Insert(d, #name, PyInt_FromLong(EXPP_TEX_IMAGEFLAG_##name)) - static PyObject *M_Texture_ImageFlagsDict( void ) { PyObject *ImageFlags = PyConstant_New( ); if( ImageFlags ) { BPy_constant *d = ( BPy_constant * ) ImageFlags; - - EXPP_ADDCONST( INTERPOL ); - EXPP_ADDCONST( USEALPHA ); - EXPP_ADDCONST( MIPMAP ); - EXPP_ADDCONST( FIELDS ); - EXPP_ADDCONST( ROT90 ); - EXPP_ADDCONST( CALCALPHA ); - EXPP_ADDCONST( STFIELD ); - EXPP_ADDCONST( MOVIE ); - EXPP_ADDCONST( CYCLIC ); - EXPP_ADDCONST( NORMALMAP ); + PyConstant_Insert(d, "INTERPOL", PyInt_FromLong(TEX_INTERPOL)); + PyConstant_Insert(d, "USEALPHA", PyInt_FromLong(TEX_USEALPHA)); + PyConstant_Insert(d, "MIPMAP", PyInt_FromLong(TEX_MIPMAP)); + PyConstant_Insert(d, "FIELDS", PyInt_FromLong(TEX_FIELDS)); + PyConstant_Insert(d, "ROT90", PyInt_FromLong(TEX_IMAROT)); + PyConstant_Insert(d, "CALCALPHA", PyInt_FromLong(TEX_CALCALPHA)); + PyConstant_Insert(d, "STFIELD", PyInt_FromLong(TEX_STD_FIELD)); + PyConstant_Insert(d, "MOVIE", PyInt_FromLong(TEX_ANIM5)); + PyConstant_Insert(d, "CYCLIC", PyInt_FromLong(TEX_ANIMCYCLIC)); + PyConstant_Insert(d, "NORMALMAP", PyInt_FromLong(TEX_NORMALMAP)); } return ImageFlags; } +static PyObject *M_Texture_NoiseDict( void ) +{ + PyObject *Noise = PyConstant_New( ); + if( Noise ) { + BPy_constant *d = ( BPy_constant * ) Noise; + PyConstant_Insert(d, "SINE", PyInt_FromLong(EXPP_TEX_NOISE_SINE)); + PyConstant_Insert(d, "SAW", PyInt_FromLong(EXPP_TEX_NOISE_SAW)); + PyConstant_Insert(d, "TRI", PyInt_FromLong(EXPP_TEX_NOISE_TRI)); + PyConstant_Insert(d, "BLENDER", PyInt_FromLong(TEX_BLENDER)); + PyConstant_Insert(d, "PERLIN", PyInt_FromLong(TEX_STDPERLIN)); + PyConstant_Insert(d, "IMPROVEPERLIN", PyInt_FromLong(TEX_NEWPERLIN)); + PyConstant_Insert(d, "VORONOIF1", PyInt_FromLong(TEX_VORONOI_F1)); + PyConstant_Insert(d, "VORONOIF2", PyInt_FromLong(TEX_VORONOI_F2)); + PyConstant_Insert(d, "VORONOIF3", PyInt_FromLong(TEX_VORONOI_F3)); + PyConstant_Insert(d, "VORONOIF4", PyInt_FromLong(TEX_VORONOI_F4)); + PyConstant_Insert(d, "VORONOIF2F1", PyInt_FromLong(TEX_VORONOI_F2F1)); + PyConstant_Insert(d, "VORONOICRACKLE", + PyInt_FromLong(TEX_VORONOI_CRACKLE)); + PyConstant_Insert(d, "CELLNOISE", PyInt_FromLong(TEX_CELLNOISE)); + } + return Noise; +} PyObject *Texture_Init( void ) { @@ -818,8 +1209,10 @@ PyObject *Texture_Init( void ) PyObject *Flags = M_Texture_FlagsDict( ); PyObject *ExtendModes = M_Texture_ExtendModesDict( ); PyObject *ImageFlags = M_Texture_ImageFlagsDict( ); + PyObject *Noise = M_Texture_NoiseDict( ); - Texture_Type.ob_type = &PyType_Type; + if( PyType_Ready( &Texture_Type ) < 0) + return NULL; submodule = Py_InitModule3( "Blender.Texture", M_Texture_methods, M_Texture_doc ); @@ -838,6 +1231,8 @@ PyObject *Texture_Init( void ) PyModule_AddObject( submodule, "ExtendModes", ExtendModes ); if( ImageFlags ) PyModule_AddObject( submodule, "ImageFlags", ImageFlags ); + if( Noise ) + PyModule_AddObject( submodule, "Noise", Noise ); /* Add the MTex submodule to this module */ dict = PyModule_GetDict( submodule ); @@ -864,13 +1259,11 @@ Tex *Texture_FromPyObject( PyObject * pyobj ) return ( ( BPy_Texture * ) pyobj )->texture; } - int Texture_CheckPyObject( PyObject * pyobj ) { return ( pyobj->ob_type == &Texture_Type ); } - /*****************************************************************************/ /* Python BPy_Texture methods: */ /*****************************************************************************/ @@ -913,16 +1306,23 @@ static PyObject *Texture_getName( BPy_Texture * self ) return attr; } -static PyObject *Texture_getSType( BPy_Texture * self ) +static PyObject *Texture_oldgetSType( BPy_Texture * self ) { PyObject *attr = NULL; const char *stype = NULL; int n_stype; - if( self->texture->type == EXPP_TEX_TYPE_ENVMAP ) + if( self->texture->type == TEX_VORONOI ) + n_stype = self->texture->vn_coltype; +#if 0 + else if( self->texture->type == TEX_MUSGRAVE ) + n_stype = self->texture->noisebasis; +#endif + else if( self->texture->type == TEX_ENVMAP ) n_stype = self->texture->env->stype; - else + else n_stype = self->texture->stype; + if( EXPP_map_getStrVal( tex_stype_map[self->texture->type], n_stype, &stype ) ) attr = PyString_FromString( stype ); @@ -934,7 +1334,7 @@ static PyObject *Texture_getSType( BPy_Texture * self ) return attr; } -static PyObject *Texture_getType( BPy_Texture * self ) +static PyObject *Texture_oldgetType( BPy_Texture * self ) { PyObject *attr = NULL; const char *type = NULL; @@ -949,1076 +1349,1295 @@ static PyObject *Texture_getType( BPy_Texture * self ) return attr; } -static PyObject *Texture_setAnimFrames( BPy_Texture * self, PyObject * args ) +static int Texture_setAnimFrames( BPy_Texture * self, PyObject * value ) { - int frames; - if( !PyArg_ParseTuple( args, "i", &frames ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected an int" ); - - if( frames < 0 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "frames cannot be negative" ); - - self->texture->frames = (short)frames; - - Py_INCREF( Py_None ); - return Py_None; + return EXPP_setIValueClamped ( value, &self->texture->frames, + EXPP_TEX_ANIMFRAME_MIN, + EXPP_TEX_ANIMFRAME_MAX, 'h' ); } -static PyObject *Texture_setAnimLength( BPy_Texture * self, PyObject * args ) +static int Texture_setAnimLength( BPy_Texture * self, PyObject * value ) { - int length; - if( !PyArg_ParseTuple( args, "i", &length ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected an int" ); - - if( length < 0 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "length cannot be negative" ); - - self->texture->len = (short)length; - - Py_INCREF( Py_None ); - return Py_None; + return EXPP_setIValueClamped ( value, &self->texture->len, + EXPP_TEX_ANIMLEN_MIN, + EXPP_TEX_ANIMLEN_MAX, 'h' ); } - -static PyObject *Texture_setAnimMontage( BPy_Texture * self, PyObject * args ) +static int Texture_setAnimMontage( BPy_Texture * self, PyObject * value ) { int fradur[4][2]; - int i, j; - if( !PyArg_ParseTuple( args, "((ii)(ii)(ii)(ii))", + int i; + + if( !PyArg_ParseTuple( value, "(ii)(ii)(ii)(ii)", &fradur[0][0], &fradur[0][1], &fradur[1][0], &fradur[1][1], &fradur[2][0], &fradur[2][1], &fradur[3][0], &fradur[3][1] ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, + return EXPP_ReturnIntError( PyExc_TypeError, "expected a tuple of tuples" ); - for( i = 0; i < 4; ++i ) - for( j = 0; j < 2; ++j ) - if( fradur[i][j] < 0 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "values must be greater than zero" ); - - for( i = 0; i < 4; ++i ) - for( j = 0; j < 2; ++j ) - self->texture->fradur[i][j] = (short)fradur[i][j]; + for( i = 0; i < 4; ++i ) { + self->texture->fradur[i][0] = + EXPP_ClampInt ( fradur[i][0], EXPP_TEX_ANIMMONSTART_MIN, + EXPP_TEX_ANIMMONSTART_MAX ); + self->texture->fradur[i][1] = + EXPP_ClampInt ( fradur[i][1], EXPP_TEX_ANIMMONDUR_MIN, + EXPP_TEX_ANIMMONDUR_MAX ); + } - Py_INCREF( Py_None ); - return Py_None; + return 0; } - -static PyObject *Texture_setAnimOffset( BPy_Texture * self, PyObject * args ) +static int Texture_setAnimOffset( BPy_Texture * self, PyObject * value ) { - int offset; - if( !PyArg_ParseTuple( args, "i", &offset ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected an int" ); + return EXPP_setIValueClamped ( value, &self->texture->offset, + EXPP_TEX_ANIMOFFSET_MIN, + EXPP_TEX_ANIMOFFSET_MAX, 'h' ); +} - self->texture->offset = (short)offset; +static int Texture_setAnimStart( BPy_Texture * self, PyObject * value ) +{ + return EXPP_setIValueClamped ( value, &self->texture->sfra, + EXPP_TEX_ANIMSTART_MIN, + EXPP_TEX_ANIMSTART_MAX, 'h' ); +} - Py_INCREF( Py_None ); - return Py_None; +static int Texture_setBrightness( BPy_Texture * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->texture->bright, + EXPP_TEX_BRIGHTNESS_MIN, + EXPP_TEX_BRIGHTNESS_MAX ); } +static int Texture_setContrast( BPy_Texture * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->texture->contrast, + EXPP_TEX_CONTRAST_MIN, + EXPP_TEX_CONTRAST_MAX ); +} -static PyObject *Texture_setAnimStart( BPy_Texture * self, PyObject * args ) +static int Texture_setCrop( BPy_Texture * self, PyObject * value ) { - int sfra; - if( !PyArg_ParseTuple( args, "i", &sfra ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected an int" ); + float crop[4]; - if( sfra < 1 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "start must be greater than zero" ); + if( !PyArg_ParseTuple( value, "ffff", + &crop[0], &crop[1], &crop[2], &crop[3] ) ) + return EXPP_ReturnIntError( PyExc_TypeError, + "expected tuple of 4 floats" ); - self->texture->sfra = (short)sfra; + self->texture->cropxmin = EXPP_ClampFloat( crop[0], EXPP_TEX_CROP_MIN, + EXPP_TEX_CROP_MAX ); + self->texture->cropymin = EXPP_ClampFloat( crop[1], EXPP_TEX_CROP_MIN, + EXPP_TEX_CROP_MAX ); + self->texture->cropxmax = EXPP_ClampFloat( crop[2], EXPP_TEX_CROP_MIN, + EXPP_TEX_CROP_MAX ); + self->texture->cropymax = EXPP_ClampFloat( crop[3], EXPP_TEX_CROP_MIN, + EXPP_TEX_CROP_MAX ); - Py_INCREF( Py_None ); - return Py_None; + return 0; } - -static PyObject *Texture_setBrightness( BPy_Texture * self, PyObject * args ) +static int Texture_setIntExtend( BPy_Texture * self, PyObject * value ) { - float bright; - if( !PyArg_ParseTuple( args, "f", &bright ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a float" ); - - if( bright < 0 || bright > 2 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "brightness must be in range [0,2]" ); + return EXPP_setIValueRange ( value, &self->texture->extend, + EXPP_TEX_EXTEND_MIN, + EXPP_TEX_EXTEND_MAX, 'h' ); +} - self->texture->bright = bright; +static int Texture_setFieldsPerImage( BPy_Texture * self, + PyObject * value ) +{ + return EXPP_setIValueClamped ( value, &self->texture->fie_ima, + EXPP_TEX_FIEIMA_MIN, + EXPP_TEX_FIEIMA_MAX, 'h' ); - Py_INCREF( Py_None ); - return Py_None; } +static int Texture_setFilterSize( BPy_Texture * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->texture->filtersize, + EXPP_TEX_FILTERSIZE_MIN, + EXPP_TEX_FILTERSIZE_MAX ); +} -static PyObject *Texture_setContrast( BPy_Texture * self, PyObject * args ) +static int Texture_setFlags( BPy_Texture * self, PyObject * value ) { - float contrast; - if( !PyArg_ParseTuple( args, "f", &contrast ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a float" ); + int param; + int bitmask = TEX_FLIPBLEND +#if 0 + | TEX_COLORBAND +#endif + | TEX_NEGALPHA + | TEX_CHECKER_ODD + | TEX_CHECKER_EVEN; - if( contrast < 0.01 || contrast > 5.0 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "contrast must be in range [0.01,5.0]" ); + if( !PyInt_CheckExact ( value ) ) { + char errstr[128]; + sprintf ( errstr , "expected int bitmask of 0x%08x", bitmask ); + return EXPP_ReturnIntError( PyExc_TypeError, errstr ); + } + param = PyInt_AS_LONG ( value ); - self->texture->contrast = contrast; + if ( ( param & bitmask ) != param ) + return EXPP_ReturnIntError( PyExc_ValueError, + "invalid bit(s) set in mask" ); - Py_INCREF( Py_None ); - return Py_None; -} + self->texture->flag = param; + +#if 0 + /* if Colorband enabled, make sure we allocate memory for it */ + + if ( ( param & TEX_COLORBAND ) && !self->texture->coba ) + self->texture->coba = add_colorband(); +#endif + return 0; +} -static PyObject *Texture_setCrop( BPy_Texture * self, PyObject * args ) +static int Texture_setImage( BPy_Texture * self, PyObject * value ) { - float crop[4]; - int i; - if( !PyArg_ParseTuple( args, "(ffff)", - &crop[0], &crop[1], &crop[2], &crop[3] ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected tuple of 4 floats" ); + PyObject *pyimg; + Image *blimg = NULL; - for( i = 0; i < 4; ++i ) - if( crop[i] < -10 || crop[i] > 10 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "values must be in range [-10,10]" ); + if( !PyArg_ParseTuple( value, "O!", &Image_Type, &pyimg ) ) + return EXPP_ReturnIntError( PyExc_TypeError, + "expected an Image" ); + blimg = Image_FromPyObject( pyimg ); - self->texture->cropxmin = crop[0]; - self->texture->cropymin = crop[1]; - self->texture->cropxmax = crop[2]; - self->texture->cropymax = crop[3]; + if( self->texture->ima ) { + self->texture->ima->id.us--; + } - Py_INCREF( Py_None ); - return Py_None; + self->texture->ima = blimg; + id_us_plus( &blimg->id ); + + return 0; } +static int Texture_setImageFlags( BPy_Texture * self, PyObject * value, + void *type ) +{ + short param; + + /* + * if type is non-zero, then attribute is "mipmap", "calcAlpha", etc., + * so set/clear the bit in the bitfield based on the type + */ + + if( (int)type ) { + int err; + param = self->texture->imaflag; + err = EXPP_setBitfield( value, ¶m, (int)type, 'h' ); + if( err ) + return err; + + /* + * if type is zero, then attribute is "imageFlags", so check + * value for a valid bitmap range. + */ + + } else { + int bitmask = TEX_INTERPOL + | TEX_USEALPHA + | TEX_MIPMAP + | TEX_FIELDS + | TEX_IMAROT + | TEX_CALCALPHA + | TEX_ANIMCYCLIC + | TEX_ANIM5 + | TEX_ANTIALI + | TEX_STD_FIELD + | TEX_NORMALMAP; + + if( !PyInt_CheckExact ( value ) ) { + char errstr[128]; + sprintf ( errstr , "expected int bitmask of 0x%08x", bitmask ); + return EXPP_ReturnIntError( PyExc_TypeError, errstr ); + } + + param = PyInt_AS_LONG( value ); + if( ( param & bitmask ) != param ) + return EXPP_ReturnIntError( PyExc_ValueError, + "invalid bit(s) set in mask" ); + } + + /* "mipmap" and "fields" can't be set at the same time */ + + if( ( param & TEX_MIPMAP ) && + ( param & TEX_FIELDS ) ) + return EXPP_ReturnIntError( PyExc_ValueError, + "image flags MIPMAP and FIELDS cannot be used together" ); + + /* everything is OK; save the new flag setting */ + + self->texture->imaflag = param; + return 0; +} -static PyObject *Texture_setExtend( BPy_Texture * self, PyObject * args ) +static int Texture_setName( BPy_Texture * self, PyObject * value ) { - char *extend = NULL; - if( !PyArg_ParseTuple( args, "s", &extend ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, + char *name; + char buf[21]; + + name = PyString_AsString ( value ); + if( !name ) + return EXPP_ReturnIntError( PyExc_TypeError, "expected string argument" ); - if( !EXPP_map_getShortVal - ( tex_extend_map, extend, &self->texture->extend ) ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "invalid extend mode" ); + PyOS_snprintf( buf, sizeof( buf ), "%s", name ); - Py_INCREF( Py_None ); - return Py_None; + rename_id( &self->texture->id, buf ); + + return 0; } -static PyObject *Texture_setIntExtend( BPy_Texture * self, PyObject * args ) +static int Texture_setNoiseDepth( BPy_Texture * self, PyObject * value ) { - int extend = 0; - if( !PyArg_ParseTuple( args, "i", &extend ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument" ); + short max = EXPP_TEX_NOISEDEPTH_MAX; - if( extend < EXPP_TEX_EXTEND_MIN || extend > EXPP_TEX_EXTEND_MAX ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "invalid extend mode" ); + /* for whatever reason, magic texture has a different max value */ - self->texture->extend = (short)extend; + if( self->texture->type == TEX_MAGIC ) + max = EXPP_TEX_NOISEDEPTH_MAX_MAGIC; - Py_INCREF( Py_None ); - return Py_None; + return EXPP_setIValueClamped ( value, &self->texture->noisedepth, + EXPP_TEX_NOISEDEPTH_MIN, max, 'h' ); } -static PyObject *Texture_setFieldsPerImage( BPy_Texture * self, - PyObject * args ) +static int Texture_setNoiseSize( BPy_Texture * self, PyObject * value ) { - int fie_ima; - if( !PyArg_ParseTuple( args, "i", &fie_ima ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected an int" ); + return EXPP_setFloatClamped ( value, &self->texture->noisesize, + EXPP_TEX_NOISESIZE_MIN, + EXPP_TEX_NOISESIZE_MAX ); +} - if( fie_ima < 1 || fie_ima > 200 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "value must be in range [1,200]" ); +static int Texture_setNoiseType( BPy_Texture * self, PyObject * value ) +{ + char *param; - self->texture->fie_ima = (short)fie_ima; + if( !PyString_Check( value ) ) + return EXPP_ReturnIntError( PyExc_TypeError, + "expected string argument" ); + param = PyString_AS_STRING( value ); - Py_INCREF( Py_None ); - return Py_None; + if( STREQ( param, "soft" ) ) + self->texture->noisetype = TEX_NOISESOFT; + else if( STREQ( param, "hard" ) ) + self->texture->noisetype = TEX_NOISEPERL; + else + return EXPP_ReturnIntError( PyExc_ValueError, + "noise type must be 'soft' or 'hard'" ); + + return 0; } -static PyObject *Texture_setFilterSize( BPy_Texture * self, PyObject * args ) +static int Texture_setNoiseBasis( BPy_Texture * self, PyObject * value ) { - float size; - if( !PyArg_ParseTuple( args, "f", &size ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a float" ); + int param; - if( size < 0.1 || size > 25 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "filter size must be in range [0.1,25]" ); + if( !PyInt_CheckExact ( value ) ) + return EXPP_ReturnIntError( PyExc_TypeError, + "expected int (see 'Noise' constant dictionary)" ); - self->texture->filtersize = size; + param = PyInt_AS_LONG ( value ); - Py_INCREF( Py_None ); - return Py_None; + if ( param < TEX_BLENDER + || ( param > TEX_VORONOI_CRACKLE + && param != TEX_CELLNOISE ) ) + return EXPP_ReturnIntError( PyExc_ValueError, + "invalid noise type" ); + + self->texture->noisebasis = param; + return 0; } -static PyObject *Texture_setFlags( BPy_Texture * self, PyObject * args ) +static int Texture_setNoiseBasis2( BPy_Texture * self, PyObject * value, + void *type ) { - char *sf[3] = { NULL, NULL, NULL }; - int i; - short flags = 0; - short thisflag; - if( !PyArg_ParseTuple( args, "|sss", &sf[0], &sf[1], &sf[2] ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected 0-3 string arguments" ); + /* + * if type is EXPP_TEX_NOISEBASIS2, then this is the "noiseBasis2" + * attribute, so check the range and set the whole value + */ - for( i = 0; i < 3; ++i ) { - if( !sf[i] ) - break; + if( (int)type == EXPP_TEX_NOISEBASIS2 ) { + int param; + if( !PyInt_CheckExact ( value ) ) + return EXPP_ReturnIntError( PyExc_TypeError, + "expected int (see 'Noise' constant dictionary)" ); - if( !EXPP_map_getShortVal( tex_flag_map, sf[i], &thisflag ) ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "invalid texture flag name" ); + param = PyInt_AS_LONG ( value ); - flags |= thisflag; - } + if ( param < TEX_BLENDER + || ( param > TEX_VORONOI_CRACKLE + && param != TEX_CELLNOISE ) ) + return EXPP_ReturnIntError( PyExc_ValueError, + "invalid noise type" ); - self->texture->flag = flags; + self->texture->noisebasis2 = param; - Py_INCREF( Py_None ); - return Py_None; + /* + * for other type values, the attribute is "sine", "saw" or "tri", + * so set the noise basis to the supplied type if value is 1 + */ + + } else { + if( !PyInt_CheckExact ( value ) ) + return EXPP_ReturnIntError( PyExc_TypeError, + "expected int value of 1" ); + + if( PyInt_AS_LONG ( value ) != 1 ) + return EXPP_ReturnIntError( PyExc_ValueError, + "expected int value of 1" ); + + self->texture->noisebasis2 = (int)type; + } + return 0; } -static PyObject *Texture_setIntFlags( BPy_Texture * self, PyObject * args ) +static int Texture_setRepeat( BPy_Texture * self, PyObject * args ) { - int flags = 0; - if( !PyArg_ParseTuple( args, "i", &flags ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument" ); + int repeat[2]; - self->texture->flag = (short)flags; + if( !PyArg_ParseTuple( args, "ii", &repeat[0], &repeat[1] ) ) + return EXPP_ReturnIntError( PyExc_TypeError, + "expected tuple of 2 ints" ); - Py_INCREF( Py_None ); - return Py_None; + self->texture->xrepeat = EXPP_ClampInt( repeat[0], EXPP_TEX_REPEAT_MIN, + EXPP_TEX_REPEAT_MAX ); + self->texture->yrepeat = EXPP_ClampInt( repeat[1], EXPP_TEX_REPEAT_MIN, + EXPP_TEX_REPEAT_MAX ); + + return 0; } +static int Texture_setRGBCol( BPy_Texture * self, PyObject * args ) +{ + float rgb[3]; + + if( !PyArg_ParseTuple( args, "fff", &rgb[0], &rgb[1], &rgb[2] ) ) + return EXPP_ReturnIntError( PyExc_TypeError, + "expected tuple of 3 floats" ); + + self->texture->rfac = EXPP_ClampFloat( rgb[0], EXPP_TEX_RGBCOL_MIN, + EXPP_TEX_RGBCOL_MAX ); + self->texture->gfac = EXPP_ClampFloat( rgb[1], EXPP_TEX_RGBCOL_MIN, + EXPP_TEX_RGBCOL_MAX ); + self->texture->bfac = EXPP_ClampFloat( rgb[2], EXPP_TEX_RGBCOL_MIN, + EXPP_TEX_RGBCOL_MAX ); + + return 0; +} -static PyObject *Texture_setImage( BPy_Texture * self, PyObject * args ) +static int Texture_setSType( BPy_Texture * self, PyObject * value ) { - PyObject *pyimg; - Image *blimg = NULL; + short param; + const char *dummy = NULL; - if( !PyArg_ParseTuple( args, "O!", &Image_Type, &pyimg ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected an Image" ); - blimg = Image_FromPyObject( pyimg ); + if( !PyInt_CheckExact ( value ) ) + return EXPP_ReturnIntError( PyExc_TypeError, + "expected int argument" ); - if( self->texture->ima ) { - self->texture->ima->id.us--; - } + param = PyInt_AS_LONG ( value ); - self->texture->ima = blimg; - id_us_plus( &blimg->id ); + /* use the stype map to find out if this is a valid stype for this type * + * note that this will allow CLD_COLOR when type is ENVMAP. there's not * + * much that we can do about this though. */ + if( !EXPP_map_getStrVal + ( tex_stype_map[self->texture->type], param, &dummy ) ) + return EXPP_ReturnIntError( PyExc_ValueError, + "invalid stype (for this type)" ); - Py_INCREF( Py_None ); - return Py_None; + if( self->texture->type == TEX_VORONOI ) + self->texture->vn_coltype = param; +#if 0 + else if( self->texture->type == TEX_MUSGRAVE ) + self->texture->noisebasis = param; +#endif + else if( self->texture->type == TEX_ENVMAP ) + self->texture->env->stype = param; + else + self->texture->stype = param; + + return 0; } +static int Texture_setTurbulence( BPy_Texture * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->texture->turbul, + EXPP_TEX_TURBULENCE_MIN, + EXPP_TEX_TURBULENCE_MAX ); +} -static PyObject *Texture_setImageFlags( BPy_Texture * self, PyObject * args ) +static int Texture_setHFracDim( BPy_Texture * self, PyObject * value ) { - char *sf[9] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; - int i; - short flags = 0; - short thisflag; - if( !PyArg_ParseTuple - ( args, "|sssssssss", &sf[0], &sf[1], &sf[2], &sf[3], &sf[4], - &sf[5], &sf[6], &sf[7], &sf[8] ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected 0-9 string arguments" ); + return EXPP_setFloatClamped ( value, &self->texture->mg_H, + EXPP_TEX_MH_G_MIN, + EXPP_TEX_MH_G_MAX ); +} - for( i = 0; i < 9; ++i ) { - if( !sf[i] ) - break; +static int Texture_setLacunarity( BPy_Texture * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->texture->mg_lacunarity, + EXPP_TEX_LACUNARITY_MIN, + EXPP_TEX_LACUNARITY_MAX ); +} - if( !EXPP_map_getShortVal - ( tex_imageflag_map, sf[i], &thisflag ) ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "invalid texture image flag name" ); +static int Texture_setOcts( BPy_Texture * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->texture->mg_octaves, + EXPP_TEX_OCTS_MIN, + EXPP_TEX_OCTS_MAX ); +} - flags |= thisflag; - } +static int Texture_setIScale( BPy_Texture * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->texture->ns_outscale, + EXPP_TEX_ISCALE_MIN, + EXPP_TEX_ISCALE_MAX ); +} - /* MIPMAP and FIELDS can't be used together */ - if( ( flags & EXPP_TEX_IMAGEFLAG_MIPMAP ) && - ( flags & EXPP_TEX_IMAGEFLAG_FIELDS ) ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "image flags MIPMAP and FIELDS cannot be used together" ); +static int Texture_setType( BPy_Texture * self, PyObject * value ) +{ + int err = EXPP_setIValueRange ( value, &self->texture->type, + EXPP_TEX_TYPE_MIN, + EXPP_TEX_TYPE_MAX, 'h' ); - self->texture->imaflag = flags; + /* + * if we set the texture OK, and it's a environment map, and + * there is no environment map yet, allocate one (code borrowed + * from texture_panel_envmap() in source/blender/src/buttons_shading.c) + */ - Py_INCREF( Py_None ); - return Py_None; + if( !err && self->texture->type == TEX_ENVMAP + && !self->texture->env ) { + self->texture->env = RE_add_envmap(); + self->texture->env->object= OBACT; + } + return err; } -static PyObject *Texture_setIntImageFlags( BPy_Texture * self, - PyObject * args ) +static int Texture_setDistMetric( BPy_Texture * self, PyObject * value ) { - int flags = 0; - if( !PyArg_ParseTuple( args, "i", &flags ) ) +#if 0 + char *dist = NULL; + + if( !PyArg_ParseTuple( value, "s", &dist ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument" ); + "expected string argument" ); - /* MIPMAP and FIELDS can't be used together */ - if( ( flags & EXPP_TEX_IMAGEFLAG_MIPMAP ) && - ( flags & EXPP_TEX_IMAGEFLAG_FIELDS ) ) + /* can we really trust texture->type? */ + if( self->texture->type == TEX_VORONOI && + !EXPP_map_getShortVal( tex_stype_map[self->texture->type + 2], + dist, &self->texture->vn_distm ) ) return EXPP_ReturnPyObjError( PyExc_ValueError, - "image flags MIPMAP and FIELDS cannot be used together" ); - - self->texture->imaflag = (short)flags; + "invalid dist metric type" ); Py_INCREF( Py_None ); return Py_None; +#else + return EXPP_setIValueRange ( value, &self->texture->vn_distm, + TEX_DISTANCE, + TEX_MINKOVSKY, 'h' ); +#endif } -static PyObject *Texture_setName( BPy_Texture * self, PyObject * args ) +static int Texture_setExp( BPy_Texture * self, PyObject * value ) { - char *name; - char buf[21]; + return EXPP_setFloatClamped ( value, &self->texture->vn_mexp, + EXPP_TEX_EXP_MIN, + EXPP_TEX_EXP_MAX ); +} - if( !PyArg_ParseTuple( args, "s", &name ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected string argument" ); +static int Texture_setWeight1( BPy_Texture * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->texture->vn_w1, + EXPP_TEX_WEIGHT1_MIN, + EXPP_TEX_WEIGHT1_MAX ); +} - PyOS_snprintf( buf, sizeof( buf ), "%s", name ); - rename_id( &self->texture->id, buf ); +static int Texture_setWeight2( BPy_Texture * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->texture->vn_w2, + EXPP_TEX_WEIGHT2_MIN, + EXPP_TEX_WEIGHT2_MAX ); +} - Py_INCREF( Py_None ); - return Py_None; +static int Texture_setWeight3( BPy_Texture * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->texture->vn_w3, + EXPP_TEX_WEIGHT3_MIN, + EXPP_TEX_WEIGHT3_MAX ); } -static PyObject *Texture_setNoiseDepth( BPy_Texture * self, PyObject * args ) +static int Texture_setWeight4( BPy_Texture * self, PyObject * value ) { - int depth; - if( !PyArg_ParseTuple( args, "i", &depth ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected an int" ); + return EXPP_setFloatClamped ( value, &self->texture->vn_w4, + EXPP_TEX_WEIGHT4_MIN, + EXPP_TEX_WEIGHT4_MAX ); +} - if( depth < 0 || depth > 6 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "value must be in range [0,6]" ); +static int Texture_setDistAmnt( BPy_Texture * self, PyObject * value ) +{ + return EXPP_setFloatClamped ( value, &self->texture->dist_amount, + EXPP_TEX_DISTAMNT_MIN, + EXPP_TEX_DISTAMNT_MAX ); +} - self->texture->noisedepth = (short)depth; +static PyObject *Texture_getIpo( BPy_Texture * self ) +{ + struct Ipo *ipo = self->texture->ipo; - Py_INCREF( Py_None ); - return Py_None; + if( !ipo ) { + Py_INCREF( Py_None ); + return Py_None; + } + + return Ipo_CreatePyObject( ipo ); } -static PyObject *Texture_setNoiseSize( BPy_Texture * self, PyObject * args ) +/* + * this should accept a Py_None argument and just delete the Ipo link + * (as Texture_clearIpo() does) + */ + +static int Texture_setIpo( BPy_Texture * self, PyObject * value ) { - float size; - if( !PyArg_ParseTuple( args, "f", &size ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a float" ); + Ipo *ipo = NULL; + Ipo *oldipo = self->texture->ipo; + ID *id; - if( size < 0 || size > 2 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "noise size must be in range [0,2]" ); + /* if parameter is not None, check for valid Ipo */ - self->texture->noisesize = size; + if ( value != Py_None ) { + if ( !Ipo_CheckPyObject( value ) ) + return EXPP_ReturnIntError( PyExc_RuntimeError, + "expected an Ipo object" ); - Py_INCREF( Py_None ); - return Py_None; + ipo = Ipo_FromPyObject( value ); + + if( !ipo ) + return EXPP_ReturnIntError( PyExc_RuntimeError, + "null ipo!" ); + + if( ipo->blocktype != ID_TE ) + return EXPP_ReturnIntError( PyExc_TypeError, + "Ipo is not a texture data Ipo" ); + } + + /* if already linked to Ipo, delete link */ + + if ( oldipo ) { + id = &oldipo->id; + if( id->us > 0 ) + id->us--; + } + + /* assign new Ipo and increment user count, or set to NULL if deleting */ + + self->texture->ipo = ipo; + if ( ipo ) { + id = &ipo->id; + id->us++; + } + + return 0; } -static PyObject *Texture_setNoiseType( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getAnimFrames( BPy_Texture *self ) { - char *type; + PyObject *attr = PyInt_FromLong( self->texture->frames ); - if( !PyArg_ParseTuple( args, "s", &type ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected string argument" ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - if( STREQ( type, "soft" ) ) - self->texture->noisetype = TEX_NOISESOFT; - else if( STREQ( type, "hard" ) ) - self->texture->noisetype = TEX_NOISEPERL; + return attr; +} - else - return EXPP_ReturnPyObjError( PyExc_ValueError, - "noise type must be 'soft' or 'hard'" ); +static PyObject *Texture_getAnimLength( BPy_Texture *self ) +{ + PyObject *attr = PyInt_FromLong( self->texture->len ); - Py_INCREF( Py_None ); - return Py_None; + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" );return attr; + + return attr; } -static PyObject *Texture_setNoiseBasis( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getAnimMontage( BPy_Texture *self ) { - char *nbasis; + PyObject *attr; + + attr = Py_BuildValue( "((i,i),(i,i),(i,i),(i,i))", + self->texture->fradur[0][0], + self->texture->fradur[0][1], + self->texture->fradur[1][0], + self->texture->fradur[1][1], + self->texture->fradur[2][0], + self->texture->fradur[2][1], + self->texture->fradur[3][0], + self->texture->fradur[3][1] ); - if( !PyArg_ParseTuple( args, "s", &nbasis ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected string argument" ); - if( self->texture->type == EXPP_TEX_TYPE_MUSGRAVE && - EXPP_map_getShortVal( tex_stype_map[EXPP_TEX_TYPE_DISTNOISE], - nbasis, &self->texture->noisebasis ) ); - else if( self->texture->type == EXPP_TEX_TYPE_DISTNOISE && - !EXPP_map_getShortVal( tex_stype_map[EXPP_TEX_TYPE_DISTNOISE], - nbasis, &self->texture->noisebasis2 ) ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "invalid noise basis" ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - Py_INCREF( Py_None ); - return Py_None; + return attr; } -/* Distorted Noise */ -static PyObject *Texture_setDistNoise( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getAnimOffset( BPy_Texture *self ) { - char *nbasis; + PyObject *attr = PyInt_FromLong( self->texture->offset ); - if( !PyArg_ParseTuple( args, "s", &nbasis ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected string argument" ); - if( self->texture->type == EXPP_TEX_TYPE_DISTNOISE && - !EXPP_map_getShortVal( tex_stype_map[EXPP_TEX_TYPE_DISTNOISE], - nbasis, &self->texture->noisebasis ) ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "invalid noise basis" ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - Py_INCREF( Py_None ); - return Py_None; + return attr; } -static PyObject *Texture_setRepeat( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getAnimStart( BPy_Texture *self ) { - int repeat[2]; - int i; - if( !PyArg_ParseTuple( args, "(ii)", &repeat[0], &repeat[1] ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected tuple of 2 ints" ); + PyObject *attr = PyInt_FromLong( self->texture->sfra ); - for( i = 0; i < 2; ++i ) - if( repeat[i] < 1 || repeat[i] > 512 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "values must be in range [1,512]" ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - self->texture->xrepeat = (short)repeat[0]; - self->texture->yrepeat = (short)repeat[1]; + return attr; +} - Py_INCREF( Py_None ); - return Py_None; +static PyObject *Texture_getBrightness( BPy_Texture *self ) +{ + PyObject *attr = PyFloat_FromDouble ( self->texture->bright ); + + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); + + return attr; } -static PyObject *Texture_setRGBCol( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getContrast( BPy_Texture *self ) { - float rgb[3]; - int i; - if( !PyArg_ParseTuple( args, "(fff)", &rgb[0], &rgb[1], &rgb[2] ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected tuple of 3 floats" ); + PyObject *attr = PyFloat_FromDouble( self->texture->contrast ); - for( i = 0; i < 3; ++i ) - if( rgb[i] < 0 || rgb[i] > 2 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "values must be in range [0,2]" ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - self->texture->rfac = rgb[0]; - self->texture->gfac = rgb[1]; - self->texture->bfac = rgb[2]; + return attr; +} - Py_INCREF( Py_None ); - return Py_None; +static PyObject *Texture_getCrop( BPy_Texture *self ) +{ + PyObject *attr; + + attr = Py_BuildValue( "(f,f,f,f)", + self->texture->cropxmin, + self->texture->cropymin, + self->texture->cropxmax, + self->texture->cropymax ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); + + return attr; } +static PyObject *Texture_getDistAmnt( BPy_Texture *self ) +{ + PyObject *attr = PyFloat_FromDouble( self->texture->dist_amount ); + + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); + + return attr; +} -static PyObject *Texture_setSType( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getDistMetric( BPy_Texture *self ) { - char *stype = NULL; - if( !PyArg_ParseTuple( args, "s", &stype ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected string argument" ); + PyObject *attr = PyInt_FromLong( self->texture->vn_distm ); - /* can we really trust texture->type? */ - if( ( self->texture->type == EXPP_TEX_TYPE_VORONOI && - EXPP_map_getShortVal( tex_stype_map[self->texture->type], - stype, &self->texture->vn_coltype ) ) ); - else if( ( self->texture->type == EXPP_TEX_TYPE_MUSGRAVE && - EXPP_map_getShortVal( tex_stype_map - [EXPP_TEX_TYPE_DISTNOISE], stype, - &self->texture->noisebasis ) ) ); - else if( ( self->texture->type == EXPP_TEX_TYPE_ENVMAP && - EXPP_map_getShortVal( tex_stype_map[self->texture->type], - stype, &self->texture->env->stype ) ) ); - else if( !EXPP_map_getShortVal - ( tex_stype_map[self->texture->type], stype, - &self->texture->stype ) ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "invalid texture stype" ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - Py_INCREF( Py_None ); - return Py_None; + return attr; } -static PyObject *Texture_setIntSType( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getExp( BPy_Texture *self ) { - int stype = 0; - const char *dummy = NULL; - if( !PyArg_ParseTuple( args, "i", &stype ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument" ); + PyObject *attr = PyFloat_FromDouble( self->texture->vn_mexp ); - /* use the stype map to find out if this is a valid stype for this type * - * note that this will allow CLD_COLOR when type is ENVMAP. there's not * - * much that we can do about this though. */ - if( !EXPP_map_getStrVal - ( tex_stype_map[self->texture->type], stype, &dummy ) ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "invalid stype (for this type)" ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - if( self->texture->type == EXPP_TEX_TYPE_ENVMAP ) - self->texture->env->stype = (short)stype; - else - self->texture->stype = (short)stype; + return attr; +} - Py_INCREF( Py_None ); - return Py_None; +static PyObject *Texture_getIntExtend( BPy_Texture * self ) +{ + PyObject *attr = PyInt_FromLong( self->texture->extend ); + + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); + + return attr; } -static PyObject *Texture_setTurbulence( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getFieldsPerImage( BPy_Texture *self ) { - float turb; - if( !PyArg_ParseTuple( args, "f", &turb ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a float" ); + PyObject *attr = PyInt_FromLong( self->texture->fie_ima ); - if( turb < 0 || turb > 200 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "turbulence must be in range [0,200]" ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); + + return attr; +} - self->texture->turbul = turb; +static PyObject *Texture_getFilterSize( BPy_Texture *self ) +{ + PyObject *attr = PyFloat_FromDouble( self->texture->filtersize ); - Py_INCREF( Py_None ); - return Py_None; + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); + + return attr; } -static PyObject *Texture_setType( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getFlags( BPy_Texture *self ) { - char *type = NULL; - if( !PyArg_ParseTuple( args, "s", &type ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected string argument" ); + PyObject *attr = PyInt_FromLong( self->texture->flag ); - if( !EXPP_map_getShortVal( tex_type_map, type, &self->texture->type ) ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "invalid texture type" ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - Py_INCREF( Py_None ); - return Py_None; + return attr; } +static PyObject *Texture_getHFracDim( BPy_Texture *self ) +{ + PyObject *attr = PyInt_FromLong( self->texture->mg_H ); + + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); + + return attr; +} -static PyObject *Texture_setHFrac( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getImageFlags( BPy_Texture *self, void *type ) { - float mg_H; - if( !PyArg_ParseTuple( args, "f", &mg_H ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a float" ); + PyObject *attr; - if( mg_H < 0 || mg_H > 2 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "turbulence must be in range [0,2]" ); + /* + * type == 0 means attribute "imageFlags" + * other types means attribute "mipmap", "calcAlpha", etc + */ + + if( (int)type ) + attr = EXPP_getBitfield( &self->texture->imaflag, (int)type, 'h' ); + else + attr = PyInt_FromLong( self->texture->imaflag ); - self->texture->mg_H = mg_H; + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - Py_INCREF( Py_None ); - return Py_None; + return attr; } -static PyObject *Texture_setLacunarity( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getIScale( BPy_Texture *self ) { - float mg_lac; - if( !PyArg_ParseTuple( args, "f", &mg_lac ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a float" ); - - if( mg_lac < 0 || mg_lac > 6 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "lacunarity must be in range [0,6]" ); + PyObject *attr = PyFloat_FromDouble( self->texture->ns_outscale ); - self->texture->mg_lacunarity = mg_lac; + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - Py_INCREF( Py_None ); - return Py_None; + return attr; } -static PyObject *Texture_setOcts( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getLacunarity( BPy_Texture *self ) { - float mg_oct; - if( !PyArg_ParseTuple( args, "f", &mg_oct ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a float" ); + PyObject *attr = PyFloat_FromDouble( self->texture->mg_lacunarity ); - if( mg_oct < 0 || mg_oct > 8 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "turbulence must be in range [0,8]" ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - self->texture->mg_octaves = mg_oct; + return attr; +} - Py_INCREF( Py_None ); - return Py_None; +static PyObject *Texture_getNoiseBasis( BPy_Texture *self ) +{ + PyObject *attr = PyInt_FromLong( self->texture->noisebasis ); + + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); + + return attr; } -static PyObject *Texture_setiScale( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getNoiseBasis2( BPy_Texture *self, void *type ) { - float ns_osc; - if( !PyArg_ParseTuple( args, "f", &ns_osc ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a float" ); + PyObject *attr; - if( ns_osc < 0 || ns_osc > 10 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "turbulence must be in range [0,10]" ); + /* + * type == EXPP_TEX_NOISEBASIS2 means attribute "noiseBasis2" + * other types means attribute "sine", "saw", or "tri" attribute + */ - self->texture->ns_outscale = ns_osc; + if( (int)type == EXPP_TEX_NOISEBASIS2 ) + attr = PyInt_FromLong( self->texture->noisebasis2 ); + else + attr = PyInt_FromLong( ( self->texture->noisebasis2 == (int)type ) ? 1 : 0 ); - Py_INCREF( Py_None ); - return Py_None; + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); + + return attr; } -static PyObject *Texture_setIntType( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getNoiseDepth( BPy_Texture *self ) { - int type = 0; - if( !PyArg_ParseTuple( args, "i", &type ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument" ); + PyObject *attr = PyInt_FromLong( self->texture->noisedepth ); - if( type < EXPP_TEX_TYPE_MIN || type > EXPP_TEX_TYPE_MAX ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "invalid type number" ); - - self->texture->type = (short)type; + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - Py_INCREF( Py_None ); - return Py_None; + return attr; } -static PyObject *Texture_setDistMetric( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getNoiseSize( BPy_Texture *self ) { - char *dist = NULL; + PyObject *attr = PyFloat_FromDouble( self->texture->noisesize ); - if( !PyArg_ParseTuple( args, "s", &dist ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected string argument" ); - /* can we really trust texture->type? */ - if( self->texture->type == EXPP_TEX_TYPE_VORONOI && - !EXPP_map_getShortVal( tex_stype_map[self->texture->type + 2], - dist, &self->texture->vn_distm ) ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "invalid dist metric type" ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - Py_INCREF( Py_None ); - return Py_None; + return attr; } -static PyObject *Texture_setExp( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getNoiseType( BPy_Texture *self ) { - float vn_mexp; - if( !PyArg_ParseTuple( args, "f", &vn_mexp ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a float" ); + PyObject *attr; - if( vn_mexp < 0.01 || vn_mexp > 10.0 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "Exp must be in range [0.01,10.0]" ); + if ( self->texture->noisetype == TEX_NOISESOFT ) + attr = PyString_FromString( "soft" ); + else + attr = PyString_FromString( "hard" ); - self->texture->vn_mexp = vn_mexp; + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - Py_INCREF( Py_None ); - return Py_None; + return attr; } -static PyObject *Texture_setW1( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getOcts( BPy_Texture *self ) { - float vn_w1; - if( !PyArg_ParseTuple( args, "f", &vn_w1 ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a float" ); + PyObject *attr = PyFloat_FromDouble( self->texture->mg_octaves ); - if( vn_w1 < -2 || vn_w1 > 2 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "Exp must be in range [0,10]" ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - self->texture->vn_w1 = vn_w1; + return attr; +} - Py_INCREF( Py_None ); - return Py_None; +static PyObject *Texture_getRepeat( BPy_Texture *self ) +{ + PyObject *attr; + + attr = Py_BuildValue( "(i,i)", self->texture->xrepeat, + self->texture->yrepeat ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); + + return attr; } -static PyObject *Texture_setW2( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getRGBCol( BPy_Texture *self ) { - float vn_w2; - if( !PyArg_ParseTuple( args, "f", &vn_w2 ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a float" ); + PyObject *attr; - if( vn_w2 < -2 || vn_w2 > 2 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "Exp must be in range [0,10]" ); + attr = Py_BuildValue( "(f,f,f)", self->texture->rfac, + self->texture->gfac, self->texture->bfac ); - self->texture->vn_w2 = vn_w2; + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - Py_INCREF( Py_None ); - return Py_None; + return attr; } -static PyObject *Texture_setW3( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getSType( BPy_Texture *self ) { - float vn_w3; - if( !PyArg_ParseTuple( args, "f", &vn_w3 ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a float" ); + PyObject *attr; - if( vn_w3 < -2 || vn_w3 > 2 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "Exp must be in range [0,10]" ); + if( self->texture->type == TEX_VORONOI ) + attr = PyInt_FromLong( self->texture->vn_coltype ); +#if 0 + else if( self->texture->type == TEX_MUSGRAVE ) + attr = PyInt_FromLong( self->texture->noisebasis ); +#endif + else if( self->texture->type == TEX_ENVMAP ) + attr = PyInt_FromLong( self->texture->env->stype ); + else + attr = PyInt_FromLong( self->texture->stype ); - self->texture->vn_w3 = vn_w3; + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - Py_INCREF( Py_None ); - return Py_None; + return attr; } -static PyObject *Texture_setW4( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getTurbulence( BPy_Texture *self ) { - float vn_w4; - if( !PyArg_ParseTuple( args, "f", &vn_w4 ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a float" ); + PyObject *attr = PyFloat_FromDouble( self->texture->turbul ); - if( vn_w4 < -2 || vn_w4 > 2 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "Exp must be in range [0,10]" ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); + + return attr; +} - self->texture->vn_w4 = vn_w4; +static PyObject *Texture_getType( BPy_Texture *self ) +{ + PyObject *attr = PyInt_FromLong( self->texture->type ); - Py_INCREF( Py_None ); - return Py_None; + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); + + return attr; } -static PyObject *Texture_setDistAmnt( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_getUsers( BPy_Texture *self ) { - float dist_amount; - if( !PyArg_ParseTuple( args, "f", &dist_amount ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected a float" ); + PyObject *attr = PyInt_FromLong( self->texture->id.us ); - if( dist_amount < 0 || dist_amount > 10 ) - return EXPP_ReturnPyObjError( PyExc_ValueError, - "Exp must be in range [0,10]" ); + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - self->texture->dist_amount = dist_amount; + return attr; +} - Py_INCREF( Py_None ); - return Py_None; +static PyObject *Texture_getWeight1( BPy_Texture *self ) +{ + PyObject *attr = PyFloat_FromDouble( self->texture->vn_w1 ); + + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); + + return attr; } -static void Texture_dealloc( BPy_Texture * self ) +static PyObject *Texture_getWeight2( BPy_Texture *self ) { - PyObject_DEL( self ); + PyObject *attr = PyFloat_FromDouble( self->texture->vn_w2 ); + + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); + + return attr; } -static PyObject *Texture_getAttr( BPy_Texture * self, char *name ) -{ - PyObject *attr = Py_None; - Tex *tex = self->texture; - - if( STREQ( name, "animFrames" ) ) - attr = PyInt_FromLong( tex->frames ); - else if( STREQ( name, "animLength" ) ) - attr = PyInt_FromLong( tex->len ); - else if( STREQ( name, "animMontage" ) ) - attr = Py_BuildValue( "((i,i),(i,i),(i,i),(i,i))", - tex->fradur[0][0], tex->fradur[0][1], - tex->fradur[1][0], tex->fradur[1][1], - tex->fradur[2][0], tex->fradur[2][1], - tex->fradur[3][0], tex->fradur[3][1] ); - else if( STREQ( name, "animOffset" ) ) - attr = PyInt_FromLong( tex->offset ); - else if( STREQ( name, "animStart" ) ) - attr = PyInt_FromLong( tex->sfra ); - else if( STREQ( name, "brightness" ) ) - attr = PyFloat_FromDouble( tex->bright ); - else if( STREQ( name, "contrast" ) ) - attr = PyFloat_FromDouble( tex->contrast ); - else if( STREQ( name, "crop" ) ) - attr = Py_BuildValue( "(f,f,f,f)", tex->cropxmin, - tex->cropymin, tex->cropxmax, - tex->cropymax ); - else if( STREQ( name, "extend" ) ) - attr = PyInt_FromLong( tex->extend ); - else if( STREQ( name, "fieldsPerImage" ) ) - attr = PyInt_FromLong( tex->fie_ima ); - else if( STREQ( name, "filterSize" ) ) - attr = PyFloat_FromDouble( tex->filtersize ); - else if( STREQ( name, "flags" ) ) - attr = PyInt_FromLong( tex->flag ); - else if( STREQ( name, "image" ) ) - attr = Texture_getImage( self ); - else if( STREQ( name, "imageFlags" ) ) - attr = PyInt_FromLong( tex->imaflag ); - else if( STREQ( name, "name" ) ) - attr = PyString_FromString( tex->id.name + 2 ); - else if( STREQ( name, "noiseDepth" ) ) - attr = PyInt_FromLong( tex->noisedepth ); - else if( STREQ( name, "noiseSize" ) ) - attr = PyFloat_FromDouble( tex->noisesize ); - else if( STREQ( name, "noiseType" ) ) { - if( tex->noisetype == TEX_NOISESOFT ) - attr = PyString_FromString( "soft" ); - else - attr = PyString_FromString( "hard" ); - } else if( STREQ( name, "repeat" ) ) - attr = Py_BuildValue( "(i,i)", tex->xrepeat, tex->yrepeat ); - else if( STREQ( name, "rgbCol" ) ) - attr = Py_BuildValue( "(f,f,f)", tex->rfac, tex->gfac, - tex->gfac ); - else if( STREQ( name, "stype" ) ) - if( self->texture->type == EXPP_TEX_TYPE_ENVMAP ) - attr = PyInt_FromLong( tex->env->stype ); - else - attr = PyInt_FromLong( tex->stype ); - else if( STREQ( name, "turbulence" ) ) - attr = PyFloat_FromDouble( tex->turbul ); - else if( STREQ( name, "type" ) ) - attr = PyInt_FromLong( tex->type ); - else if( STREQ( name, "hFracDim" ) ) - attr = PyInt_FromLong( (long)tex->mg_H ); - else if( STREQ( name, "lacunarity" ) ) - attr = PyFloat_FromDouble( tex->mg_lacunarity ); - else if( STREQ( name, "octs" ) ) - attr = PyFloat_FromDouble( tex->mg_octaves ); - else if( STREQ( name, "iSacale" ) ) - attr = PyFloat_FromDouble( tex->ns_outscale ); - else if( STREQ( name, "exp" ) ) - attr = PyFloat_FromDouble( tex->vn_mexp ); - else if( STREQ( name, "weight1" ) ) - attr = PyFloat_FromDouble( tex->vn_w1 ); - else if( STREQ( name, "weight2" ) ) - attr = PyFloat_FromDouble( tex->vn_w2 ); - else if( STREQ( name, "weight3" ) ) - attr = PyFloat_FromDouble( tex->vn_w3 ); - else if( STREQ( name, "weight4" ) ) - attr = PyFloat_FromDouble( tex->vn_w4 ); - else if( STREQ( name, "distAmnt" ) ) - attr = PyFloat_FromDouble( tex->vn_w4 ); - else if( STREQ( name, "users" ) ) - attr = PyInt_FromLong( tex->id.us ); - - else if( STREQ( name, "__members__" ) ) - attr = Py_BuildValue - ( "[s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s]", - "animFrames", "animLength", "animMontage", - "animOffset", "animStart", "brightness", "contrast", - "crop", "extend", "fieldsPerImage", "filterSize", - "flags", "image", "imageFlags", "name", "noiseDepth", - "noiseSize", "noiseType", "repeat", "rgbCol", - "stype", "turbulence", "type", "hFracDim", - "lacunarity", "octs", "iScale", "exp", "weight1", - "weight2", "weight3", "weight4", "distAmnt", "users" ); +static PyObject *Texture_getWeight3( BPy_Texture *self ) +{ + PyObject *attr = PyFloat_FromDouble( self->texture->vn_w3 ); if( !attr ) - return EXPP_ReturnPyObjError( PyExc_MemoryError, - "couldn't create PyObject" ); - - if( attr != Py_None ) - return attr; /* member attribute found, return it */ - - /* not an attribute, search the methods table */ - return Py_FindMethod( BPy_Texture_methods, ( PyObject * ) self, name ); -} - - -static int Texture_setAttr( BPy_Texture * self, char *name, PyObject * value ) -{ - PyObject *valtuple; - PyObject *error = NULL; - - /* Put "value" in a tuple, because we want to pass it to functions * - * that only accept PyTuples. */ - valtuple = Py_BuildValue( "(O)", value ); - if( !valtuple ) - return EXPP_ReturnIntError( PyExc_MemoryError, - "Texture_setAttr: couldn't create PyTuple" ); - - if( STREQ( name, "animFrames" ) ) - error = Texture_setAnimFrames( self, valtuple ); - else if( STREQ( name, "animLength" ) ) - error = Texture_setAnimLength( self, valtuple ); - else if( STREQ( name, "animMontage" ) ) - error = Texture_setAnimMontage( self, valtuple ); - else if( STREQ( name, "animOffset" ) ) - error = Texture_setAnimOffset( self, valtuple ); - else if( STREQ( name, "animStart" ) ) - error = Texture_setAnimStart( self, valtuple ); - else if( STREQ( name, "brightness" ) ) - error = Texture_setBrightness( self, valtuple ); - else if( STREQ( name, "contrast" ) ) - error = Texture_setContrast( self, valtuple ); - else if( STREQ( name, "crop" ) ) - error = Texture_setCrop( self, valtuple ); - else if( STREQ( name, "extend" ) ) - error = Texture_setIntExtend( self, valtuple ); - else if( STREQ( name, "fieldsPerImage" ) ) - error = Texture_setFieldsPerImage( self, valtuple ); - else if( STREQ( name, "filterSize" ) ) - error = Texture_setFilterSize( self, valtuple ); - else if( STREQ( name, "flags" ) ) - error = Texture_setIntFlags( self, valtuple ); - else if( STREQ( name, "image" ) ) - error = Texture_setImage( self, valtuple ); - else if( STREQ( name, "imageFlags" ) ) - error = Texture_setIntImageFlags( self, valtuple ); - else if( STREQ( name, "name" ) ) - error = Texture_setName( self, valtuple ); - else if( STREQ( name, "noiseDepth" ) ) - error = Texture_setNoiseDepth( self, valtuple ); - else if( STREQ( name, "noiseSize" ) ) - error = Texture_setNoiseSize( self, valtuple ); - else if( STREQ( name, "noiseType" ) ) - error = Texture_setNoiseType( self, valtuple ); - else if( STREQ( name, "repeat" ) ) - error = Texture_setRepeat( self, valtuple ); - else if( STREQ( name, "rgbCol" ) ) - error = Texture_setRGBCol( self, valtuple ); - else if( STREQ( name, "stype" ) ) - error = Texture_setIntSType( self, valtuple ); - else if( STREQ( name, "turbulence" ) ) - error = Texture_setTurbulence( self, valtuple ); - else if( STREQ( name, "type" ) ) - error = Texture_setIntType( self, valtuple ); - else if( STREQ( name, "hFracDim" ) ) - error = Texture_setHFrac( self, valtuple ); - else if( STREQ( name, "lacunarity" ) ) - error = Texture_setLacunarity( self, valtuple ); - else if( STREQ( name, "octs" ) ) - error = Texture_setOcts( self, valtuple ); - else if( STREQ( name, "iScale" ) ) - error = Texture_setiScale( self, valtuple ); - else if( STREQ( name, "exp" ) ) - error = Texture_setExp( self, valtuple ); - else if( STREQ( name, "weight1" ) ) - error = Texture_setW1( self, valtuple ); - else if( STREQ( name, "weight2" ) ) - error = Texture_setW2( self, valtuple ); - else if( STREQ( name, "weight3" ) ) - error = Texture_setW3( self, valtuple ); - else if( STREQ( name, "weight4" ) ) - error = Texture_setW4( self, valtuple ); - else if( STREQ( name, "distAmnt" ) ) - error = Texture_setDistAmnt( self, valtuple ); - - - else { - /* Error */ - Py_DECREF( valtuple ); - return EXPP_ReturnIntError( PyExc_KeyError, - "attribute not found" ); - } + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); + + return attr; +} - Py_DECREF( valtuple ); +static PyObject *Texture_getWeight4( BPy_Texture *self ) +{ + PyObject *attr = PyFloat_FromDouble( self->texture->vn_w4 ); - if( error != Py_None ) - return -1; + if( !attr ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "couldn't get attribute" ); - /* Py_None was INCREF'd by the set*() function, so we need to DECREF it */ - Py_DECREF( Py_None ); + return attr; +} - return 0; +/* #####DEPRECATED###### */ + +static PyObject *Texture_oldsetImage( BPy_Texture * self, PyObject * args ) +{ + return EXPP_setterWrapper( (void *)self, args, + (setter)Texture_setImage ); } -static int Texture_compare( BPy_Texture * a, BPy_Texture * b ) +static PyObject *Texture_oldsetName( BPy_Texture * self, PyObject * args ) { - return ( a->texture == b->texture ) ? 0 : -1; + return EXPP_setterWrapper( (void *)self, args, + (setter)Texture_setName ); } -static PyObject *Texture_repr( BPy_Texture * self ) +static PyObject *Texture_oldsetIpo( BPy_Texture * self, PyObject * args ) { - return PyString_FromFormat( "[Texture \"%s\"]", - self->texture->id.name + 2 ); + return EXPP_setterWrapper ( (void *)self, args, (setter)Texture_setIpo ); } -static PyObject *Texture_getIpo( BPy_Texture * self ) +/* + * clearIpo() returns True/False depending on whether material has an Ipo + */ + +static PyObject *Texture_clearIpo( BPy_Texture * self ) { - struct Ipo *ipo = self->texture->ipo; + /* if Ipo defined, delete it and return true */ - if( !ipo ) { - Py_INCREF( Py_None ); - return Py_None; + if( self->texture->ipo ) { + PyObject *value = Py_BuildValue( "(O)", Py_None ); + EXPP_setterWrapper( (void *)self, value, (setter)Texture_setIpo ); + Py_DECREF( value ); + return EXPP_incr_ret_True(); } + return EXPP_incr_ret_False(); /* no ipo found */ +} - return Ipo_CreatePyObject( ipo ); +/* + * these older setter methods take strings as parameters; check the list of + * strings to figure out which bits to set, then call new attribute setters + * using the wrapper. + */ + +static PyObject *Texture_oldsetFlags( BPy_Texture * self, PyObject * args ) +{ + unsigned int i, flag = 0; + PyObject *value, *error; + + /* check that we're passed a tuple */ + + if ( !PyTuple_Check( args ) ) + return EXPP_ReturnPyObjError ( PyExc_AttributeError, + "expected a tuple of string arguments" ); + + /* check each argument for type, find its value */ + + for ( i = PyTuple_Size( args ); i-- ; ) { + short thisflag; + char * name = PyString_AsString( PySequence_Fast_GET_ITEM( args, i ) ); + if( !name ) + return EXPP_ReturnPyObjError ( PyExc_AttributeError, + "expected string argument" ); + + if( !EXPP_map_getShortVal( tex_flag_map, name, &thisflag ) ) + return ( EXPP_ReturnPyObjError( PyExc_AttributeError, + "unknown Texture flag argument" ) ); + + flag |= thisflag; + } + + /* build tuple, call wrapper */ + + value = Py_BuildValue( "(i)", flag ); + error = EXPP_setterWrapper( (void *)self, value, (setter)Texture_setFlags ); + Py_DECREF ( value ); + return error; } -extern PyTypeObject Ipo_Type; +/* + * Texture_oldsetType() and Texture_oldsetExtend() + * + * These older setter methods convert a string into an integer setting, so + * doesn't make sense to try wrapping them. + */ -static PyObject *Texture_setIpo( BPy_Texture * self, PyObject * args ) +static PyObject *Texture_oldsetType( BPy_Texture * self, PyObject * args ) { - PyObject *pyipo = 0; - Ipo *ipo = NULL; - Ipo *oldipo; + char *type = NULL; - if( !PyArg_ParseTuple( args, "O!", &Ipo_Type, &pyipo ) ) + if( !PyArg_ParseTuple( args, "s", &type ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected Ipo as argument" ); + "expected string argument" ); + + if( !EXPP_map_getShortVal( tex_type_map, type, &self->texture->type ) ) + return EXPP_ReturnPyObjError( PyExc_ValueError, + "invalid texture type" ); - ipo = Ipo_FromPyObject( pyipo ); + /* + * if we set the texture OK, and it's a environment map, and + * there is no environment map yet, allocate one (code borrowed + * from texture_panel_envmap() in source/blender/src/buttons_shading.c) + */ - if( !ipo ) - return EXPP_ReturnPyObjError( PyExc_RuntimeError, - "null ipo!" ); + if( self->texture->type == TEX_ENVMAP + && !self->texture->env ) { + self->texture->env = RE_add_envmap(); + self->texture->env->object= OBACT; + } - if( ipo->blocktype != ID_TE ) + Py_INCREF( Py_None ); + return Py_None; +} + +static PyObject *Texture_oldsetExtend( BPy_Texture * self, PyObject * args ) +{ + char *extend = NULL; + if( !PyArg_ParseTuple( args, "s", &extend ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, - "this ipo is not a texture data ipo" ); + "expected string argument" ); - oldipo = self->texture->ipo; - if( oldipo ) { - ID *id = &oldipo->id; - if( id->us > 0 ) - id->us--; - } + if( !EXPP_map_getShortVal + ( tex_extend_map, extend, &self->texture->extend ) ) + return EXPP_ReturnPyObjError( PyExc_ValueError, + "invalid extend mode" ); - ( ( ID * ) & ipo->id )->us++; + Py_INCREF( Py_None ); + return Py_None; +} - self->texture->ipo = ipo; +/* + * Texture_oldsetNoiseBasis(), Texture_oldsetDistNoise() + * Texture_oldsetSType(), Texture_oldsetDistMetric(), + * Texture_oldsetImageFlags() + * + * these old setter methods behave differently from the attribute + * setters, so they are left unchanged. + */ + +static PyObject *Texture_oldsetNoiseBasis( BPy_Texture * self, PyObject * args ) +{ +/* NOTE: leave as-is: don't use setterWrapper */ + char *nbasis; + + if( !PyArg_ParseTuple( args, "s", &nbasis ) ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected string argument" ); + if( self->texture->type == TEX_MUSGRAVE && + EXPP_map_getShortVal( tex_stype_map[TEX_DISTNOISE], + nbasis, &self->texture->noisebasis ) ); + else if( self->texture->type == TEX_DISTNOISE && + !EXPP_map_getShortVal( tex_stype_map[TEX_DISTNOISE], + nbasis, &self->texture->noisebasis2 ) ) + return EXPP_ReturnPyObjError( PyExc_ValueError, + "invalid noise basis" ); Py_INCREF( Py_None ); return Py_None; } -static PyObject *Texture_clearIpo( BPy_Texture * self ) +static PyObject *Texture_oldsetDistNoise( BPy_Texture * self, PyObject * args ) { - Tex *tex = self->texture; - Ipo *ipo = ( Ipo * ) tex->ipo; +/* NOTE: leave as-is: don't use setterWrapper */ + char *nbasis; - if( ipo ) { - ID *id = &ipo->id; - if( id->us > 0 ) - id->us--; - tex->ipo = NULL; + if( !PyArg_ParseTuple( args, "s", &nbasis ) ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected string argument" ); + if( self->texture->type == TEX_DISTNOISE && + !EXPP_map_getShortVal( tex_stype_map[TEX_DISTNOISE], + nbasis, &self->texture->noisebasis ) ) + return EXPP_ReturnPyObjError( PyExc_ValueError, + "invalid noise basis" ); - return EXPP_incr_ret_True(); + Py_INCREF( Py_None ); + return Py_None; +} + +static PyObject *Texture_oldsetSType( BPy_Texture * self, PyObject * args ) +{ + char *stype = NULL; + if( !PyArg_ParseTuple( args, "s", &stype ) ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected string argument" ); + + /* can we really trust texture->type? */ + if( ( self->texture->type == TEX_VORONOI && + EXPP_map_getShortVal( tex_stype_map[self->texture->type], + stype, &self->texture->vn_coltype ) ) ); +#if 0 + else if( ( self->texture->type == TEX_MUSGRAVE && + EXPP_map_getShortVal( tex_stype_map + [TEX_DISTNOISE], stype, + &self->texture->noisebasis ) ) ); +#endif + else if( ( self->texture->type == TEX_ENVMAP && + EXPP_map_getShortVal( tex_stype_map[self->texture->type], + stype, &self->texture->env->stype ) ) ); + else if( !EXPP_map_getShortVal + ( tex_stype_map[self->texture->type], stype, + &self->texture->stype ) ) + return EXPP_ReturnPyObjError( PyExc_ValueError, + "invalid texture stype" ); + + Py_INCREF( Py_None ); + return Py_None; +} + +static PyObject *Texture_oldsetDistMetric( BPy_Texture * self, PyObject * args ) +{ +/* NOTE: leave as-is: don't use setterWrapper */ + char *dist = NULL; + + if( !PyArg_ParseTuple( args, "s", &dist ) ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected string argument" ); + /* can we really trust texture->type? */ + if( self->texture->type == TEX_VORONOI && + !EXPP_map_getShortVal( tex_stype_map[self->texture->type + 2], + dist, &self->texture->vn_distm ) ) + return EXPP_ReturnPyObjError( PyExc_ValueError, + "invalid dist metric type" ); + + Py_INCREF( Py_None ); + return Py_None; +} + +static PyObject *Texture_oldsetImageFlags( BPy_Texture * self, PyObject * args ) +{ + unsigned int i, flag = 0; + + /* check that we're passed a tuple of no more than 3 args*/ + + if( !PyTuple_Check( args ) ) + return EXPP_ReturnPyObjError ( PyExc_AttributeError, + "expected tuple of string arguments" ); + + /* check each argument for type, find its value */ + + for( i = PyTuple_Size( args ); i-- ; ) { + short thisflag; + char * name = PyString_AsString( PySequence_Fast_GET_ITEM( args, i ) ); + if( !name ) + return EXPP_ReturnPyObjError ( PyExc_AttributeError, + "expected string argument" ); + + if( !EXPP_map_getShortVal( tex_imageflag_map, name, &thisflag ) ) + return EXPP_ReturnPyObjError( PyExc_ValueError, + "unknown Texture image flag name" ); + + flag |= thisflag; } - return EXPP_incr_ret_False(); /* no ipo found */ + self->texture->imaflag = flag; + + Py_INCREF( Py_None ); + return Py_None; } + diff --git a/source/blender/python/api2_2x/doc/Lamp.py b/source/blender/python/api2_2x/doc/Lamp.py index 98a1d223e55..cd90cb5fc8a 100644 --- a/source/blender/python/api2_2x/doc/Lamp.py +++ b/source/blender/python/api2_2x/doc/Lamp.py @@ -17,6 +17,25 @@ Example:: l.setMode('square', 'shadow') # set these two lamp mode flags ob = Object.New('Lamp') # create new lamp object ob.link(l) # link lamp obj with lamp data + +@type Types: read-only dictionary +@var Types: The lamp types. + - 'Lamp': 0 + - 'Sun' : 1 + - 'Spot': 2 + - 'Hemi': 3 + - 'Area': 4 + - 'Photon': 5 +@type Modes: read-only dictionary +@var Modes: The lamp modes. Modes may be ORed together. + - 'Shadows' + - 'Halo' + - 'Layer' + - 'Quad' + - 'Negative' + - 'OnlyShadow' + - 'Sphere' + - 'Square' """ def New (type = 'Lamp', name = 'LampData'): @@ -46,44 +65,73 @@ class Lamp: The Lamp Data object ==================== This object gives access to Lamp-specific data in Blender. - @ivar name: The Lamp Data name. - @ivar type: The Lamp type (see the Types dict). - @cvar Types: The Types dictionary. - - 'Lamp': 0 - - 'Sun' : 1 - - 'Spot': 2 - - 'Hemi': 3 - - 'Area': 4 - - 'Photon': 5 - @ivar mode: The mode flags: B{or'ed value} of the flags in the Modes dict. - @cvar Modes: The Modes dictionary. - - 'Shadows' - - 'Halo' - - 'Layer' - - 'Quad' - - 'Negative' - - 'OnlyShadow' - - 'Sphere' - - 'Square' - @ivar samples: The number of shadow map samples in [1, 16]. - @ivar bufferSize: The size of the shadow buffer in [512, 5120]. - @ivar haloStep: Volumetric halo sampling frequency in [0, 12]. - @ivar energy: The intensity of the light in [0.0, 10.0]. - @ivar dist: The distance value in [0.1, 5000.0]. - @ivar spotSize: The angle of the spot beam in degrees in [1.0, 180.0]. - @ivar spotBlend: The softness of the spot edge in [0.0, 1.0]. - @ivar clipStart: The shadow map clip start in [0.1, 1000.0]. - @ivar clipEnd: The shadow map clip end in [1.0, 5000.0]. - @ivar bias: The shadow map sampling bias in [0.01, 5.00]. - @ivar softness: The size of the shadow sample area in [1.0, 100.0]. - @ivar haloInt: The intensity of the spot halo in [0.0, 5.0]. - @ivar quad1: Light intensity value 1 for a Quad lamp in [0.0, 1.0]. - @ivar quad2: Light intensity value 2 for a Quad lamp in [0.0, 1.0]. - @ivar col: The color of the light, with each rgb component in [0.0, 1.0]. - This is an rgb tuple whose values can be accessed in many ways: - - as a tuple: lamp.col, lamp.col[0], same for 1 and 2. - - as a dictionary: lamp.col['R'], same for 'G' and 'B'. - - as an object: lamp.col.R, same for G and B. + + @ivar B: Lamp color blue component. + Value is clamped to the range [0.0,1.0]. + @type B: float + @ivar G: Lamp color green component. + Value is clamped to the range [0.0,1.0]. + @type G: float + @ivar R: Lamp color red component. + Value is clamped to the range [0.0,1.0]. + @type R: float + @ivar bias: Lamp shadow map sampling bias. + Value is clamped to the range [0.01,5.0]. + @type bias: float + @ivar bufferSize: Lamp shadow buffer size. + Value is clamped to the range [512,5120]. + @type bufferSize: int + @ivar clipEnd: Lamp shadow map clip end. + Value is clamped to the range [1.0,5000.0]. + @type clipEnd: float + @ivar clipStart: Lamp shadow map clip start. + Value is clamped to the range [0.1,1000.0]. + @type clipStart: float + @ivar col: Lamp RGB color triplet. + Components are clamped to the range [0.0,1.0]. + @type col: RGB tuple + @ivar dist: Lamp clipping distance. + Value is clamped to the range [0.1,5000.0]. + @type dist: float + @ivar energy: Lamp light intensity. + Value is clamped to the range [0.0,10.0]. + @type energy: float + @ivar haloInt: Lamp spotlight halo intensity. + Value is clamped to the range [0.0,5.0]. + @type haloInt: float + @ivar haloStep: Lamp volumetric halo sampling frequency. + Value is clamped to the range [0,12]. + @type haloStep: int + @ivar ipo: Lamp Ipo. + Contains the Ipo if one is assigned to the object, B{None} otherwise. Setting to B{None} clears the current Ipo.. + @type ipo: Blender Ipo + @ivar mode: Lamp mode bitfield. See L{Modes} for values. + @type mode: int + @ivar name: Lamp data name. + @type name: str + @ivar quad1: Quad lamp linear distance attenuation. + Value is clamped to the range [0.0,1.0]. + @type quad1: float + @ivar quad2: Quad lamp quadratic distance attenuation. + Value is clamped to the range [0.0,1.0]. + @type quad2: float + @ivar samples: Lamp shadow map samples. + Value is clamped to the range [1,16]. + @type samples: int + @ivar softness: Lamp shadow sample area size. + Value is clamped to the range [1.0,100.0]. + @type softness: float + @ivar spotBlend: Lamp spotlight edge softness. + Value is clamped to the range [0.0,1.0]. + @type spotBlend: float + @ivar spotSize: Lamp spotlight beam angle (in degrees). + Value is clamped to the range [1.0,180.0]. + @type spotSize: float + @ivar type: Lamp type. See L{Types} for values. + @type type: int + @ivar users: Number of lamp users. + @type users: int + @warning: Most member variables assume values in some [Min, Max] interval. When trying to set them, the given parameter will be clamped to lie in that range: if val < Min, then val = Min, if val > Max, then val = Max. diff --git a/source/blender/python/api2_2x/doc/Material.py b/source/blender/python/api2_2x/doc/Material.py index 8d74162e17a..80d741d1d9f 100644 --- a/source/blender/python/api2_2x/doc/Material.py +++ b/source/blender/python/api2_2x/doc/Material.py @@ -57,7 +57,6 @@ Example:: uses an already taken value is preceded by "-" and appear below the normal mode which also uses that value. - @type Shaders: readonly dictionary @var Shaders: The available Material Shaders. - DIFFUSE_LAMBERT - Make Material use the lambert diffuse shader. @@ -96,59 +95,173 @@ class Material: The Material object =================== This object gives access to Materials in Blender. - @ivar name: Material's name. - @type mode: int - @ivar mode: Mode flags as an or'ed int value. See the Modes dictionary keys - and descriptions in L{Modes}. - @ivar rgbCol: Material's RGB color triplet sequence. - @ivar specCol: Specular color rgb triplet sequence. - @ivar mirCol: Mirror color rgb triplet sequence. - @ivar R: Red component of L{rgbCol} - [0.0, 1.0]. - @ivar G: Green component of L{rgbCol} - [0.0, 1.0]. - @ivar B: Blue component of L{rgbCol} - [0.0, 1.0]. - @ivar alpha: Alpha (translucency) component of the Material - [0.0, 1.0]. - @ivar amb: Ambient factor - [0.0, 1.0]. - @ivar emit: Emitting light intensity - [0.0, 1.0]. - @ivar ref: Reflectivity - [0.0, 1.0]. - @ivar spec: Specularity - [0.0, 2.0]. - @ivar specTransp: Specular transparency - [0.0, 1.0]. - @ivar add: Glow factor - [0.0, 1.0]. - @ivar zOffset: Artificial Z offset for faces - [0.0, 10.0]. - @ivar haloSize: Dimension of the halo - [0.0, 100.0]. - @ivar flareSize: Factor the flare is larger than the halo - [0.1, 25.0]. - @ivar flareBoost: Flare's extra strength - [0.1, 10.0]. - @ivar haloSeed: To use random values for ring dimension and line location - - [0, 255]. - @ivar flareSeed: Offset in the seed table - [0, 255]. - @ivar subSize: Dimension of subflares, dots and circles - [0.1, 25.0]. - @ivar hard: Hardness of the specularity - [1, 255]. - @ivar nFlares: Number of halo subflares - [1, 32]. - @ivar nStars: Number of points on the halo stars - [3, 50]. - @ivar nLines: Number of star shaped lines on each halo - [0, 250]. - @ivar nRings: Number of halo rings - [0, 24]. - @type ipo: Blender Ipo - @ivar ipo: This Material's ipo. - @ivar rayMirr: Amount mirror reflection for raytrace. - @ivar rayMirrDepth: Amount of inter-reflections calculated maximal. - @ivar fresnelDepth: Power of Fresnel for mirror reflection. - @ivar fresnelDepthFac: Blending factor for Fresnel. - @ivar IOR: Sets the angular index of refraction for raytrace. - @ivar transDepth: Amount of refractions calculated maximal. - @ivar fresnelTrans: Power of Fresnel for transparency. - @ivar fresnelTransFac: Blending factor for Fresnel. - @ivar specTrans: Makes specular areas opaque on transparent materials. - @cvar specShader: Specular shader from one of the shaders in Material.Shaders dict - [0, 4]. - @cvar diffuseShader: Diffuse shader from one of the shaders in Material.Shaders dict - [0, 3]. - @cvar roughness: Material's Roughness (applies to the \"Oren Nayar\" Diffuse Shader only) - [0.0, 3.14]. - @cvar specSize: Material's size of speculara area (applies to the \"Toon\" Specular Shader only) - [0.0, 1.53]. - @cvar diffuseSize: Material's size of diffuse area (applies to the \"Toon\" Diffuse Shader only) - [0.0, 3.14]. - @cvar specSmooth: Material's smoothing of specular area (applies to the \"Toon\" Specular Shader only) - [0.0, 1.0]. - @cvar diffuseSmooth: Material's smoothing of diffuse area (applies to the \"Toon\" Diffuse Shader only) - [0.0, 1.0]. - @cvar diffuseDarkness: Material's diffuse darkness (applies to the \"Minnaert\" Diffuse Shader only) - [0.0, 2.0]. - @cvar refracIndex: Material's Index of Refraction (applies to the \"Blinn\" Specular Shader only) - [1.0, 10.0]. - @cvar rms: Material's standard deviation of surface slope (applies to the \"WardIso\" Specular Shader only) - [0.0, 0.4]. - @cvar filter: Amount of filtering when transparent raytrace is enabled - [0.0, 1.0]. - @cvar translucency: Amount of diffuse shading of the back side - [0.0, 1.0]. + @ivar B: Diffuse color (L{rgbCol}) blue component. + Value is clamped to the range [0.0,1.0]. + @type B: float + @ivar G: Diffuse color (L{rgbCol}) green component. + Value is clamped to the range [0.0,1.0]. + @type G: float + @ivar IOR: Angular index of refraction for raytrace. + Value is clamped to the range [1.0,3.0]. + @type IOR: float + @ivar R: Diffuse color (L{rgbCol}) red component. + Value is clamped to the range [0.0,1.0]. + @type R: float + @ivar add: Strength of the add effect. + Value is clamped to the range [0.0,1.0]. + @type add: float + @ivar alpha: Alpha (translucency) component of the material. + Value is clamped to the range [0.0,1.0]. + @type alpha: float + @ivar amb: Amount of global ambient color material receives. + Value is clamped to the range [0.0,1.0]. + @type amb: float + @ivar diffuseDarkness: Material's diffuse darkness ("Minnaert" diffuse shader only). + Value is clamped to the range [0.0,2.0]. + @type diffuseDarkness: float + @ivar diffuseShader: Diffuse shader type (see L{Shaders}). + Value must be in the range [0,3]. + @type diffuseShader: int + @ivar diffuseSize: Material's diffuse area size ("Toon" diffuse shader only). + Value is clamped to the range [0.0,3.14]. + @type diffuseSize: float + @ivar diffuseSmooth: Material's diffuse area smoothing ("Toon" diffuse shader only). + Value is clamped to the range [0.0,1.0]. + @type diffuseSmooth: float + @ivar emit: Amount of light the material emits. + Value is clamped to the range [0.0,1.0]. + @type emit: float + @ivar filter: Amount of filtering when transparent raytrace is enabled. + Value is clamped to the range [0.0,1.0]. + @type filter: float + @ivar flareBoost: Flare's extra strength. + Value is clamped to the range [0.1,1.0]. + @type flareBoost: float + @ivar flareSeed: Offset in the flare seed table. + Value is clamped to the range [1,255]. + @type flareSeed: int + @ivar flareSize: Ratio of flare size to halo size. + Value is clamped to the range [0.1,25.0]. + @type flareSize: float + @ivar fresnelDepth: Power of Fresnel for mirror reflection. + Value is clamped to the range [0.0,5.0]. + @type fresnelDepth: float + @ivar fresnelDepthFac: Blending factor for Fresnel mirror. + Value is clamped to the range [1.0,5.0]. + @type fresnelDepthFac: float + @ivar fresnelTrans: Power of Fresnel for transparency. + Value is clamped to the range [0.0,5.0]. + @type fresnelTrans: float + @ivar fresnelTransFac: Blending factor for Fresnel transparency. + Value is clamped to the range [1.0,5.0]. + @type fresnelTransFac: float + @ivar haloSeed: Randomizes halo ring dimension and line location. + Value is clamped to the range [1,255]. + @type haloSeed: int + @ivar haloSize: Dimension of the halo. + Value is clamped to the range [0.0,100.0]. + @type haloSize: float + @ivar hard: Hardness of the specularity. + Value is clamped to the range [1,255]. + @type hard: int + @ivar ipo: Material Ipo data. + Contains the Ipo if one is assigned to the object, None otherwise. Setting to None clears the current Ipo. + @type ipo: Blender Ipo + @ivar mirB: Mirror color (L{mirCol}) blue component. + Value is clamped to the range [0.0,1.0]. + @type mirB: float + @ivar mirCol: Mirror RGB color triplet. + Components are clamped to the range [0.0,1.0]. + @type mirCol: list of 3 floats + @ivar mirG: Mirror color (L{mirCol}) green component. + Value is clamped to the range [0.0,1.0]. + @type mirG: float + @ivar mirR: Mirror color (L{mirCol}) red component. + Value is clamped to the range [0.0,1.0]. + @type mirR: float + @ivar mode: Mode mode bitfield. See L{the Modes dictionary<Modes>} keys and descriptions. + @type mode: int + @ivar nFlares: Number of subflares with halo. + Value is clamped to the range [1,32]. + @type nFlares: int + @ivar nLines: Number of star-shaped lines with halo. + Value is clamped to the range [0,250]. + @type nLines: int + @ivar nRings: Number of rings with halo. + Value is clamped to the range [0,24]. + @type nRings: int + @ivar nStars: Number of star points with halo. + Value is clamped to the range [3,50]. + @type nStars: int + @ivar name: Material data name. + @type name: str + @ivar oopsLoc: Material OOPs location. Returns None if materal not found in list. + @type oopsLoc: list of 2 floats + @ivar oopsSel: Material OOPs selection flag. + Value must be in the range [0,1]. + @type oopsSel: int + @ivar rayMirr: Mirror reflection amount for raytrace. + Value is clamped to the range [0.0,1.0]. + @type rayMirr: float + @ivar rayMirrDepth: Amount of raytrace inter-reflections. + Value is clamped to the range [0,10]. + @type rayMirrDepth: int + @ivar ref: Amount of reflections (for shader). + Value is clamped to the range [0.0,1.0]. + @type ref: float + @ivar refracIndex: Material's Index of Refraction (applies to the "Blinn" Specular Shader only. + Value is clamped to the range [1.0,10.0]. + @type refracIndex: float + @ivar rgbCol: Diffuse RGB color triplet. + Components are clamped to the range [0.0,1.0]. + @type rgbCol: list of 3 floats + @ivar rms: Material's surface slope standard deviation ("WardIso" specular shader only). + Value is clamped to the range [0.0,0.4]. + @type rms: float + @ivar roughness: Material's roughness ("Oren Nayar" diffuse shader only). + Value is clamped to the range [0.0,3.14]. + @type roughness: float + @ivar spec: Degree of specularity. + Value is clamped to the range [0.0,2.0]. + @type spec: float + @ivar specB: Specular color (L{specCol}) blue component. + Value is clamped to the range [0.0,1.0]. + @type specB: float + @ivar specCol: Specular RGB color triplet. + Components are clamped to the range [0.0,1.0]. + @type specCol: list of 3 floats + @ivar specG: Specular color (L{specCol}) green component. + Value is clamped to the range [0.0,1.0]. + @type specG: float + @ivar specR: Specular color (L{specCol}) red component. + Value is clamped to the range [0.0,1.0]. + @type specR: float + @ivar specShader: Specular shader type. See L{Shaders}. + Value must be in the range [0,4]. + @type specShader: int + @ivar specSize: Material's specular area size ("Toon" specular shader only). + Value is clamped to the range [0.0,1.53]. + @type specSize: float + @ivar specSmooth: Sets the smoothness of specular toon area. + Value is clamped to the range [0.0,1.0]. + @type specSmooth: float + @ivar specTransp: Makes specular areas opaque on transparent materials. + Value is clamped to the range [0.0,1.0]. + @type specTransp: float + @ivar subSize: Dimension of subflares, dots and circles. + Value is clamped to the range [0.1,25.0]. + @type subSize: float + @ivar transDepth: calculated maximal. Amount of refractions for raytrace. + Value is clamped to the range [0,10]. + @type transDepth: int + @ivar translucency: Amount of diffuse shading of the back side. + Value is clamped to the range [0.0,1.0]. + @type translucency: float + @ivar users: Number of material users. + @type users: int + @ivar zOffset: Artificial offset in the Z buffer (for Ztransp option). + Value is clamped to the range [0.0,10.0]. + @type zOffset: float @warning: Most member variables assume values in some [Min, Max] interval. When trying to set them, the given parameter will be clamped to lie in that range: if val < Min, then val = Min, if val > Max, then val = Max. diff --git a/source/blender/python/api2_2x/doc/Texture.py b/source/blender/python/api2_2x/doc/Texture.py index e05d81fb1b7..454a6efa40d 100644 --- a/source/blender/python/api2_2x/doc/Texture.py +++ b/source/blender/python/api2_2x/doc/Texture.py @@ -4,7 +4,6 @@ # Written by Alex Mole # - """ The Blender.Texture submodule. @@ -46,11 +45,16 @@ Example:: - IMAGE - Image texture - PLUGIN - Plugin texture - ENVMAP - EnvMap texture + - MUSGRAVE - Musgrave procedural texture + - VORONOI - Voronoi procedural texture + - DISTNOISE - Distorted noise texture @type Flags: readonly dictionary @var Flags: The available Texture flags: - FLIPBLEND - Flips the blend texture's X and Y directions - NEGALPHA - Reverse the alpha value + - CHECKER_ODD - Fill the "odd" checkerboard tiles + - CHECKER_EVEN - Fill the "even" checkerboard tiles @type ImageFlags: readonly dictionary @var ImageFlags: The available image flags for Texture.imageFlags: @@ -67,11 +71,31 @@ Example:: - NORMALMAP - Use image RGB values for normal mapping @type ExtendModes: readonly dictionary -@var ExtendModes: Extend, clamp or repeat modes for images +@var ExtendModes: Extend, clip, repeat or checker modes for image textures - EXTEND - Extends the colour of the edge - CLIP - Return alpha 0.0 outside image - CLIPCUBE - Return alpha 0.0 around cube-shaped area around image - REPEAT - Repeat image vertically and horizontally + - CHECKER - Repeat image in checkerboard pattern + +@type Noise: readonly dictionary +@var Noise: Noise types and bases. SINE, SAW and TRI are only used for + marble and wood textures, while the remainder are used for all textures + which has a noise basis function (for these textures, the constant should + be used with the second noise basis setting). + - SINE - Produce bands using sine wave (marble, wood textures) + - SAW - Produce bands using saw wave (marble, wood textures) + - TRI - Produce bands using triangle wave (marble, wood textures) + - BLENDER - Original Blender algorithm + - PERLIN - Ken Perlin's original (1985) algorithm + - IMPROVEPERLIN - Ken Perlin's newer (2002) algorithm + - VORONOIF1 - none + - VORONOIF2 - none + - VORONOIF3 - none + - VORONOIF4 - none + - VORONOIF2F1 - none + - VORONOICRACKLE - none + - CELLNOISE - Steven Worley's cellular basis algorithm (1996) @type STypes: readonly dictionary @var STypes: Texture-type specific data. Depending on the value of @@ -113,6 +137,28 @@ Example:: - ENV_STATIC - Calculate map only once - ENV_ANIM - Calculate map each rendering - ENV_LOAD - Load map from disk + 11. Musgrave type + - MUS_MFRACTAL - Hetero Multifractal + - MUS_RIDGEDMF - Ridged Multifractal + - MUS_HYBRIDMF - Hybrid Multifractal + - MUS_FBM - Fractal Brownian Motion + - MUS_HTERRAIN - Hetero Terrain + 12. Voronoi type + - VN_INT - Only calculate intensity + - VN_COL1 - Color cells by position + - VN_COL2 - Same as Col1 plus outline based on F2-F1 + - VN_COL3 - Same as Col2 multiplied by intensity + 13. Distorted noise type + - DN_BLENDER - Original Blender algorithm + - DN_PERLIN - Ken Perlin's original (1985) algorithm + - DN_IMPROVEPERLIN - Ken Perlin's newer (2002) algorithm + - DN_VORONOIF1 - none + - DN_VORONOIF2 - none + - DN_VORONOIF3 - none + - DN_VORONOIF4 - none + - DN_VORONOIF2F1 - none + - DN_VORONOICRACKLE - none + - DN_CELLNOISE - Steven Worley's cellular basis algorithm (1996) @var TexCo: Flags for MTex.texco. - ORCO - Use the original coordinates of the mesh @@ -166,41 +212,146 @@ class Texture: ================== This object gives access to Texture-specific data in Blender. - Note that many of the attributes of this object are only relevant if - specific modes are enabled. - - @ivar name: The Texture name. - @ivar type: The Texture type. See L{Types} - @ivar flags: The texture flags (OR'd together). See L{Flags} - @ivar imageFlags: The texture image flags (OR'd tegether). - See L{ImageFlags} - @ivar stype: Texture-type specific data. See L{STypes} - @ivar image: The image associated with this texture, or None. - @type image: Blender Image - @ivar rgbCol: The texture's RGB color triplet. - @ivar brightness: The brightness in range [0,2]. - @ivar contrast: The contrast in range [0,2]. - @ivar filterSize: The filter size for the image. - @ivar extend: Texture extend/repeat mode. See L{ExtendModes} - @ivar crop: Tuple of image crop values as floats, - like C{(xmin, ymin, xmax, ymax)} - @ivar repeat: Tuple of image repeat values as ints, like - C{(xrepeat, yrepeat)} - @ivar noiseSize: The noise size. - @ivar noiseDepth: The noise depth. - @ivar noiseType: The noise type: 'soft' or 'hard'. - @ivar animLength: Length of the animation. - @ivar animFrames: Frames of the animation. - @ivar animOffset: The number of the first picture of the animation. - @ivar animStart: Start frame of the animation. - @ivar fieldsPerImage: The number of fields per rendered frame. - @ivar animMontage: Montage mode data as a tuple of tuples, like - C{( (fra1,dur1), (fra2,dur2), (fra3,dur3), (fra4,dur4) )} + Note that many of the attributes of this object are only relevant for + specific texture types. + + @ivar animFrames: Number of frames of a movie to use. + Value is clamped to the range [0,30000]. + @type animFrames: int + @ivar animLength: Number of frames of a movie to use (0 for all). + Value is clamped to the range [0,9000]. + @type animLength: int + @ivar animMontage: Montage mode, start frames and durations. Example: C{( (fra1,dur1), (fra2,dur2), (fra3,dur3), (fra4,dur4) )}. + @type animMontage: tuple of 4 (int,int) + @ivar animOffset: Offsets the number of the first movie frame to use. + Value is clamped to the range [-9000,9000]. + @type animOffset: int + @ivar animStart: Starting frame of the movie to use. + Value is clamped to the range [1,9000]. + @type animStart: int + @ivar anti: Image anti-aliasing enabled. Also see L{ImageFlags}. + @type anti: int + @ivar brightness: Changes the brightness of a texture's color. + Value is clamped to the range [0.0,2.0]. + @type brightness: float + @ivar calcAlpha: Calculation of image's alpha channel enabled. Also see L{ImageFlags}. + @type calcAlpha: int + @ivar contrast: Changes the contrast of a texture's color. + Value is clamped to the range [0.01,5.0]. + @type contrast: float + @ivar crop: Sets the cropping extents (for image textures). + @type crop: tuple of 4 ints + @ivar cyclic: Looping of animated frames enabled. Also see L{ImageFlags}. + @type cyclic: int + @ivar distAmnt: Amount of distortion (for distorted noise textures). + Value is clamped to the range [0.0,10.0]. + @type distAmnt: float + @ivar distMetric: The distance metric (for Voronoi textures). + @type distMetric: int + @ivar exp: Minkovsky exponent (for Minkovsky Voronoi textures). + Value is clamped to the range [0.01,10.0]. + @type exp: float + @ivar extend: Texture's 'Extend' mode (for image textures). See L{ExtendModes}. + @type extend: int + @ivar fields: Use of image's fields enabled. Also see L{ImageFlags}. + @type fields: int + @ivar fieldsPerImage: Number of fields per rendered frame. + Value is clamped to the range [1,200]. + @type fieldsPerImage: int + @ivar filterSize: The filter size (for image and envmap textures). + Value is clamped to the range [0.1,25.0]. + @type filterSize: float + @ivar flags: Texture's 'Flag' bitfield. See L{Flags}. + bitmask. + @type flags: int + @ivar hFracDim: Highest fractional dimension (for Musgrave textures). + Value is clamped to the range [0.0001,2.0]. + @type hFracDim: float + @ivar iScale: Intensity output scale (for Musgrave and Voronoi textures). + Value is clamped to the range [0.0,10.0]. + @type iScale: float + @ivar image: Texture's image object. + @type image: Blender Image (or None) + @ivar imageFlags: Texture's 'ImageFlags' bits. + @type imageFlags: int + @ivar interpol: Interpolate image's pixels to fit texture mapping enabled. Also see L{ImageFlags}. + @type interpol: int + @ivar ipo: Texture Ipo data. + Contains the Ipo if one is assigned to the object, B{None} otherwise. Setting to B{None} clears the current Ipo.. + @type ipo: Blender Ipo + @ivar lacunarity: Gap between succesive frequencies (for Musgrave textures). + Value is clamped to the range [0.0,6.0]. + @type lacunarity: float + @ivar mipmap: Mipmaps enabled. Also see L{ImageFlags}. + @type mipmap: int + @ivar movie: Movie frames as images enabled. Also see L{ImageFlags}. + @type movie: int + @ivar name: Texture data name. + @type name: string + @ivar noiseBasis: Noise basis type (wood, stucci, marble, clouds, + Musgrave, distorted). See L{Noise} dictionary. + @type noiseBasis: int + @ivar noiseBasis2: Additional noise basis type (wood, marble, distorted + noise). See L{Noise} dictionary. + @type noiseBasis2: int + @ivar noiseDepth: Noise depth (magic, marble, clouds). + Value is clamped to the range [0,6]. + @type noiseDepth: int + @ivar noiseSize: Noise size (wood, stucci, marble, clouds, Musgrave, + distorted noise). + Value is clamped to the range [0.0001,2.0]. + @type noiseSize: float + @ivar noiseType: Noise type (for wood, stucci, marble, clouds textures). Valid values are 'hard' or 'soft'. + @type noiseType: string + @ivar normalMap: Use of image RGB values for normal mapping enabled. + Also see L{ImageFlags}. + @type normalMap: int + @ivar octs: Number of frequencies (for Musgrave textures). + Value is clamped to the range [0.0,8.0]. + @type octs: float + @ivar repeat: Repetition multiplier (for image textures). + @type repeat: tuple of 2 ints + @ivar rgbCol: RGB color tuple. + @type rgbCol: tuple of 3 floats + @ivar rot90: X/Y flip for rendering enabled. Also see L{ImageFlags}. + @type rot90: int + @ivar saw: Produce bands using saw wave (marble, wood textures). Also see L{Noise}. + @type saw: int + @ivar sine: Produce bands using sine wave (marble, wood textures). Also see L{Noise}. + @type sine: int + @ivar stField: Standard field deinterlacing enabled. Also see L{ImageFlags}. + @type stField: int + @ivar stype: Texture's 'SType' mode. See L{STypes}. + @type stype: int + @ivar tri: Produce bands using triangle wave (marble, wood textures). Also see L{Noise}. + @type tri: int + @ivar turbulence: Turbulence (for magic, wood, stucci, marble textures). + Value is clamped to the range [0.0,200.0]. + @type turbulence: float + @ivar type: Texture's 'Type' mode. See L{Types}. + Value must be in the range [0,13]. + @type type: int + @ivar useAlpha: Use of image's alpha channel enabled. Also see L{ImageFlags}. + @type useAlpha: int + @ivar users: Number of texture users. Read-only. + @type users: int + @ivar weight1: Weight 1 (for Voronoi textures). + Value is clamped to the range [-2.0,2.0]. + @type weight1: float + @ivar weight2: Weight 2 (for Voronoi textures). + Value is clamped to the range [-2.0,2.0]. + @type weight2: float + @ivar weight3: Weight 3 (for Voronoi textures). + Value is clamped to the range [-2.0,2.0]. + @type weight3: float + @ivar weight4: Weight 4 (for Voronoi textures). + Value is clamped to the range [-2.0,2.0]. + @type weight4: float """ def getExtend(): """ - Get the extend mode of the texture. See L{setExtend} + Get the extend mode of the texture. See L{setExtend}. @rtype: string. """ @@ -218,9 +369,8 @@ class Texture: def getType(): """ - Get this Texture's type. + Get this Texture's type. See L{setType}. @rtype: string - @return: The Texture's type. See L{setType} """ def setExtend(extendmode): @@ -231,12 +381,12 @@ class Texture: @type extendmode: string """ - def setFlags(f=None, f2=None, f3=None): + def setFlags(f1=None, f2=None, f3=None, f4=None): """ Set this object's flags. - @param f: Flags to be set (omitted flags are cleared). Can be any of - 'ColorBand', 'FlipBlendXY', and 'NegAlpha' - @type f: string + @param f1,f2,f3,f4: Flags to be set (omitted flags are cleared). Can be any of + 'FlipBlendXY', 'NegAlpha', 'CheckerOdd', and 'CheckerEven' + @type f1,f2,f3,f4: string """ def setImage(image): @@ -247,14 +397,14 @@ class Texture: @warning: This sets the texture's type to 'Image' if it is not already. """ - def setImageFlags(f=None, f2=None, f3=None, and_so_on=None): + def setImageFlags(f1=None, f2=None, f3=None, etc=None): """ Set the Image flags (only makes sense for IMAGE textures). Omitted flags are cleared. - @param f: Flag to set. See L{ImageFlags} for their meanings. Can be + @param f1, f2, f3, etc: Flag to set. See L{ImageFlags} for their meanings. Can be any of: 'InterPol', 'UseAlpha', 'MipMap', 'Fields', 'Rot90', - 'CalcAlpha', 'StField', 'Movie' and 'Cyclic' - @type f: string + 'CalcAlpha', 'Cyclic', 'Movie', 'StField', 'Anti' and 'NormalMap' + @type f1, f2, f3, etc: string """ def setName(name): @@ -267,24 +417,22 @@ class Texture: def setSType(stype): """ Set the SType. - @param stype: The new stype. This can be one of the following values - or 'Default' which sets the stype to the default value. See - L{STypes} for their meanings. - 'CloudDefault', 'CloudColor', 'WoodBands', 'WoodRings', - 'WoodBandNoise', 'WoodRingNoise', 'MarbleSoft', 'MarbleSharp', - 'MarbleSharper', 'BlendLin', 'BlendQuad', 'BlendEase', - 'BlendDiag', 'BlendSphere', 'BlendHalo', 'StucciPlastic', - 'StucciWallIn', 'StucciWallOut', 'EnvmapStatic', 'EnvmapAnim', - 'EnvmapLoad' + @param stype: The new stype. This can be any of the values listed in + L{STypes} or 'Default' which sets the stype to the default value. @type stype: string + + @note: the set of valid parameters is dependent on the current + texture type. Be sure to always set the texture type B{before} + setting the texture's stype; otherwise an exception might occur. """ - + def setType(type): """ Set this Texture's type. @param type: The new type. Possible options are: 'None', 'Clouds', 'Wood', 'Marble', 'Magic', 'Blend', 'Stucci', - 'Noise', 'Image', 'Plugin' and 'EnvMap' + 'Noise', 'Image', 'Plugin', 'EnvMap', 'Musgrave', 'Voronoi' + and 'DistNoise' @type type: string """ diff --git a/source/blender/python/api2_2x/gen_utils.c b/source/blender/python/api2_2x/gen_utils.c index 3cc4cff1176..e76943573a0 100644 --- a/source/blender/python/api2_2x/gen_utils.c +++ b/source/blender/python/api2_2x/gen_utils.c @@ -39,6 +39,8 @@ #include "BKE_global.h" #include "BKE_main.h" +#include "constant.h" + //---------------------- EXPP_GetModuleConstant ------------------------- //Helper function for returning a module constant PyObject *EXPP_GetModuleConstant(char *module, char *constant) @@ -597,69 +599,59 @@ PyObject *EXPP_addScriptLink(ScriptLink *slink, PyObject *args, int is_scene) * value: PyObject containing the new value * param: pointer to destination variable * max, min: range of values for clamping + * type: kind of pointer and data (uses the same characters as + * PyArgs_ParseTuple() and Py_BuildValue() * * Return 0 on success, -1 on error. */ -int EXPP_setCharClamped ( PyObject *value, char *param, - short min, short max ) +int EXPP_setFloatClamped( PyObject *value, float *param, + float min, float max ) { - /* if value not of correct type, raise Type exception */ - - if( !PyInt_CheckExact( value ) ) { + if( !PyNumber_Check ( value ) ) { char errstr[128]; - sprintf ( errstr, "expected char argument in [%d,%d]", min, max ); + sprintf ( errstr, "expected float argument in [%f,%f]", min, max ); return EXPP_ReturnIntError( PyExc_TypeError, errstr ); } - /* clamp and store value */ + *param = EXPP_ClampFloat( PyFloat_AsDouble( value ), min, max ); - *param = EXPP_ClampInt( PyInt_AS_LONG ( value ), min, max ); return 0; } -int EXPP_setShortClamped ( PyObject *value, short *param, - short min, short max ) +int EXPP_setIValueClamped( PyObject *value, void *param, + int min, int max, char type ) { - if( !PyInt_CheckExact ( value ) ) { - char errstr[128]; - sprintf ( errstr, "expected int argument in [%d,%d]", min, max ); - return EXPP_ReturnIntError( PyExc_TypeError, errstr ); - } - - *param = EXPP_ClampInt( PyInt_AS_LONG ( value ), min, max ); + char errstr[128]; + int number; - return 0; -} + sprintf ( errstr, "expected int argument in [%d,%d]", min, max ); -int EXPP_setIntClamped ( PyObject *value, int *param, - int min, int max ) -{ - if( !PyInt_CheckExact ( value ) ) { - char errstr[128]; - sprintf ( errstr, "expected int argument in [%d,%d]", min, max ); + if( !PyInt_CheckExact ( value ) ) return EXPP_ReturnIntError( PyExc_TypeError, errstr ); - } - *param = EXPP_ClampInt( PyInt_AS_LONG ( value ), min, max ); + number = PyInt_AS_LONG( value ); - return 0; -} - -int EXPP_setFloatClamped ( PyObject *value, float *param, - float min, float max ) -{ - if( !PyFloat_CheckExact ( value ) ) { - char errstr[128]; - sprintf ( errstr, "expected float argument in [%f,%f]", min, max ); - return EXPP_ReturnIntError( PyExc_TypeError, errstr ); + switch ( type ) { + case 'b': + *(char *)param = EXPP_ClampInt( number, min, max ); + return 0; + case 'h': + *(short *)param = EXPP_ClampInt( number, min, max ); + return 0; + case 'H': + *(unsigned short *)param = EXPP_ClampInt( number, min, max ); + return 0; + case 'i': + *(int *)param = EXPP_ClampInt( number, min, max ); + return 0; + default: + return EXPP_ReturnIntError( PyExc_RuntimeError, + "EXPP_setIValueClamped(): invalid type code" ); } - - *param = EXPP_ClampFloat( PyFloat_AS_DOUBLE( value ), min, max ); - - return 0; } + /* * Utility routines to range-check and store various datatypes. The object * type is checked and a exception is raised if it's not the correct type. @@ -670,90 +662,215 @@ int EXPP_setFloatClamped ( PyObject *value, float *param, * value: PyObject containing the new value * param: pointer to destination variable * max, min: valid range for value + * type: kind of pointer and data (uses the same characters as + * PyArgs_ParseTuple() and Py_BuildValue() * * Return 0 on success, -1 on error. */ -int EXPP_setCharRange ( PyObject *value, char *param, - short min, short max ) +int EXPP_setFloatRange( PyObject *value, float *param, + float min, float max ) { char errstr[128]; short number; - /* build exception error string */ - - sprintf ( errstr, "expected int argument in [%d,%d]", min, max ); - - /* if value not of correct type, raise Type exception */ + sprintf ( errstr, "expected int argument in [%f,%f]", min, max ); - if( !PyInt_CheckExact ( value ) ) + if( !PyNumber_Check ( value ) ) return EXPP_ReturnIntError( PyExc_TypeError, errstr ); - /* if value out of range, raise Value exception */ - - number = PyInt_AS_LONG ( value ); + number = PyFloat_AsDouble( value ); if ( number < min || number > max ) return EXPP_ReturnIntError( PyExc_ValueError, errstr ); - /* store value */ - *param = number; return 0; } -int EXPP_setShortRange ( PyObject *value, short *param, - short min, short max ) +int EXPP_setIValueRange( PyObject *value, void *param, + int min, int max, char type ) { char errstr[128]; - short number; + int number; sprintf ( errstr, "expected int argument in [%d,%d]", min, max ); if( !PyInt_CheckExact ( value ) ) return EXPP_ReturnIntError( PyExc_TypeError, errstr ); - number = PyInt_AS_LONG ( value ); - if ( number < min || number > max ) + number = PyInt_AS_LONG( value ); + if( number < min || number > max ) return EXPP_ReturnIntError( PyExc_ValueError, errstr ); - *param = number; - return 0; + switch ( type ) { + case 'b': + *(char *)param = number; + return 0; + case 'h': + *(short *)param = number; + return 0; + case 'H': + *(unsigned short *)param = number; + return 0; + case 'i': + *(int *)param = number; + return 0; + default: + return EXPP_ReturnIntError( PyExc_RuntimeError, + "EXPP_setIValueRange(): invalid type code" ); + } } -int EXPP_setIntRange ( PyObject *value, int *param, - int min, int max ) +/* + * Utility routines to handle all attribute setters which use module + * constants. Generic pointer to destination variable is used, and typecast + * to the appropriate type based on the "type" specifier. + * + * Inputs: + * constant: constant_Type value + * param: pointer to destination variable + * type: kind of pointer and data + * + * Return 0 on success, -1 on error. + */ + +int EXPP_setModuleConstant ( BPy_constant *constant, void *param, char type ) { - char errstr[128]; - int number; + PyObject *item; - sprintf ( errstr, "expected int argument in [%d,%d]", min, max ); + if( constant->ob_type != &constant_Type ) + return EXPP_ReturnIntError( PyExc_TypeError, + "expected module constant" ); + + item = PyDict_GetItemString( constant->dict, "value" ); + if( !item ) + return EXPP_ReturnIntError( PyExc_RuntimeError, + "module constant has no \"value\" key" ); + + switch ( type ) { + case 'h': + *(short *)param = PyInt_AS_LONG( item ); + return 0; + case 'i': + *(int *)param = PyInt_AS_LONG( item ); + return 0; + case 'f': + *(float *)param = PyFloat_AS_DOUBLE( item ); + return 0; + default: + return EXPP_ReturnIntError( PyExc_RuntimeError, + "EXPP_setModuleConstant(): invalid type code" ); + } +} + +/* + * Utility routines to get/set bits in bitfields. Adapted from code in + * sceneRender.c (thanks, ascotan!). + * + * Inputs: + * param: pointer to source/destination variable + * setting: the bit to get/set + * type: pointer type ('h' == short, 'i' == integer) + */ + +PyObject *EXPP_getBitfield( void *param, int setting, char type ) +{ + switch ( type ) { + case 'b': + return (*(char *)param & setting) + ? EXPP_incr_ret_True() : EXPP_incr_ret_False(); + case 'h': + return (*(short *)param & setting) + ? EXPP_incr_ret_True() : EXPP_incr_ret_False(); + case 'i': + return (*(int *)param & setting) + ? EXPP_incr_ret_True() : EXPP_incr_ret_False(); + default: + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "EXPP_getBit(): invalid type code" ); + } +} + +int EXPP_setBitfield( PyObject * value, void *param, int setting, char type ) +{ + int flag; + char errstr[] = "expected TRUE or FALSE (1 or 0)"; if( !PyInt_CheckExact ( value ) ) return EXPP_ReturnIntError( PyExc_TypeError, errstr ); - number = PyInt_AS_LONG ( value ); - if ( number < min || number > max ) + flag = PyInt_AS_LONG ( value ); + if( flag != 0 && flag != 1 ) return EXPP_ReturnIntError( PyExc_ValueError, errstr ); - *param = number; - return 0; + switch ( type ) { + case 'b': + if ( flag ) + *(char *)param |= setting; + else + *(char *)param &= ~setting; + return 0; + case 'h': + if ( flag ) + *(short *)param |= setting; + else + *(short *)param &= ~setting; + return 0; + case 'i': + if ( flag ) + *(int *)param |= setting; + else + *(int *)param &= ~setting; + return 0; + default: + return EXPP_ReturnIntError( PyExc_RuntimeError, + "EXPP_setBit(): invalid type code" ); + } } -int EXPP_setFloatRange ( PyObject *value, float *param, - float min, float max ) +/* + * Procedure to handle older setStuff() methods. Assumes that argument + * is a tuple with one object, and so grabs the object and passes it to + * the specified tp_getset setter for the corresponding attribute. + */ + +PyObject *EXPP_setterWrapper ( PyObject * self, PyObject * args, + setter func) { - char errstr[128]; - short number; + int error; - sprintf ( errstr, "expected int argument in [%f,%f]", min, max ); + if ( !PyTuple_Check( args ) || PyTuple_Size( args ) != 1 ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "expected tuple of one item" ); - if( !PyFloat_CheckExact ( value ) ) - return EXPP_ReturnIntError( PyExc_TypeError, errstr ); + error = func ( self, PySequence_Fast_GET_ITEM( args, 0 ), NULL ); + if ( !error ) { + Py_INCREF( Py_None ); + return Py_None; + } else + return NULL; +} - number = PyFloat_AS_DOUBLE( value ); - if ( number < min || number > max ) - return EXPP_ReturnIntError( PyExc_ValueError, errstr ); +/* + * Procedure to handle older setStuff() methods. Assumes that argument + * is a tuple, so just passes it to the specified tp_getset setter for + * the corresponding attribute. + */ - *param = number; - return 0; +PyObject *EXPP_setterWrapperTuple ( PyObject * self, PyObject * args, + setter func) +{ + int error; + + if ( !PyTuple_Check( args ) ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "expected tuple" ); + + error = func ( self, args, NULL ); + if ( !error ) { + Py_INCREF( Py_None ); + return Py_None; + } else + return NULL; } + diff --git a/source/blender/python/api2_2x/gen_utils.h b/source/blender/python/api2_2x/gen_utils.h index 32c5e314ecf..c69790075d1 100644 --- a/source/blender/python/api2_2x/gen_utils.h +++ b/source/blender/python/api2_2x/gen_utils.h @@ -38,6 +38,8 @@ #include "DNA_scriptlink_types.h" #include "DNA_listBase.h" +#include "constant.h" + #define Py_PI 3.14159265358979323846 #define Py_WRAP 1024 #define Py_NEW 2048 @@ -99,24 +101,36 @@ int EXPP_map_getStrVal( const EXPP_map_pair * map, /* clamping and range-checking utilities */ -int EXPP_setCharClamped ( PyObject *value, char *param, - short min, short max); -int EXPP_setShortClamped ( PyObject *value, short *param, - short min, short max); -int EXPP_setIntClamped ( PyObject *value, int *param, - int min, int max); +int EXPP_setIValueClamped( PyObject *value, void *param, + int min, int max, char type ); int EXPP_setFloatClamped ( PyObject *value, float *param, float min, float max); - -int EXPP_setChrRange ( PyObject *value, char *param, - short min, short max); -int EXPP_setShortRange ( PyObject *value, short *param, - short min, short max); -int EXPP_setIntRange ( PyObject *value, int *param, - int min, int max); +int EXPP_setIValueRange( PyObject *value, void *param, + int min, int max, char type ); int EXPP_setFloatRange ( PyObject *value, float *param, float min, float max); +/* utility routine for PyType attributes setters with module constant */ + +int EXPP_setModuleConstant ( BPy_constant *constant, void *param, + char type ); + +/* utilities to get/set bits in bitfields */ + +PyObject *EXPP_getBitfield( void *param, int setting, char type ); +int EXPP_setBitfield( PyObject * value, void *param, int setting, char type ); + +/* + * Procedures to handle older setStuff() methods, which now access + * a PyType's setter attributes using the tp_getset mechanism. + */ + +PyObject *EXPP_setterWrapper ( PyObject * self, PyObject * args, + setter func); + +PyObject *EXPP_setterWrapperTuple ( PyObject * self, PyObject * args, + setter func); + /* scriplinks-related: */ PyObject *EXPP_getScriptLinks(ScriptLink *slink, PyObject *args, int is_scene); PyObject *EXPP_addScriptLink(ScriptLink *slink, PyObject *args, int is_scene); diff --git a/source/blender/python/api2_2x/rgbTuple.c b/source/blender/python/api2_2x/rgbTuple.c index ad9eb485667..f7ad9dc10af 100644 --- a/source/blender/python/api2_2x/rgbTuple.c +++ b/source/blender/python/api2_2x/rgbTuple.c @@ -45,7 +45,7 @@ static PyObject *rgbTuple_getAttr( BPy_rgbTuple * self, char *name ); static int rgbTuple_setAttr( BPy_rgbTuple * self, char *name, PyObject * v ); static PyObject *rgbTuple_repr( BPy_rgbTuple * self ); -static int rgbTupleLength( BPy_rgbTuple * self ); +static int rgbTupleLength( void ); static PyObject *rgbTupleSubscript( BPy_rgbTuple * self, PyObject * key ); static int rgbTupleAssSubscript( BPy_rgbTuple * self, PyObject * who, @@ -138,39 +138,47 @@ PyObject *rgbTuple_New( float *rgb[3] ) /*****************************************************************************/ PyObject *rgbTuple_getCol( BPy_rgbTuple * self ) { - PyObject *list = PyList_New( 3 ); - - if( !list ) + PyObject *attr = Py_BuildValue( "[fff]", *(self->rgb[0]), + *(self->rgb[1]), *(self->rgb[2])); + if( !attr ) return EXPP_ReturnPyObjError( PyExc_MemoryError, - "couldn't create PyList" ); - - PyList_SET_ITEM( list, 0, Py_BuildValue( "f", *( self->rgb[0] ) ) ); - PyList_SET_ITEM( list, 1, Py_BuildValue( "f", *( self->rgb[1] ) ) ); - PyList_SET_ITEM( list, 2, Py_BuildValue( "f", *( self->rgb[2] ) ) ); - - return list; + "Py_BuildValue() failed" ); + return attr; } -PyObject *rgbTuple_setCol( BPy_rgbTuple * self, PyObject * args ) +int rgbTuple_setCol( BPy_rgbTuple * self, PyObject * args ) { - int ok; + int ok = 0; float r = 0, g = 0, b = 0; - if( PyObject_Length( args ) == 3 ) - ok = PyArg_ParseTuple( args, "fff", &r, &g, &b ); - - else + /* + * since rgbTuple_getCol() returns a list, be sure we accept a list + * as valid input + */ + + if( PyObject_Length( args ) == 3 ) { + if ( PyList_Check ( args ) && + PyNumber_Check( PySequence_Fast_GET_ITEM( args, 0 ) ) && + PyNumber_Check( PySequence_Fast_GET_ITEM( args, 1 ) ) && + PyNumber_Check( PySequence_Fast_GET_ITEM( args, 2 ) ) ) { + r = PyFloat_AsDouble( PySequence_Fast_GET_ITEM( args, 0 ) ); + g = PyFloat_AsDouble( PySequence_Fast_GET_ITEM( args, 1 ) ); + b = PyFloat_AsDouble( PySequence_Fast_GET_ITEM( args, 2 ) ); + ok = 1; + } else + ok = PyArg_ParseTuple( args, "fff", &r, &g, &b ); + } else ok = PyArg_ParseTuple( args, "|(fff)", &r, &g, &b ); if( !ok ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected [f,f,f] or f,f,f as arguments (or nothing)" ); + return EXPP_ReturnIntError( PyExc_TypeError, + "expected [f,f,f], (f,f,f) or f,f,f as arguments (or nothing)" ); *( self->rgb[0] ) = EXPP_ClampFloat( r, 0.0, 1.0 ); *( self->rgb[1] ) = EXPP_ClampFloat( g, 0.0, 1.0 ); *( self->rgb[2] ) = EXPP_ClampFloat( b, 0.0, 1.0 ); - return EXPP_incr_ret( Py_None ); + return 0; } /*****************************************************************************/ @@ -245,7 +253,7 @@ static int rgbTuple_setAttr( BPy_rgbTuple * self, char *name, PyObject * v ) /* These functions provide code to access rgbTuple objects as */ /* mappings. */ /*****************************************************************************/ -static int rgbTupleLength( BPy_rgbTuple * self ) +static int rgbTupleLength( void ) { return 3; } diff --git a/source/blender/python/api2_2x/rgbTuple.h b/source/blender/python/api2_2x/rgbTuple.h index 4e113d7dd49..a1af0e27549 100644 --- a/source/blender/python/api2_2x/rgbTuple.h +++ b/source/blender/python/api2_2x/rgbTuple.h @@ -51,6 +51,6 @@ typedef struct { /*****************************************************************************/ PyObject *rgbTuple_New( float *rgb[3] ); PyObject *rgbTuple_getCol( BPy_rgbTuple * self ); -PyObject *rgbTuple_setCol( BPy_rgbTuple * self, PyObject * args ); +int rgbTuple_setCol( BPy_rgbTuple * self, PyObject * args ); #endif /* EXPP_rgbTuple_H */ |