diff options
author | Ken Hughes <khughes@pacific.edu> | 2006-01-19 18:48:56 +0300 |
---|---|---|
committer | Ken Hughes <khughes@pacific.edu> | 2006-01-19 18:48:56 +0300 |
commit | 0fcfd5bd4014c4cfcd51b3685dbd012c7dbf583b (patch) | |
tree | ce978c79e3aa31f7a6c9dd6fa62964e99aa84b54 | |
parent | 14e1000e387b0dc3541610a88c54cb88f367b05e (diff) |
===Python API===
Bugfix #3660: NMesh.getVertexInfluences() was broken following the changes
to the armature system. Tron Thomas (kudos) came up with a fix that seems
to perform identically to the old method. I'm also adding it to the Mesh
module for compatibility.
-rw-r--r-- | source/blender/python/api2_2x/Mesh.c | 59 | ||||
-rw-r--r-- | source/blender/python/api2_2x/NMesh.c | 86 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Mesh.py | 10 |
3 files changed, 95 insertions, 60 deletions
diff --git a/source/blender/python/api2_2x/Mesh.c b/source/blender/python/api2_2x/Mesh.c index 9440e15bbd8..49d699174cf 100644 --- a/source/blender/python/api2_2x/Mesh.c +++ b/source/blender/python/api2_2x/Mesh.c @@ -82,8 +82,6 @@ #include "constant.h" #include "gen_utils.h" -#define MESH_TOOLS /* add access to mesh tools */ - /* EXPP Mesh defines */ #define MESH_SMOOTHRESH 30 @@ -5509,7 +5507,53 @@ static PyObject *Mesh_getVertGroupNames( BPy_Mesh * self ) return list; } -#ifdef MESH_TOOLS +static PyObject *Mesh_getVertexInfluences( BPy_Mesh * self, PyObject * args ) +{ + int index; + PyObject *influence_list = NULL; + Object *object = self->object; + Mesh *me = self->mesh; + + /* Get a reference to the mesh object wrapped in here. */ + if( !object ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "This mesh must be linked to an object" ); + + /* Parse the parameters: only on integer (vertex index) */ + if( !PyArg_ParseTuple( args, "i", &index ) ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected int argument (index of the vertex)" ); + + /* check for valid index */ + if( index < 0 || index >= me->totvert ) + return EXPP_ReturnPyObjError( PyExc_IndexError, + "vertex index out of range" ); + + influence_list = PyList_New( 0 ); + + /* Proceed only if we have vertex deformation information */ + if( me->dvert ) { + int i; + MDeformWeight *sweight = NULL; + + /* Number of bones influencing the vertex */ + int totinfluences = me->dvert[index].totweight; + + /* Get the reference of the first weight structure */ + sweight = me->dvert[index].dw; + + /* Build the list only with weights and names of the influent bones */ + for( i = 0; i < totinfluences; i++, sweight++ ) { + bDeformGroup *defgroup = BLI_findlink( &object->defbase, + sweight->def_nr ); + if( defgroup ) + PyList_Append( influence_list, Py_BuildValue( "[sf]", + defgroup->name, sweight->weight ) ); + } + } + + return influence_list; +} static PyObject *Mesh_Tools( BPy_Mesh * self, int type, void **args ) { @@ -5711,8 +5755,6 @@ static PyObject *Mesh_fill( BPy_Mesh * self ) return Mesh_Tools( self, MESH_TOOL_FILL, NULL ); } -#endif - static struct PyMethodDef BPy_Mesh_methods[] = { {"calcNormals", (PyCFunction)Mesh_calcNormals, METH_NOARGS, "all recalculate vertex normals"}, @@ -5740,10 +5782,10 @@ static struct PyMethodDef BPy_Mesh_methods[] = { "Rename an existing vertex group"}, {"getVertGroupNames", (PyCFunction)Mesh_getVertGroupNames, METH_NOARGS, "Get names of vertex groups"}, + {"getVertexInfluences", (PyCFunction)Mesh_getVertexInfluences, METH_VARARGS, + "Get list of the influences of bones for a given mesh vertex"}, - - -#ifdef MESH_TOOLS + /* Mesh tools */ {"smooth", (PyCFunction)Mesh_smooth, METH_NOARGS, "Flattens angle of selected faces (experimental)"}, {"flipNormals", (PyCFunction)Mesh_flipNormals, METH_NOARGS, @@ -5762,7 +5804,6 @@ static struct PyMethodDef BPy_Mesh_methods[] = { "Removes duplicates from selected vertices (experimental)"}, {"recalcNormals", (PyCFunction)Mesh_recalcNormals, METH_VARARGS, "Recalculates inside or outside normals (experimental)"}, -#endif {NULL, NULL, 0, NULL} }; diff --git a/source/blender/python/api2_2x/NMesh.c b/source/blender/python/api2_2x/NMesh.c index f285557d5ee..1fc0bff2af2 100644 --- a/source/blender/python/api2_2x/NMesh.c +++ b/source/blender/python/api2_2x/NMesh.c @@ -1466,71 +1466,55 @@ static PyObject *NMesh_update( PyObject *self, PyObject *a, PyObject *kwd ) * influences that this vertex receives. * @author Jordi Rovira i Bonet */ + static PyObject *NMesh_getVertexInfluences( PyObject * self, PyObject * args ) { int index; PyObject *influence_list = NULL; - - /* Get a reference to the mesh object wrapped in here. */ + Object *object = ( ( BPy_NMesh * ) self )->object; Mesh *me = ( ( BPy_NMesh * ) self )->mesh; + /* Get a reference to the mesh object wrapped in here. */ if( !me ) return EXPP_ReturnPyObjError( PyExc_RuntimeError, - "unlinked nmesh: call its .update() method first" ); + "unlinked nmesh: call its .update() method first" ); + + if( !object ) + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "This mesh must be linked to an object" ); /* Parse the parameters: only on integer (vertex index) */ if( !PyArg_ParseTuple( args, "i", &index ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected int argument (index of the vertex)" ); + "expected int argument (index of the vertex)" ); + + /* check for valid index */ + if( index < 0 || index >= me->totvert ) + return EXPP_ReturnPyObjError( PyExc_IndexError, + "vertex index out of range" ); + + influence_list = PyList_New( 0 ); - /* Proceed only if we have vertex deformation information and index is valid */ + /* Proceed only if we have vertex deformation information */ if( me->dvert ) { - if( ( index >= 0 ) && ( index < me->totvert ) ) { - - int i; - MDeformWeight *sweight = NULL; - - /* Number of bones influencing the vertex */ - int totinfluences = me->dvert[index].totweight; - - /* Build the list only with weights and names of the influent bones */ - /*influence_list = PyList_New(totinfluences); */ - influence_list = PyList_New( 0 ); - - /* Get the reference of the first weight structure */ - sweight = me->dvert[index].dw; - - for( i = 0; i < totinfluences; i++ ) { - /*Add the weight and the name of the bone, which is used to identify it */ - - /* Disabled this code, it couldn't be correct! - * sweight->data was being set to a posechannel not a bone - * for one thing, and it is not always set for another. - * The only thing safe here is to return the defgroup number. -zr - */ -// if( sweight->data ) - /* valid bone: return its name */ - /* PyList_SetItem(influence_list, i, - Py_BuildValue("[sf]", sweight->data->name, sweight->weight)); - else // NULL bone: return Py_None instead - PyList_SetItem(influence_list, i, - Py_BuildValue("[Of]", Py_None, sweight->weight)); */ -// PyList_Append( influence_list, -// Py_BuildValue( "[sf]", -// sweight-> -// data-> -// name, -// sweight-> -// weight ) ); - - /* Next weight */ - sweight++; - } - } else //influence_list = PyList_New(0); - return EXPP_ReturnPyObjError( PyExc_IndexError, - "vertex index out of range" ); - } else - influence_list = PyList_New( 0 ); + int i; + MDeformWeight *sweight = NULL; + + /* Number of bones influencing the vertex */ + int totinfluences = me->dvert[index].totweight; + + /* Get the reference of the first weight structure */ + sweight = me->dvert[index].dw; + + /* Build the list only with weights and names of the influent bones */ + for( i = 0; i < totinfluences; i++, sweight++ ) { + bDeformGroup *defgroup = BLI_findlink( &object->defbase, + sweight->def_nr ); + if( defgroup ) + PyList_Append( influence_list, Py_BuildValue( "[sf]", + defgroup->name, sweight->weight ) ); + } + } return influence_list; } diff --git a/source/blender/python/api2_2x/doc/Mesh.py b/source/blender/python/api2_2x/doc/Mesh.py index 7711345959e..54fd5d59cf0 100644 --- a/source/blender/python/api2_2x/doc/Mesh.py +++ b/source/blender/python/api2_2x/doc/Mesh.py @@ -846,6 +846,16 @@ class Mesh: associated with the mesh's object """ + def getVertexInfluences(index): + """ + Get the bone influences for a specific vertex. + @type index: int + @param index: The index of a vertex. + @rtype: list of lists + @return: List of pairs [name, weight], where name is the bone name (string) + and weight is a float value. + """ + def smooth(): """ Flattens angle of selected faces. Experimental mesh tool. |