Jump to content
  • Advertisement
Sign in to follow this  
Reitano

Animation of DirectX models driving me crazy!

This topic is 3968 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my engine I am adding support for models in the X format. I am not using D3DX but my own skeletal animation system. The importer seem to work fine because the mesh is correctly visualized, both in the character pose (without skinning) and in the bind pose (applying the offset matrices and combined joint transformations). The problems start when I try to animate the joints, using information extracted from the loaded animation controller. These information come in the form of a set of keyframes, one for rotations (as quaternions), one for translation and one for scaling. The algorithm I'm using is the standard one and it works perfectly with Milkshape3D models for example, so my fear is that DirectX stores keyframes using a convention different than the one used by my engine. For example, what order and coordinate system (this should not matter as long as everything is consistent) are the rotation, translation and scaling applied? My algorithm: .for each joint { . interpolate rotation, translation, scaling . build matrix M = translation*rotation*scaling (scaling is always identity in my samples, ignore it..) . if (joint->parent) { . joint->combined = joint->parent->combined*joint->relative*M . } . else { . joint->combined = joint->relative*M . } .} .for each bone { bone->matrix = bone->joint->combined * bone->offsetMatrix } The bones' matrices are then passed to a vertex shader and used for skinning. As I said, everything works as long as M = identity and it also works for Milkshape models so the problem is my interpretation of the keyframes imported from the X model. I have looked everywhere on the net all tutorials, examples etc but I didn't find any information specific to my problem. Any help will be very appreciated!!!

Share this post


Link to post
Share on other sites
Advertisement
I managed to solve the animation problem!
First of all, X models have keyframes that directly represent the transformation of a joint relative to its parent. In code:

transformation = interpolatedMatrix(keyframe->rotation, keyframe->scaling, keyframe->translation)
joint->combinedMatrix = joint->parentMatrix*transformation

This is very different with Milkshape 3D models, which store keyframes that modify the relative transformation instead of setting it directly. In code:

transformation = interpolatedMatrix(keyframe->rotation, keyframe->scaling, keyframe->translation)
joint->combinedMatrix = joint->parentMatrix*joint->relativeMatrix*transformation

Another difference I found by chance is that I had to negate the w component of all quaternions of the rotational keyframes. This has the effect of rotating the joints in the opposite direction with respect to their parents and it gives me correct animations. Go figure why.

If only Microsoft put some effort in documenting their classes and algorithms; reverse engineering is really not that fun.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!