1
\$\begingroup\$

I'm creating a model/animation viewer in C# using OpenTK for a game's models. Before stating my problem I want to describe a bit what I've accomplished so far in case I'm fundamentally missing something.

First of all I parsed the model skeleton. Like described pretty much everywhere on the web, what I do is to traverse all the hierarchy starting from the root bone and start building up the joint matrices. The game file provides separately translation,rotation and scale vectors. In order to create all the joint matrices I'm using only the rotation values, which I am converting into a rotation matrix and I'm saving it as the localMatrix. I'm saving the translations as joint position (localPosition) and I'm using them later on to calculate the worldPosition of my joints by transforming that using the parent's worldMatrix.

The following methods are responsible for getting the joint world Matrix and its world Position

public Vector3 worldPosition {
        get
        {
            if (parent != null)
                return parent.worldPosition + Vector3.Transform(this.localPosition, parent.worldMat);
                this.worldMat);
            else
                return this.localPosition;
        }
}
public Matrix4 worldMat
    {
        get
        {
            if (parent != null)
                return Matrix4.Mult(this.localMat, parent.worldMat);
            else
                return this.localMat;
        }
}

Using that piece of code I can preview the skeleton perfectly. I also managed to parse the animations. I used the rotation information on each frame in order to update each joints local matrix and therefore I was able to successfully preview the animation on the joint skeleton.

Now the only thing I am missing is to bind the mesh on the skeleton (I'm trying to do that using a vertex shader). Wherever I search on the web, i find that i need to apply the following equation:

eq

I got the blendIndices and the blendWeights so that's not a problem as well. I'm completely confused with the bone matrices though. If I understand correctly matrix[i] is the joint's world transformation matrix. The other inverse matrix is supposed to transform my vertex back to the bindpose? Since my model is already in the bindpose what do I need this matrix for?

I tried applying just the joint worldmatrices that I have precalculated, but the mesh was completely corrupted. So I'm definitely missing something.

I've also found some matrices in the model file which seem like they are probably prebaked joint world matrices. In fact I compared their values and they are EXACTLY the same with the ones I'm calculating through traversing the bone hierarchy. Their only difference though is that they also contain translation information. So my question is: Do bone matrices contain translation information as well? If so, then this means that my way of parsing the skeleton is wrong? I just can't thing of another way to use the full matrices (rotation + translation) in order to correctly position the joints.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I think the bindpose matrix you are referring to is also the bone offset matrix, which is related to its parent. It transform the bone from the mesh space to its local space. A final transformation of a bone is normally calculated like this:

FinalTransform = ParentTransform * (Translation * Rotation *Scaling) * OffsetMatrix

Are you missing the parent's transform here? Would be better if you can provide a code snippet.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .