diff options
author | Willian Padovani Germano <wpgermano@gmail.com> | 2003-11-23 20:46:06 +0300 |
---|---|---|
committer | Willian Padovani Germano <wpgermano@gmail.com> | 2003-11-23 20:46:06 +0300 |
commit | 5e7f9dfa084d978bbcb96dad7ac2bae80789714e (patch) | |
tree | 65767c41ef26feb0a7724ad3b4f05daaa69e253e /source/blender/python/api2_2x/Material.c | |
parent | 511b098c81913a8ce437ebed6c7f211dd9563f1b (diff) |
BPython:
-- New module: Blender.Texture, by new developer Alex Mole.
Most of it is done: guess only Ipo, envmap, colorband and plugin were not implemented yet.
Diffstat (limited to 'source/blender/python/api2_2x/Material.c')
-rw-r--r-- | source/blender/python/api2_2x/Material.c | 103 |
1 files changed, 102 insertions, 1 deletions
diff --git a/source/blender/python/api2_2x/Material.c b/source/blender/python/api2_2x/Material.c index 2d2de751aa0..abf2c349edc 100644 --- a/source/blender/python/api2_2x/Material.c +++ b/source/blender/python/api2_2x/Material.c @@ -24,7 +24,7 @@ * * This is a new part of Blender. * - * Contributor(s): Willian P. Germano, Michel Selten + * Contributor(s): Willian P. Germano, Michel Selten, Alex Mole * * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ @@ -41,6 +41,9 @@ #include "bpy_types.h" #include "modules.h" +#include "MTex.h" +#include "Texture.h" + #include "Material.h" /*****************************************************************************/ @@ -345,6 +348,7 @@ static PyObject *Material_getNFlares(BPy_Material *self); static PyObject *Material_getNStars(BPy_Material *self); static PyObject *Material_getNLines(BPy_Material *self); static PyObject *Material_getNRings(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); @@ -373,6 +377,8 @@ 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); +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); @@ -435,6 +441,8 @@ static PyMethodDef BPy_Material_methods[] = { "() - Return Material's number of lines in halo"}, {"getNRings", (PyCFunction)Material_getNRings, METH_NOARGS, "() - Return Material's number of rings in halo"}, + {"getTextures", (PyCFunction)Material_getTextures, METH_NOARGS, + "() - Return Material's texture list as a tuple"}, {"setName", (PyCFunction)Material_setName, METH_VARARGS, "(s) - Change Material's name"}, {"setIpo", (PyCFunction)Material_setIpo, METH_VARARGS, @@ -491,6 +499,10 @@ static PyMethodDef BPy_Material_methods[] = { "(i) - Set Material's number of lines in halo - [0, 250]"}, {"setNRings", (PyCFunction)Material_setNRings, METH_VARARGS, "(i) - Set Material's number of rings in halo - [0, 24]"}, + {"setTexture", (PyCFunction)Material_setTexture, METH_VARARGS, + "(n,tex,texco=0,mapto=0) - Set numbered texture to tex"}, + {"clearTexture", (PyCFunction)Material_clearTexture, METH_VARARGS, + "(n) - Remove texture from numbered slot"}, {0} }; @@ -878,6 +890,36 @@ static PyObject *Material_getNRings(BPy_Material *self) "couldn't get Material.nRings attribute"); } +static PyObject *Material_getTextures(BPy_Material *self) +{ + int i; + struct MTex *mtex; + PyObject *t[8]; + PyObject *tuple; + + /* build a texture list */ + for (i=0; i<8; ++i) { + mtex = self->material->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 ("NNNNNNNN", t[0], t[1], t[2], t[3], + t[4], t[5], t[6], t[7]); + if (!tuple) + return EXPP_ReturnPyObjError(PyExc_MemoryError, + "Material_getTextures: couldn't create PyTuple"); + + return tuple; +} + static PyObject *Material_setIpo(BPy_Material *self, PyObject *args) { PyObject *pyipo = 0; @@ -1352,6 +1394,65 @@ static PyObject *Material_setNRings(BPy_Material *self, PyObject *args) return EXPP_incr_ret (Py_None); } +static PyObject *Material_setTexture(BPy_Material *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,7] and Texture"); + if ((texnum<0) || (texnum>=8)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected int in [0,7] and Texture"); + + bltex = Texture_FromPyObject (pytex); + + if (!self->material->mtex[texnum]) { + /* there isn't an mtex for this slot so we need to make one */ + self->material->mtex[texnum] = add_mtex (); + } + else { + /* we already had a texture here so deal with the old one first */ + self->material->mtex[texnum]->tex->id.us--; + } + + self->material->mtex[texnum]->tex = bltex; + id_us_plus (&bltex->id); + self->material->mtex[texnum]->texco = texco; + self->material->mtex[texnum]->mapto = mapto; + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject *Material_clearTexture(BPy_Material *self, PyObject *args) +{ + int texnum; + struct MTex *mtex; + + if (!PyArg_ParseTuple(args, "i", &texnum)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected int in [0,7]"); + if ((texnum<0) || (texnum>=8)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected int in [0,7]"); + + mtex = self->material->mtex[texnum]; + if (mtex) { + if (mtex->tex) + mtex->tex->id.us--; + MEM_freeN (mtex); + self->material->mtex[texnum] = NULL; + } + + Py_INCREF(Py_None); + return Py_None; +} + /*****************************************************************************/ /* Function: Material_getAttr */ /* Description: This is a callback function for the BPy_Material type. It is */ |