¿Cómo obtengo la matriz absoluta de cada hueso?

I am working with C and OpenGL. I am trying to load a 3D model with skeletal animation, but I just can't seem to calculate the absolute matrix of each bone for each frame of the animation.

I have: For each bone, I have a matrix and an inverse matrix and for each frame of the animation, I have a rotation(Euler) and a translation for each bone.

Blender Import/Export scripts:

http://pastebin.com/xMJ2fG26

http://pastebin.com/9D42RKRf

edit: if someone knows how to get a bone's absolute matrix with blender and export that, that would also be fine (I'm new to Blender)

for each frame f
    for each bone i
        glLoadIdentity();
        glMultMatrixd(bones[i].matrix);
        for each parent bone ii(starting from the top)
            glTranslated(bones[ii].translation[f].x, bones[ii].translation[f].y, bones[ii].translation[f].z);
            glRotated(bones[ii].degrees[f].z, 0.0, 0.0, 1.0);
            glRotated(bones[ii].degrees[f].x, 1.0, 0.0, 0.0);
            glRotated(bones[ii].degrees[f].y, 0.0, 1.0, 0.0);
        glMultMatrixd(bones[i].inversematrix);
        glGetDoublev(GL_PROJECTION_MATRIX, bones[i].absmatrix[f]);

preguntado el 01 de febrero de 12 a las 22:02

I tried applying the rotations/transations starting from the first parent bone. Then I tried applying the bone's(still starting from the first parent bone) matrix, then rotation/translation, then the inverse matrix of that bone, and do that for each bone of the tree. I also tried many other things... -

Can you give some example code of what you've tried and what doesn't work about it? -

I added some pseudo-code representing my latest attempt -

2 Respuestas

Those scripts look like they were written for the obsolete 2.4*x* versions of Blender. For 2.5*x*/2.6*x*, you have a much-improved Python API that includes Hueso objects with “matrix” and “matrix_local” attributes.

I’d recommend you try to do what you want to do with a current version of Blender. Much less likely to be hitting your head against a brick wall that way.

Respondido 02 Feb 12, 04:02

Would you happen to know how I can get the absolute matrix of each bone(in 2.4*x*)? I tried using the poseMatrix of each bone for each frame but it didn't work. I cant use the new versions of Blender because those scripts wouldn't work (actually I didnt try but..) - Jonathan

In your comment to Lawrence you're right that your 2.4 scripts will not work for Blender 2.5. However your problem is not very complicated. The matrices you get are the local transformation from each bone to the next one. So all you need to do it multiplying them one after another in the dependency tree.

So what you do is a depth-first traversal of the tree, and for each iteration down the tree you ad a glPushMatrix(); glMultMatrix(bone_matrix); and when going up a step reverse the effect with glPopMatrix();

Respondido 02 Feb 12, 12:02

By "bone_matrix" do you mean the bone's armature matrix or the local transformation matrix of the bone? - Jonathan

@Jonathan: IIRC the armature matrix is the transformation of the armature's pivot point. Each bone is locally represented, relative to its parent bone by the local transformation. So you'd multiply AM * BM * BM * ... * BM. - datenwolf

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.