I'm trying to debug an issue I'm having with regards to skeletal animation exporting from Maya and importing into my engine - C++ with OpenGL ES 2.0 and GLSL
I export the geometry along with bind pose matrices from an exporter in Maya along with bone/weight information in World Space. I'm able to see that this data gets imported correctly into my engine.
Maya
My Engine
http://imgur.com/yUL3D3D
As you can see, the base pose transforms are correctly exported. As is the geometry.
Next, I export the Animation Data in World Space from Maya. I'm able to draw the animated skeleton and have verified this as correct. Furthermore, I've written a custom shader that draws bone indices and weights directly on the mesh - this, too, I've verified as correct.
Where things are going wrong is when I pass along the transformation matrix to my vertex shader to displace the vertex positions and normals. My calculations are as follows -
worldToBindPose - transform from world origin to Bind Pose
worldToAnimation - transform from world origin to Animation Pose
finalTransform - the array of mat4 transforms passed to the vertex shader
So for each bone in the animation, I perform this calculation (Bind => World => Animation)
finalTransform = worldToAnimation * inverse(worldToBindPose);
and then in the vertex shader
vec4 tpos = vec4(pos, 1.0);
vec4 new_position =
((animation[int(bones.x)] * tpos) * weights.x) +
((animation[int(bones.y)] * tpos) * weights.y) +
((animation[int(bones.z)] * tpos) * weights.z) +
((animation[int(bones.w)] * tpos) * weights.w);
return projection * modelview * new_position.xyz;
And we get this:
The previous image sums up the result - the orange-red line is the bind pose, the purple line is the animated skeleton transforms. As you can see, the geometry should be fit to the purple line, but it's off. Similar animations display the same result - it looks kind of correct - it's almost as if my matrices aren't concatenating properly. I've looked at similar code samples, and even a previous exporter I had written years ago for 3D Studio Max, and my math is darn near identical.
I'm totally stuck, although I think I've narrowed it down to the line
finalTransform = worldToAnimation * inverse(worldToBindPose);
Any ideas?