I am making a simple bone animation library but I stuck in some point.
What I have: Mesh with few bones attached to it with animation. Mesh is properly skinned. It is 3d studio max file.
What I do:
I export this skinned mesh with my plugin. I take first animation frame and multiply every vertex, by this matrix (pseudocode)
Matrix invertedBoneMatrix = ZeroMatrix; invertedBoneMatrix += bone1WorldTransform * weight1; invertedBoneMatrix += bone2WorldTransform * weight2; invertedBoneMatrix += bone3WorldTransform * weight3; invertedBoneMatrix += bone4WorldTransform * weight4; invertedBoneMatrix.Invert(); foreach (vertex) vertex = invertedBoneMatrix * vertex;
When I load this model in my engine, I calculate world transforms for every bone at every animation frame and multiply every vertex by corresponding bone world transforms with proper weights.
Problem: Only first frame looks fine, others frames are distorted.
Maybe I have errors somewhere in my code, but I want to know, if my approach is correct - to bring all vertices to local space of its corresponding bones.