diff options
author | Ken Hughes <khughes@pacific.edu> | 2005-11-20 04:07:54 +0300 |
---|---|---|
committer | Ken Hughes <khughes@pacific.edu> | 2005-11-20 04:07:54 +0300 |
commit | a86b0af575c6dad58b8c6ef223d20f5e76a055ed (patch) | |
tree | 16afa9953fde0d1ce2f504a99b0c3facf3e0ffd8 /source/blender | |
parent | b6c5b24f4ff763a8c9ecde4367f30a7784dc5677 (diff) |
-- added an optional "cage" parameter to mesh.getFromObject() to allow
getting cage vertices from geometry objects
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/python/api2_2x/Mesh.c | 52 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Mesh.py | 10 |
2 files changed, 40 insertions, 22 deletions
diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c index 2f088a1be87..3aed4695ca1 100644 --- a/source/blender/python/api2_2x/Mesh.c +++ b/source/blender/python/api2_2x/Mesh.c @@ -639,7 +639,7 @@ static PyObject *MCol_getAttr( BPy_MCol * self, void *type ) unsigned char param; PyObject *attr; - switch( (int)type ) { + switch( (long)type ) { case 'R': /* these are backwards, but that how it works */ param = self->color->b; break; @@ -655,7 +655,8 @@ static PyObject *MCol_getAttr( BPy_MCol * self, void *type ) default: { char errstr[1024]; - sprintf( errstr, "undefined type '%d' in MCol_getAttr", (int)type ); + sprintf( errstr, "undefined type '%d' in MCol_getAttr", + (int)((long)type & 0xff)); return EXPP_ReturnPyObjError( PyExc_RuntimeError, errstr ); } } @@ -676,23 +677,24 @@ static int MCol_setAttr( BPy_MCol * self, PyObject * value, void * type ) { unsigned char *param; - switch( (int)type ) { + switch( (long)type ) { case 'R': /* these are backwards, but that how it works */ - param = &self->color->b; + param = (unsigned char *)&self->color->b; break; case 'G': - param = &self->color->g; + param = (unsigned char *)&self->color->g; break; case 'B': /* these are backwards, but that how it works */ - param = &self->color->r; + param = (unsigned char *)&self->color->r; break; case 'A': - param = &self->color->a; + param = (unsigned char *)&self->color->a; break; default: { char errstr[1024]; - sprintf( errstr, "undefined type '%d' in MCol_setAttr", (int)type ); + sprintf( errstr, "undefined type '%d' in MCol_setAttr", + (int)((long)type & 0xff)); return EXPP_ReturnIntError( PyExc_RuntimeError, errstr ); } } @@ -3065,7 +3067,7 @@ static PyObject *MFace_getMFlagBits( BPy_MFace * self, void * type ) if( !face ) return NULL; - return EXPP_getBitfield( &face->flag, (int)type, 'b' ); + return EXPP_getBitfield( &face->flag, (int)((long)type & 0xff), 'b' ); } /* @@ -3080,7 +3082,7 @@ static int MFace_setMFlagBits( BPy_MFace * self, PyObject * value, if( !face ) return -1; - return EXPP_setBitfield( value, &face->flag, (int)type, 'b' ); + return EXPP_setBitfield( value, &face->flag, (int)((long)type & 0xff), 'b' ); } /* @@ -4736,10 +4738,15 @@ static PyObject *Mesh_getFromObject( BPy_Mesh * self, PyObject * args ) DispListMesh *dlm; DerivedMesh *dm; Object *tmpobj = NULL; + int cage = 0; - if( !PyArg_ParseTuple( args, "s", &name ) ) + if( !PyArg_ParseTuple( args, "s|i", &name, &cage ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected string argument" ); + "expected string and optional integer arguments" ); + + if( cage != 0 && cage != 1 ) + return EXPP_ReturnPyObjError( PyExc_ValueError, + "cage value must be 0 or 1" ); /* find the specified object */ ob = ( Object * ) GetIdFromList( &( G.main->object ), name ); @@ -4756,6 +4763,10 @@ static PyObject *Mesh_getFromObject( BPy_Mesh * self, PyObject * args ) tmpcu = (Curve *)tmpobj->data; tmpcu->id.us--; + /* if getting the original caged mesh, delete object modifiers */ + if( cage ) + object_free_modifiers(tmpobj); + /* copies the data */ tmpobj->data = copy_curve( (Curve *) ob->data ); @@ -4768,6 +4779,7 @@ static PyObject *Mesh_getFromObject( BPy_Mesh * self, PyObject * args ) MEM_freeN( cu->disp.first ); cu->disp.first = NULL; } + #endif /* get updated display list, and convert to a mesh */ @@ -4793,11 +4805,13 @@ static PyObject *Mesh_getFromObject( BPy_Mesh * self, PyObject * args ) G.totmesh++; tmpmesh = tmpobj->data; - /* get the final derived mesh */ - dm = mesh_create_derived_render( tmpobj ); - dlm = dm->convertToDispListMesh( dm, 0 ); - displistmesh_to_mesh( dlm, tmpmesh ); - dm->release( dm ); + /* if not getting the original caged mesh, get final derived mesh */ + if( !cage ) { + dm = mesh_create_derived_render( tmpobj ); + dlm = dm->convertToDispListMesh( dm, 0 ); + displistmesh_to_mesh( dlm, tmpmesh ); + dm->release( dm ); + } /* take control of mesh before object is freed */ tmpobj->data = NULL; @@ -5752,7 +5766,7 @@ static PyObject *Mesh_getFlag( BPy_Mesh * self, void *type ) { PyObject *attr; - switch( (int)type ) { + switch( (long)type ) { case MESH_HASFACEUV: attr = self->mesh->tface ? EXPP_incr_ret_True() : EXPP_incr_ret_False(); @@ -5793,7 +5807,7 @@ static int Mesh_setFlag( BPy_Mesh * self, PyObject *value, void *type ) /* sticky is independent of faceUV and vertUV */ /* faceUV (tface) has priority over vertUV (mcol) */ - switch( (int)type ) { + switch( (long)type ) { case MESH_HASFACEUV: if( !param ) { if( mesh->tface ) { diff --git a/source/blender/python/api2_2x/doc/Mesh.py b/source/blender/python/api2_2x/doc/Mesh.py index 263c4762a76..9e1b3e6610f 100644 --- a/source/blender/python/api2_2x/doc/Mesh.py +++ b/source/blender/python/api2_2x/doc/Mesh.py @@ -620,17 +620,21 @@ class Mesh: @type activeFace: int """ - def getFromObject(name): + def getFromObject(name,cage=0): """ Replace the mesh's existing data with the raw mesh data from a Blender Object. This method supports all the geometry based objects (mesh, text, curve, surface, and meta). If the object has modifiers, they will be - applied before to the object before extracting the vertex data. - @note: The mesh coordinates are in i{local space}, not the world space of + applied before to the object before extracting the vertex data unless + the B{cage} parameter is 1. + @note: The mesh coordinates are in I{local space}, not the world space of its object. For world space vertex coordinates, each vertex location must be multiplied by the object's 4x4 transform matrix (see L{transform}). @type name: string @param name: name of the Blender object which contains the geometry data. + @type cage: int + @param cage: determines whether the original vertices or derived vertices + (for objects with modifiers) are used. The default is derived vertices. """ def calcNormals(): |