diff options
author | Joseph Gilbert <ascotan@gmail.com> | 2004-04-15 03:42:58 +0400 |
---|---|---|
committer | Joseph Gilbert <ascotan@gmail.com> | 2004-04-15 03:42:58 +0400 |
commit | e2bed35011e353c98bce8ad8f457177e1ebf1332 (patch) | |
tree | 7f81bb4464536e566870eb93855ae1b6a2f9181d /source/blender/python/api2_2x/Armature.c | |
parent | 837da93f19376bd61a478b6cda11868415241703 (diff) |
- parenting checks for bone additions to armature
- update to addBone parenting transform code
- hide/unhide bones
- draw axes/draw names
- clear parenting and clear children from bones - removes childbase links from bone and set as root or remove parenting and set as root
Diffstat (limited to 'source/blender/python/api2_2x/Armature.c')
-rw-r--r-- | source/blender/python/api2_2x/Armature.c | 89 |
1 files changed, 63 insertions, 26 deletions
diff --git a/source/blender/python/api2_2x/Armature.c b/source/blender/python/api2_2x/Armature.c index b10fb6574d0..c8ae99fd67b 100644 --- a/source/blender/python/api2_2x/Armature.c +++ b/source/blender/python/api2_2x/Armature.c @@ -24,7 +24,7 @@ * * This is a new part of Blender. * - * Contributor(s): Jordi Rovira i Bonet + * Contributor(s): Jordi Rovira i Bonet, Joseph Gilbert * * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ @@ -94,7 +94,8 @@ static PyObject *Armature_getName (BPy_Armature * self); static PyObject *Armature_getBones (BPy_Armature * self); static PyObject *Armature_addBone(BPy_Armature *self, PyObject *args); static PyObject *Armature_setName (BPy_Armature * self, PyObject * args); -/* static PyObject *Armature_setBones(BPy_Armature *self, PyObject *args); */ +static PyObject *Armature_drawAxes (BPy_Armature * self, PyObject * args); +static PyObject *Armature_drawNames (BPy_Armature * self, PyObject * args); /*****************************************************************************/ /* Python BPy_Armature methods table: */ @@ -109,9 +110,10 @@ static PyMethodDef BPy_Armature_methods[] = { "(str) - rename Armature"}, {"addBone", (PyCFunction)Armature_addBone, METH_VARARGS, "(bone)-add bone"}, - /* {"setBones", (PyCFunction)Armature_setBones, METH_VARARGS, - "(list of bones) - replace the whole bone list of the armature"}, - */ + {"drawAxes", (PyCFunction)Armature_drawAxes, METH_VARARGS, + "will draw the axis of each bone in armature"}, + {"drawNames", (PyCFunction)Armature_drawNames, METH_VARARGS, + "will draw the names of each bone in armature"}, {NULL, NULL, 0, NULL} }; @@ -389,16 +391,25 @@ doesBoneName_exist(char *name, bArmature* arm) return 0; } +static int +testBoneInArmature(bArmature *arm, Bone *test) +{ + Bone *root; + + for(root = arm->bonebase.first; root; root = root->next){ + if(root == test){ + return 1; + } + } + + return 0; +} + static PyObject *Armature_addBone(BPy_Armature *self, PyObject *args) { BPy_Bone* py_bone = NULL; float M_boneObjectspace[4][4]; - float M_parentRest[4][4]; float iM_parentRest[4][4]; - float delta[3]; - float rootHead[3]; - float rootTail[3]; - if (!PyArg_ParseTuple(args, "O!", &Bone_Type, &py_bone)) return (EXPP_ReturnPyObjError (PyExc_TypeError, @@ -413,30 +424,20 @@ static PyObject *Armature_addBone(BPy_Armature *self, PyObject *args) //if bone has a parent.... if(py_bone->bone->parent){ + + //then check to see if parent has been added to the armature - bone loop test + if(!testBoneInArmature(self->armature, py_bone->bone->parent)) + return (EXPP_ReturnPyObjError (PyExc_TypeError, + "cannot parent to a bone not yet added to armature!")); //add to parent's childbase BLI_addtail (&py_bone->bone->parent->childbase, py_bone->bone); //get the worldspace coords for the parent - get_objectspace_bone_matrix(py_bone->bone->parent, M_boneObjectspace, 1,0); - rootHead[0] = M_boneObjectspace[3][0]; - rootHead[1] = M_boneObjectspace[3][1]; - rootHead[2] = M_boneObjectspace[3][2]; get_objectspace_bone_matrix(py_bone->bone->parent, M_boneObjectspace, 0,0); - rootTail[0] = M_boneObjectspace[3][0]; - rootTail[1] = M_boneObjectspace[3][1]; - rootTail[2] = M_boneObjectspace[3][2]; - - //rest matrix of parent - VecSubf (delta, rootTail, rootHead); - make_boneMatrixvr(M_parentRest, delta, py_bone->bone->parent->roll); // Invert the parent rest matrix - Mat4Invert (iM_parentRest, M_parentRest); - - // Get the new head and tail - VecSubf (py_bone->bone->head, py_bone->bone->head, rootTail); - VecSubf (py_bone->bone->tail, py_bone->bone->tail, rootTail); + Mat4Invert (iM_parentRest, M_boneObjectspace); //transformation of local bone Mat4MulVecfl(iM_parentRest, py_bone->bone->head); @@ -469,6 +470,42 @@ Armature_setName (BPy_Armature * self, PyObject * args) return Py_None; } +static PyObject * +Armature_drawAxes (BPy_Armature * self, PyObject * args) +{ + int toggle; + + if (!PyArg_ParseTuple (args, "i", &toggle)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected 1 or 0 as integer")); + + if(toggle) + self->armature->flag |= ARM_DRAWAXES; + else + self->armature->flag &= ~ARM_DRAWAXES; + + Py_INCREF (Py_None); + return Py_None; +} + +static PyObject * +Armature_drawNames (BPy_Armature * self, PyObject * args) +{ + int toggle; + + if (!PyArg_ParseTuple (args, "i", &toggle)) + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected 1 or 0 as integer")); + + if(toggle) + self->armature->flag |= ARM_DRAWNAMES; + else + self->armature->flag &= ~ARM_DRAWNAMES; + + Py_INCREF (Py_None); + return Py_None; +} + /*****************************************************************************/ /* Function: Armature_dealloc */ /* Description: This is a callback function for the BPy_Armature type. It is */ |