Index: source/blender/python/api2_2x/Lamp.c =================================================================== --- source/blender/python/api2_2x/Lamp.c (revision 16014) +++ source/blender/python/api2_2x/Lamp.c (working copy) @@ -34,15 +34,20 @@ #include "BKE_global.h" #include "BKE_object.h" #include "BKE_library.h" +#include "BKE_texture.h" #include "BLI_blenlib.h" #include "BIF_space.h" #include "BSE_editipo.h" #include "mydevice.h" #include "Ipo.h" +#include "MTex.h" +#include "Texture.h" #include "constant.h" #include "gen_utils.h" #include "gen_library.h" #include "BKE_utildefines.h" +#include "DNA_material_types.h" +#include "MEM_guardedalloc.h" /*****************************************************************************/ /* Python BPy_Lamp defaults: */ @@ -204,6 +209,7 @@ static PyObject *Lamp_getQuad1( BPy_Lamp * self ); static PyObject *Lamp_getQuad2( BPy_Lamp * self ); static PyObject *Lamp_getCol( BPy_Lamp * self ); +static PyObject *Lamp_getTextures( BPy_Lamp * self ); static PyObject *Lamp_getIpo( BPy_Lamp * self ); static PyObject *Lamp_getComponent( BPy_Lamp * self, void * closure ); static PyObject *Lamp_clearIpo( BPy_Lamp * self ); @@ -253,6 +259,8 @@ static int Lamp_setQuad1( BPy_Lamp * self, PyObject * args ); static int Lamp_setQuad2( BPy_Lamp * self, PyObject * args ); static int Lamp_setCol( BPy_Lamp * self, PyObject * args ); +static PyObject *Lamp_setTexture( BPy_Lamp * self, PyObject * args ); +static PyObject *Lamp_clearTexture( BPy_Lamp * self, PyObject * args ); static PyObject *Lamp_getScriptLinks( BPy_Lamp * self, PyObject * value ); static PyObject *Lamp_addScriptLink( BPy_Lamp * self, PyObject * args ); static PyObject *Lamp_clearScriptLinks( BPy_Lamp * self, PyObject * args ); @@ -308,6 +316,8 @@ "() - return light intensity value #2 for a Quad Lamp"}, {"getCol", ( PyCFunction ) Lamp_getCol, METH_NOARGS, "() - return light rgb color triplet"}, + {"getTextures", ( PyCFunction ) Lamp_getTextures, METH_NOARGS, + "() - Return Lamp's texture list as a tuple"}, {"setName", ( PyCFunction ) GenericLib_setName_with_method, METH_VARARGS, "(str) - rename Lamp"}, {"setType", ( PyCFunction ) Lamp_oldsetType, METH_O, @@ -352,6 +362,10 @@ "(float) - change light intensity value #2 for a Quad Lamp"}, {"setCol", ( PyCFunction ) Lamp_oldsetCol, METH_VARARGS, "(f,f,f) or ([f,f,f]) - change light's rgb color triplet"}, + {"setTexture", ( PyCFunction ) Lamp_setTexture, METH_VARARGS, + "(n,tex,texco=0,mapto=0) - Set numbered texture to tex"}, + {"clearTexture", ( PyCFunction ) Lamp_clearTexture, METH_O, + "(n) - Remove texture from numbered slot"}, {"getScriptLinks", ( PyCFunction ) Lamp_getScriptLinks, METH_O, "(eventname) - Get a list of this lamp's scriptlinks (Text names) " "of the given type\n" @@ -1618,3 +1632,84 @@ return error; } + +static PyObject *Lamp_getTextures( BPy_Lamp * self ) +{ + int i; + struct MTex *mtex; + PyObject *t[MAX_MTEX]; + PyObject *tuple; + + /* build a texture list */ + for( i = 0; i < MAX_MTEX; ++i ) { + mtex = self->lamp->mtex[i]; + + if( mtex ) { + t[i] = MTex_CreatePyObject( mtex ); + } else { + Py_INCREF( Py_None ); + t[i] = Py_None; + } + } + + /* turn the array into a tuple */ + tuple = Py_BuildValue( "NNNNNNNNNNNNNNNNNN", t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], t[9], t[10], t[11], t[12], t[13], t[14], t[15], t[16], t[17] ); + if( !tuple ) + return EXPP_ReturnPyObjError( PyExc_MemoryError, + "Lamp_getTextures: couldn't create PyTuple" ); + + return tuple; +} + +static PyObject *Lamp_setTexture( BPy_Lamp * self, PyObject * args ) +{ + int texnum; + PyObject *pytex; + Tex *bltex; + int texco = TEXCO_ORCO, mapto = MAP_COL; + + if( !PyArg_ParseTuple( args, "iO!|ii", &texnum, &Texture_Type, &pytex, + &texco, &mapto ) ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected int in [0,9] and Texture" ); + if( ( texnum < 0 ) || ( texnum >= MAX_MTEX ) ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected int in [0,9] and Texture" ); + + bltex = Texture_FromPyObject( pytex ); + + if( !self->lamp->mtex[texnum] ) { + /* there isn't an mtex for this slot so we need to make one */ + self->lamp->mtex[texnum] = add_mtex( ); + } else { + /* we already had a texture here so deal with the old one first */ + self->lamp->mtex[texnum]->tex->id.us--; + } + + self->lamp->mtex[texnum]->tex = bltex; + id_us_plus( &bltex->id ); + self->lamp->mtex[texnum]->texco = (short)texco; + self->lamp->mtex[texnum]->mapto = (short)mapto; + + Py_RETURN_NONE; +} + +static PyObject *Lamp_clearTexture( BPy_Lamp * self, PyObject * value ) +{ + int texnum = (int)PyInt_AsLong(value); + struct MTex *mtex; + /* non ints will be -1 */ + if( ( texnum < 0 ) || ( texnum >= MAX_MTEX ) ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected int in [0,9]" ); + + mtex = self->lamp->mtex[texnum]; + if( mtex ) { + if( mtex->tex ) + mtex->tex->id.us--; + MEM_freeN( mtex ); + self->lamp->mtex[texnum] = NULL; + } + + Py_RETURN_NONE; +} Index: source/blender/python/api2_2x/Lamp.h =================================================================== --- source/blender/python/api2_2x/Lamp.h (revision 16014) +++ source/blender/python/api2_2x/Lamp.h (working copy) @@ -32,6 +32,7 @@ #include #include "DNA_lamp_types.h" +#include "DNA_texture_types.h" #include "rgbTuple.h" extern PyTypeObject Lamp_Type;