diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-03-08 09:35:01 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-03-08 09:35:01 +0300 |
commit | 8e0704f59a40d9dd89b0c9cf92ec3484a106fa78 (patch) | |
tree | 0ef91cc93c518ed3ec286279a5bff53e21055f04 /source | |
parent | 4bd5ab628bbbdb23b1aeb074bc66f1133cb3af29 (diff) |
Added python access to material and texture colorbands.
mat.colorbandDiffuse
mat.colorbandSpecular
tex.colorband
gen_utils - removed unused func
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/api2_2x/Material.c | 142 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Material.h | 5 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Texture.c | 25 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Material.py | 19 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Texture.py | 4 | ||||
-rw-r--r-- | source/blender/python/api2_2x/gen_utils.c | 18 | ||||
-rw-r--r-- | source/blender/python/api2_2x/gen_utils.h | 1 |
7 files changed, 193 insertions, 21 deletions
diff --git a/source/blender/python/api2_2x/Material.c b/source/blender/python/api2_2x/Material.c index 0806c131a57..ee496c14737 100644 --- a/source/blender/python/api2_2x/Material.c +++ b/source/blender/python/api2_2x/Material.c @@ -42,6 +42,7 @@ #include "BKE_material.h" #include "BKE_texture.h" #include "BKE_idprop.h" +#include "BKE_utildefines.h" /* for CLAMP */ #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" #include "BSE_editipo.h" @@ -520,6 +521,7 @@ static PyObject *Material_getColorComponent( BPy_Material * self, void * closure ); static PyObject *Material_getOopsLoc( BPy_Material * self ); static PyObject *Material_getOopsSel( BPy_Material * self ); + /*static int Material_setSeptex( BPy_Material * self, PyObject * value ); static PyObject *Material_getSeptex( BPy_Material * self );*/ @@ -590,6 +592,8 @@ static PyObject *Material_addScriptLink(BPy_Material * self, PyObject * args ); static PyObject *Material_clearScriptLinks(BPy_Material *self, PyObject *args); static PyObject *Material_insertIpoKey( BPy_Material * self, PyObject * args ); +static PyObject *Material_getColorband( BPy_Material * self, void * type); +int Material_setColorband( BPy_Material * self, PyObject * value, void * type); static PyObject *Material_copy( BPy_Material * self ); @@ -1062,6 +1066,14 @@ static PyGetSetDef BPy_Material_getseters[] = { (getter)Material_getColorComponent, (setter)Material_setColorComponent, "Diffuse color blue component", (void *) EXPP_MAT_COMP_B }, + {"colorbandDiffuse", + (getter)Material_getColorband, (setter)Material_setColorband, + "Set the light group for this material", + (void *) 0}, + {"colorbandSpecular", + (getter)Material_getColorband, (setter)Material_setColorband, + "Set the light group for this material", + (void *) 1}, {NULL,NULL,NULL,NULL,NULL} /* Sentinel */ }; @@ -2467,6 +2479,110 @@ static PyObject *Material_repr( BPy_Material * self ) } /*****************************************************************************/ +/* These functions are used here and in in Texture.c */ +/*****************************************************************************/ +PyObject *EXPP_PyList_fromColorband( ColorBand *coba ) +{ + short i; + PyObject *cbls; + PyObject *colls; + + if (!coba) + return PyList_New( 0 ); + + cbls = PyList_New( coba->tot ); + + for (i=0; i < coba->tot; i++) { + colls = PyList_New( 5 ); + PyList_SET_ITEM( colls, 0, PyFloat_FromDouble(coba->data[i].r) ); + PyList_SET_ITEM( colls, 1, PyFloat_FromDouble(coba->data[i].g) ); + PyList_SET_ITEM( colls, 2, PyFloat_FromDouble(coba->data[i].b) ); + PyList_SET_ITEM( colls, 3, PyFloat_FromDouble(coba->data[i].a) ); + PyList_SET_ITEM( colls, 4, PyFloat_FromDouble(coba->data[i].pos) ); + PyList_SET_ITEM(cbls, i, colls); + } + return cbls; +} + +/* make sure you coba is not none before calling this */ +int EXPP_Colorband_fromPyList( ColorBand *coba, PyObject * value ) +{ + short totcol, i; + PyObject *colseq; + PyObject *pyflt; + float f; + + if ( !PySequence_Check( value ) ) + return ( EXPP_ReturnIntError( PyExc_TypeError, + "Colorband must be a sequence" ) ); + + totcol = PySequence_Size(value); + if (totcol < 1 || totcol > 31) + return ( EXPP_ReturnIntError( PyExc_ValueError, + "Colorband must be between 1 and 31 in length" ) ); + + for (i=0; i<totcol; i++) { + colseq = PySequence_GetItem( value, i ); + if ( !PySequence_Check( colseq ) || PySequence_Size( colseq ) != 5) { + Py_DECREF ( colseq ); + return ( EXPP_ReturnIntError( PyExc_ValueError, + "Colorband colors must be sequences of 5 floats" ) ); + } + for (i=0; i<5; i++) { + pyflt = PySequence_GetItem( colseq, i ); + if (!PyNumber_Check(pyflt)) { + return ( EXPP_ReturnIntError( PyExc_ValueError, + "Colorband colors must be sequences of 5 floats" ) ); + Py_DECREF ( pyflt ); + Py_DECREF ( colseq ); + } + Py_DECREF ( pyflt ); + } + Py_DECREF ( colseq ); + } + + /* ok, continue - should check for 5 floats, will ignore non floats for now */ + coba->tot = totcol; + for (i=0; i<totcol; i++) { + colseq = PySequence_GetItem( value, i ); + + pyflt = PySequence_GetItem( colseq, 0 ); + f = (float)PyFloat_AsDouble( pyflt ); + CLAMP(f, 0.0, 1.0); + coba->data[i].r = f; + Py_DECREF ( pyflt ); + + pyflt = PySequence_GetItem( colseq, 1 ); + f = (float)PyFloat_AsDouble( pyflt ); + CLAMP(f, 0.0, 1.0); + coba->data[i].g = f; + Py_DECREF ( pyflt ); + + pyflt = PySequence_GetItem( colseq, 2 ); + f = (float)PyFloat_AsDouble( pyflt ); + CLAMP(f, 0.0, 1.0); + coba->data[i].b = f; + Py_DECREF ( pyflt ); + + pyflt = PySequence_GetItem( colseq, 3 ); + f = (float)PyFloat_AsDouble( pyflt ); + CLAMP(f, 0.0, 1.0); + coba->data[i].a = f; + Py_DECREF ( pyflt ); + + pyflt = PySequence_GetItem( colseq, 4 ); + f = (float)PyFloat_AsDouble( pyflt ); + CLAMP(f, 0.0, 1.0); + coba->data[i].pos = f; + Py_DECREF ( pyflt ); + + Py_DECREF ( colseq ); + } + return 0; +} + + +/*****************************************************************************/ /* These functions are used in NMesh.c and Object.c */ /*****************************************************************************/ PyObject *EXPP_PyList_fromMaterialList( Material ** matlist, int len, int all ) @@ -2683,6 +2799,32 @@ static PyObject *Material_getOopsLoc ( BPy_Material * self ) Py_RETURN_NONE; } +static PyObject *Material_getColorband( BPy_Material * self, void * type) +{ + switch( (long)type ) { + case 0: /* these are backwards, but that how it works */ + return EXPP_PyList_fromColorband( self->material->ramp_col ); + case 1: + return EXPP_PyList_fromColorband( self->material->ramp_spec ); + } + Py_RETURN_NONE; +} + +int Material_setColorband( BPy_Material * self, PyObject * value, void * type) +{ + switch( (long)type ) { + case 0: /* these are backwards, but that how it works */ + if (!self->material->ramp_col) + self->material->ramp_col = MEM_callocN( sizeof(ColorBand), "colorband"); + return EXPP_Colorband_fromPyList( self->material->ramp_col, value ); + case 1: + if (!self->material->ramp_spec) + self->material->ramp_spec = MEM_callocN( sizeof(ColorBand), "colorband"); + return EXPP_Colorband_fromPyList( self->material->ramp_spec, value ); + } + return 0; +} + static PyObject *Material_getOopsSel ( BPy_Material * self ) { if( G.soops ) { diff --git a/source/blender/python/api2_2x/Material.h b/source/blender/python/api2_2x/Material.h index 382bff552c7..0b8f48b713b 100644 --- a/source/blender/python/api2_2x/Material.h +++ b/source/blender/python/api2_2x/Material.h @@ -36,6 +36,7 @@ #include <Python.h> #include "DNA_object_types.h" #include "DNA_material_types.h" +#include "DNA_texture_types.h" /* colorband */ #include "rgbTuple.h" /*****************************************************************************/ @@ -63,6 +64,10 @@ PyObject *Material_CreatePyObject( Material * mat ); Material *Material_FromPyObject( PyObject * pyobj ); int Material_CheckPyObject( PyObject * pyobj ); +/* colorband tp_getseters */ +PyObject *EXPP_PyList_fromColorband( ColorBand *coba ); +int EXPP_Colorband_fromPyList( ColorBand *coba, PyObject * value ); + /* Some functions needed by NMesh, Curve and friends */ PyObject *EXPP_PyList_fromMaterialList( Material ** matlist, int len, int all ); diff --git a/source/blender/python/api2_2x/Texture.c b/source/blender/python/api2_2x/Texture.c index c9cf3e406cf..67120b5f6c6 100644 --- a/source/blender/python/api2_2x/Texture.c +++ b/source/blender/python/api2_2x/Texture.c @@ -54,6 +54,7 @@ #include "gen_utils.h" #include "vector.h" /* for Texture_evaluate(vec) */ +#include "Material.h" /* for EXPP_Colorband_fromPyList and EXPP_PyList_fromColorband */ #include "RE_shader_ext.h" /*****************************************************************************/ @@ -201,9 +202,7 @@ static const EXPP_map_pair tex_type_map[] = { static const EXPP_map_pair tex_flag_map[] = { /* NOTE "CheckerOdd" and "CheckerEven" are new */ -#if 0 {"ColorBand", TEX_COLORBAND }, -#endif {"FlipBlend", TEX_FLIPBLEND}, {"NegAlpha", TEX_NEGALPHA}, {"CheckerOdd",TEX_CHECKER_ODD}, @@ -491,8 +490,11 @@ static int Texture_setImageFlags( BPy_Texture *self, PyObject *args, static int Texture_setNoiseBasis2( BPy_Texture *self, PyObject *args, void *type ); +static PyObject *Texture_getColorband( BPy_Texture * self); +int Texture_setColorband( BPy_Texture * self, PyObject * value); static PyObject *Texture_evaluate( BPy_Texture *self, PyObject *args ); + /*****************************************************************************/ /* Python BPy_Texture methods table: */ /*****************************************************************************/ @@ -754,6 +756,10 @@ static PyGetSetDef BPy_Texture_getseters[] = { (getter)Texture_getImageFlags, (setter)Texture_setImageFlags, "Use of image RGB values for normal mapping enabled ('ImageFlags')", (void *)TEX_NORMALMAP}, + {"colorband", + (getter)Texture_getColorband, (setter)Texture_setColorband, + "Use of image RGB values for normal mapping enabled ('ImageFlags')", + (void *)TEX_NORMALMAP}, {NULL,NULL,NULL,NULL,NULL} /* Sentinel */ }; @@ -1517,9 +1523,7 @@ static int Texture_setFlags( BPy_Texture * self, PyObject * value ) { int param; int bitmask = TEX_FLIPBLEND -#if 0 | TEX_COLORBAND -#endif | TEX_NEGALPHA | TEX_CHECKER_ODD | TEX_CHECKER_EVEN; @@ -2651,6 +2655,18 @@ static PyObject *Texture_oldsetImageFlags( BPy_Texture * self, PyObject * args ) Py_RETURN_NONE; } +static PyObject *Texture_getColorband( BPy_Texture * self) +{ + return EXPP_PyList_fromColorband( self->texture->coba ); +} + +int Texture_setColorband( BPy_Texture * self, PyObject * value) +{ + if (!self->texture->coba) + self->texture->coba = MEM_callocN( sizeof(ColorBand), "colorband"); + return EXPP_Colorband_fromPyList( self->texture->coba, value ); +} + static PyObject *Texture_evaluate( BPy_Texture * self, PyObject * args ) { VectorObject *vec_in = NULL; @@ -2672,4 +2688,3 @@ static PyObject *Texture_evaluate( BPy_Texture * self, PyObject * args ) return newVectorObject(vec, 4, Py_NEW); } - diff --git a/source/blender/python/api2_2x/doc/Material.py b/source/blender/python/api2_2x/doc/Material.py index 5eb47271934..5fc09edde95 100644 --- a/source/blender/python/api2_2x/doc/Material.py +++ b/source/blender/python/api2_2x/doc/Material.py @@ -282,9 +282,24 @@ class Material: @type lightGroup: Group or None @ivar uvlayer: The uv layer name to use, when UV mapping is enabled. @type uvlayer: string + @ivar colorband: Material colorband, a list of colors, + each color a list of 5 floats [0 - 1], [r,g,b,a,pos]. + The colorband can have between 1 and 31 colors. + @type colorband: list + + @ivar colorbandDiffuse: Material colorband, a list of colors, + each color a list of 5 floats [0 - 1], [r,g,b,a,pos]. + The colorband can have between 1 and 31 colors. + @type colorbandDiffuse: list + @ivar colorbandSpecular: Material colorband, a list of colors, + each color a list of 5 floats [0 - 1], [r,g,b,a,pos]. + The colorband can have between 1 and 31 colors. + @type colorbandSpecular: list + @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. + 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. + """ def getName(): diff --git a/source/blender/python/api2_2x/doc/Texture.py b/source/blender/python/api2_2x/doc/Texture.py index d8fb3255b4a..01a0d5c8908 100644 --- a/source/blender/python/api2_2x/doc/Texture.py +++ b/source/blender/python/api2_2x/doc/Texture.py @@ -381,6 +381,10 @@ class Texture: @ivar weight4: Weight 4 (for Voronoi textures). Value is clamped to the range [-2.0,2.0]. @type weight4: float + @ivar colorband: Texture colorband, a list of colors, + each color a list of 5 floats [0 - 1], [r,g,b,a,pos]. + The colorband can have between 1 and 31 colors. + @type colorband: list """ def getExtend(): diff --git a/source/blender/python/api2_2x/gen_utils.c b/source/blender/python/api2_2x/gen_utils.c index e4da9b30a34..46fb1e40961 100644 --- a/source/blender/python/api2_2x/gen_utils.c +++ b/source/blender/python/api2_2x/gen_utils.c @@ -165,18 +165,6 @@ ID *GetIdFromList( ListBase * list, char *name ) } /*****************************************************************************/ -/* Description: This function sets the fake user status of the ID */ -/* returns an int error, so from getsetattrs */ -/*****************************************************************************/ -PyObject *EXPP_GetIdLib( ID * id ) -{ - if (id->lib) - return PyString_FromString(id->lib->name); - else - return EXPP_incr_ret( Py_None ); -} - -/*****************************************************************************/ /* Description: These functions set an internal string with the given type */ /* and error_msg arguments. */ /*****************************************************************************/ @@ -1024,7 +1012,11 @@ PyObject *GenericLib_getLib( void *self ) { ID *id = ((BPy_GenericLib *)self)->id; if (!id) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "data has been removed" ) ); - return EXPP_GetIdLib(id); + + if (id->lib) + return PyString_FromString(id->lib->name); + else + return EXPP_incr_ret( Py_None ); } PyObject *GenericLib_getUsers( void *self ) diff --git a/source/blender/python/api2_2x/gen_utils.h b/source/blender/python/api2_2x/gen_utils.h index 2ad7a9843d9..f34aa22b57b 100644 --- a/source/blender/python/api2_2x/gen_utils.h +++ b/source/blender/python/api2_2x/gen_utils.h @@ -69,7 +69,6 @@ PyObject *EXPP_GetModuleConstant(char *module, char *constant); int StringEqual( const char *string1, const char *string2 ); char *GetIdName( ID * id ); -PyObject *EXPP_GetIdLib( ID * id ); int SetIdFakeUser( ID * id, PyObject *value); ID *GetIdFromList( ListBase * list, char *name ); |