[#10223] a new object function to add vertex group from an armature

Patch from Jean-Michel Soler (with slight modifs)

Small BPy feature to help script writers deal with armatures and vertex groups (calls the bone heat method to create and assign groups)
This commit is contained in:
Martin Poirier 2008-05-27 20:02:38 +00:00
parent 83a7fbf499
commit c1874b3cee
2 changed files with 46 additions and 0 deletions

@ -341,6 +341,7 @@ static int setupPI(Object* ob);
static PyObject *Object_getParticleSys( BPy_Object * self );
/* fixme Object_newParticleSys( self, default-partsys-name ) */
static PyObject *Object_addVertexGroupsFromArmature( BPy_Object * self, PyObject * args);
static PyObject *Object_newParticleSys( BPy_Object * self );
static PyObject *Object_buildParts( BPy_Object * self );
static PyObject *Object_clearIpo( BPy_Object * self );
@ -475,6 +476,8 @@ static PyMethodDef BPy_Object_methods[] = {
"Return a list of particle systems"},
{"newParticleSystem", ( PyCFunction ) Object_newParticleSys, METH_NOARGS,
"Create and link a new particle system"},
{"addVertexGroupsFromArmature" , ( PyCFunction ) Object_addVertexGroupsFromArmature, METH_VARARGS,
"Add vertex groups from armature using the bone heat method"},
{"buildParts", ( PyCFunction ) Object_buildParts, METH_NOARGS,
"Recalcs particle system (if any), (depricated, will always return an empty list in version 2.46)"},
{"getIpo", ( PyCFunction ) Object_getIpo, METH_NOARGS,
@ -1109,6 +1112,42 @@ PyObject *Object_newParticleSys( BPy_Object * self ){
return ParticleSys_CreatePyObject(rpsys,ob);
}
/*****************************************************************************/
/* attribute: addVertexGroupsFromArmature */
/* Description: evaluate and add vertex groups to the current object */
/* for each bone of the selected armature */
/* Data: self Object, Bpy armature */
/* Return: nothing */
/*****************************************************************************/
static PyObject *Object_addVertexGroupsFromArmature( BPy_Object * self, PyObject * args)
{
Object *ob = self->object;
BPy_Object *arm;
if( ob->type != OB_MESH )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"Only useable on Mesh type Objects" );
if( G.obedit != NULL)
return EXPP_ReturnPyObjError( PyExc_TypeError,
"Not useable when inside edit mode" );
/* Check if the arguments passed to makeParent are valid. */
if( !PyArg_ParseTuple( args, "O!",&Object_Type, &arm ) )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"An armature object is expected." );
if( arm->object->type != OB_ARMATURE )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"An armature object is expected." );
add_verts_to_dgroups(ob, arm->object, 1, 0);
ob->recalc |= OB_RECALC_OB;
Py_RETURN_NONE;
}
static PyObject *Object_buildParts( BPy_Object * self )
{
/* This is now handles by modifiers */

@ -651,6 +651,13 @@ class Object:
Link a new particle system (see Blender.Particle).
"""
def addVertexGroupsFromArmature(object):
"""
Add vertex groups from armature using the bone heat method
This method can be only used with an Object of the type Mesh when NOT in edit mode.
@type object: a bpy armature
"""
def buildParts():
"""
Recomputes the particle system. This method only applies to an Object of