Hallo,
I am trying to make animations work for my program, but I am running into some problems and as a bit unsure where it goes wrong for me.
Step 1:
I load the skeleton, if I try to render all the bone positions in world space (parent transform applied to children), I get a stick figure in the bind pose, so I think this part is ok.
for (int i = 0; i < skeleton.Bones.Count(); i++)
{
var x = new Microsoft.Xna.Framework.Quaternion(
skeleton.Bones[i].Rotation_X,
skeleton.Bones[i].Rotation_Y,
skeleton.Bones[i].Rotation_Z,
skeleton.Bones[i].Rotation_W);
x.Normalize();
var pos = Matrix.CreateFromQuaternion(x) * Matrix.CreateTranslation(skeleton.Bones[i].Position_X, skeleton.Bones[i].Position_Y, skeleton.Bones[i].Position_Z);
var info = new BoneInfo()
{
Index = skeleton.Bones[i].Id,
ParentIndex = skeleton.Bones[i].ParentId,
Position = pos,
WorldPosition = pos
};
model.Bones.Add(info);
}
for (int i = 0; i < model.Bones.Count(); i++)
{
if (model.Bones[i].ParentIndex == -1)
continue;
model.Bones[i].WorldPosition = model.Bones[i].WorldPosition * model.Bones[model.Bones[i].ParentIndex].WorldPosition;
}
Step 2:
I load the animation file, and do the following:
- Copy the bind pose bones into my AnimationTransform array. Then I do the following:
- For each bone that has an animation, replace that bones transformation with the animation information. At this point, we are in local space.
- Move into world space, but multiplying each child transform by its parent.
- For each AnimationTransform, multiply it with the inverse bind position for this bone.
Code removed...Updated in later post
If I at this stage apply the animation transform to the skeleton, I get a skeleton that looks like its animated correctly for its frame.
Step 3:
I now try to apply the animationFrames to the mesh, but he mesh ends up looking all messed up.
Code removed...Updated in later post
Since my skeletons are rendering ok I feel fairly certain that the animation transforms are ok, but I am not sure. Any idea where I am messing it up?