diff options
author | Ken Hughes <khughes@pacific.edu> | 2006-12-26 00:15:53 +0300 |
---|---|---|
committer | Ken Hughes <khughes@pacific.edu> | 2006-12-26 00:15:53 +0300 |
commit | 576c5b85b68f11b270736e692e120b011bedabcd (patch) | |
tree | 717c7250868db14a73611f012521a1303998c50e /source/blender/python/api2_2x/Curve.c | |
parent | 11cd11d4c938afefb0ec435f14fd02e0213f6b1e (diff) |
Python API
----------
Add .materials attribute to BPy Curve API. Also clean up Mesh.materials
documentation.
Diffstat (limited to 'source/blender/python/api2_2x/Curve.c')
-rw-r--r-- | source/blender/python/api2_2x/Curve.c | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/source/blender/python/api2_2x/Curve.c b/source/blender/python/api2_2x/Curve.c index f495a74a06c..6ac26a02c95 100644 --- a/source/blender/python/api2_2x/Curve.c +++ b/source/blender/python/api2_2x/Curve.c @@ -36,6 +36,7 @@ #include "BKE_global.h" #include "BKE_library.h" #include "BKE_curve.h" +#include "BKE_material.h" #include "MEM_guardedalloc.h" /* because we wil be mallocing memory */ #include "CurNurb.h" #include "SurfNurb.h" @@ -108,6 +109,7 @@ static PyObject *Curve_appendPoint( BPy_Curve * self, PyObject * args ); static PyObject *Curve_appendNurb( BPy_Curve * self, PyObject * args ); static PyObject *Curve_getMaterials( BPy_Curve * self ); +static PyObject *Curve_setMaterials( BPy_Curve * self, PyObject * args ); static PyObject *Curve_getBevOb( BPy_Curve * self ); static PyObject *Curve_setBevOb( BPy_Curve * self, PyObject * args ); @@ -1301,9 +1303,51 @@ PyObject *Curve_update( BPy_Curve * self ) static PyObject *Curve_getMaterials( BPy_Curve * self ) { - return ( EXPP_PyList_fromMaterialList( self->curve->mat, - self->curve->totcol, 1 ) ); + return EXPP_PyList_fromMaterialList( self->curve->mat, + self->curve->totcol, 1 ); +} + +static PyObject *Curve_setMaterials( BPy_Curve *self, PyObject * value ) +{ + Material **matlist; + int len; + + if( !PySequence_Check( value ) || + !EXPP_check_sequence_consistency( value, &Material_Type ) ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "sequence should only contain materials or None)" ); + + len = PySequence_Size( value ); + if( len > 16 ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "list can't have more than 16 materials" ); + + /* free old material list (if it exists) and adjust user counts */ + if( self->curve->mat ) { + Curve *cur = self->curve; + int i; + for( i = cur->totcol; i-- > 0; ) + if( cur->mat[i] ) + cur->mat[i]->id.us--; + MEM_freeN( cur->mat ); + } + + /* build the new material list, increment user count, store it */ + matlist = EXPP_newMaterialList_fromPyList( value ); + EXPP_incr_mats_us( matlist, len ); + self->curve->mat = matlist; + self->curve->totcol = (short)len; + +/**@ This is another ugly fix due to the weird material handling of blender. + * it makes sure that object material lists get updated (by their length) + * according to their data material lists, otherwise blender crashes. + * It just stupidly runs through all objects...BAD BAD BAD. + */ + + test_object_materials( ( ID * ) self->curve ); + + Py_RETURN_NONE; } /*****************************************************************************/ @@ -1589,6 +1633,8 @@ static PyObject *CurveGetAttr( BPy_Curve * self, char *name ) return Curve_getTaperOb( self ); else if( strcmp( name, "key" ) == 0 ) return Curve_getKey( self ); + else if( strcmp( name, "materials" ) == 0 ) + return Curve_getMaterials( self ); #if 0 else if( strcmp( name, "numpts" ) == 0 ) return Curve_getNumPoints( self ); @@ -1647,6 +1693,8 @@ static int CurveSetAttr( BPy_Curve * self, char *name, PyObject * value ) error = Curve_setBevOb( self, valtuple ); else if( strcmp( name, "taperob" ) == 0 ) error = Curve_setTaperOb( self, valtuple ); + else if( strcmp( name, "materials" ) == 0 ) + error = Curve_setMaterials( self, value ); else { /* Error */ Py_DECREF( valtuple ); |