Python API

----------
Add access to MTex objects from Lamps and Worlds (first pass).  Since the
MTex structure is slightly difference between materials, lamps, and worlds,
a field is added to the BPy MTex object to distinquish which type it wraps.

Attempting to access attributes which are unique to materials for lamp or
world MTex objects throw an exception.  The next pass will implement MTex
attributes which are specific to Lamps and Worlds.

A new attribute (textures) is added to each module.  It is compatible with
the previous Material.getTextures(), which returns a tuple of either MTex
objects or None.  Surprised we never added an attribute for this before in
all the changes and refactoring.
This commit is contained in:
Ken Hughes
2008-09-08 23:39:32 +00:00
parent de48280368
commit 3f87319428
9 changed files with 361 additions and 159 deletions

View File

@@ -52,6 +52,7 @@
#include "BIF_space.h"
#include "mydevice.h"
#include "Ipo.h"
#include "MTex.h"
#include "gen_utils.h"
#include "gen_library.h"
@@ -99,6 +100,7 @@ static PyObject *World_getScriptLinks( BPy_World * self, PyObject * value );
static PyObject *World_addScriptLink( BPy_World * self, PyObject * args );
static PyObject *World_clearScriptLinks( BPy_World * self, PyObject * args );
static PyObject *World_setCurrent( BPy_World * self );
static PyObject *World_getTextures( BPy_World * self );
static PyObject *World_copy( BPy_World * self );
@@ -250,6 +252,9 @@ static PyGetSetDef BPy_World_getseters[] = {
"world mist settings", NULL},
{"ipo", (getter)World_getIpo, (setter)World_setIpo,
"world ipo", NULL},
{"textures", (getter)World_getTextures, (setter)NULL,
"The World's texture list as a tuple",
NULL},
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
};
@@ -1029,3 +1034,27 @@ static PyObject *World_insertIpoKey( BPy_World * self, PyObject * args )
Py_RETURN_NONE;
}
static PyObject *World_getTextures( BPy_World * self )
{
int i;
PyObject *tuple;
/* build a texture list */
tuple = PyTuple_New( MAX_MTEX );
if( !tuple )
return EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create PyTuple" );
for( i = 0; i < MAX_MTEX; ++i ) {
struct MTex *mtex = self->world->mtex[i];
if( mtex ) {
PyTuple_SET_ITEM( tuple, i, MTex_CreatePyObject( mtex, ID_WO ) );
} else {
Py_INCREF( Py_None );
PyTuple_SET_ITEM( tuple, i, Py_None );
}
}
return tuple;
}