[Bf-python] Armature again
Joseph Gilbert
models at paposo.com
Tue Mar 23 04:11:07 CET 2004
Yes I saw that too. This does a better job but the 'roll's are not right.
Bob is still working on this. This is the current code.
static PyObject *Armature_addBone(BPy_Armature *self, PyObject *args)
{
BPy_Bone* py_bone = NULL;
BPy_Bone* py_boneRoot = NULL;
float M_boneObjectspace[4][4];
float M_boneRest[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,
"expected bone object argument (or nothing)"));
if(py_bone != NULL)
if(!py_bone->bone)
return (EXPP_ReturnPyObjError (PyExc_TypeError, "bone contains no
data!"));
//if bone has a parent....
if(py_bone->bone->parent){
BLI_addtail (&py_bone->bone->parent->childbase, py_bone->bone);
//get the local root for this parenting
py_bone->bone->parent = py_bone->bone->parent;
//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);
//transformation
Mat4MulVecfl(iM_parentRest, py_bone->bone->head);
Mat4MulVecfl(iM_parentRest, py_bone->bone->tail);
}else //no parent....
BLI_addtail (&self->armature->bonebase,py_bone->bone);
//add the py_bone to the py_armature list
PyList_Append(self->bones, py_bone);
precalc_bonelist_irestmats(&self->armature->bonebase);
Py_INCREF(Py_None);
return Py_None;
}
-----Original Message-----
From: bf-python-admin at blender.org [mailto:bf-python-admin at blender.org]On
Behalf Of Michael Schardt
Sent: Monday, March 22, 2004 11:28 AM
To: bf-python at blender.org
Subject: [Bf-python] Armature again
Hi all!
With my tests of the new armature module i found the following inconsistency
in positioning the bones:
Adding the first bone (call it 'A') to an armature (a rootbone) you have to
provide global coordinates for the setHead() and setTail() functions - ok.
When adding the second bone 'B' as a child of 'A' i would have expected to
provide local coordinates - but in fact we again have to give global
coordinates to setHead() and setTail() - well...
I was a bit surprised when i tried to add a 3rd bone 'C' as a child of bone
'B': all of a sudden i have to give local coordinates to the
set...-functions!
Try my little test program "test_bones-4.py" to see what i mean. See the
inconsistency?
More information about the Bf-python
mailing list