
Hello there!
I'm having a little problem creating a skeletal animation system and I wondered if any of you guys could help me.
Let me try to explain what's going on:
I am exporting the data from max with a maxscript. For each bone, I export the absolute transform with one quaternion and two vectors which respectively carry the absolute scale, and absolute translation.
To compute the absolute matrix for each bone on the engine side, I just transform everything into matrices and compute:
absoluteMatrix = rotationMatrix * scaleMatrix * translationMatrix

and this seems to work fine.
At first, I chose to calculate the relative matrices on the engine side, just after the animations are loaded. So here is what I am doing:
(1) Compute the length of the bones with:
// Any child will do
Matrix4x3 child = children[0]>absoluteInitialTranslation;
Matrix4x3 relative = inverse(absoluteInitialTranslation) * child;
length = Vector3(relative.m41, relative.m42, relative.m43).magnitude();

(2) Recursively compute the relative matrices with something like this:
relPos = inverse(parent>absoluteTranslation) * absoluteTranslation;
relScale = inverse(parent>absoluteScale) * absoluteScale;
relRot = inverse(parent>AbsoluteRotation) * absoluteOrientation;

I do that for every keyframe, there are more details that I can post if necessary.
(3) This is what I think I am getting wrong. After the interpolation (slerp for the rotations), I recursively reconnect the bones with the following:
absoluteRotation = parent>absoluteRotation * relativeRotation;
absoluteScale = parent>absoluteScale * relativeScale;
absoluteTranslation.identity();
Matrix4x3 m;
m.setupRotation(parent>absoluteRotation);
// X is the max direction for the up vector
absoluteTranslation.setupTranslation(Vector3(parent>length, 0, 0) * m);
// Concatenate with the translation of the parent
absoluteTranslation = parent>absoluteTranslation * absoluteTranslation;

This is a good summary of what I am doing. The visual problem Is is that some bones seem to be slightly in the wrong place. The animations play well, but there's a little distortion in the mesh particularly next to some joints.
I have compared the computed absolute matrices against the ones that come from max in the rest pose. There is a difference in the translation parts (the rotations seem to be fine so far). This difference is very small in the first two bones of the hierarchy, but as the recursion goes down the tree the difference gets bigger and bigger.
I would really appreciate any ideas. Thanks in advance.
William
