• Advertisement
Sign in to follow this  

X files don't animate as expected - solved

This topic is 4041 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

Hey guys - this problem has been driving me crazy for a really long time and I can't seem to find any info on what is happening. I have a simple mesh of a spider that animates. It was created in Maya5 and has bones for each of its 6 legs with a common root. When I animate it, it looks fine in Maya but not fine in my game, or in the SDK mesh viewers. Here is what it looks like: http://madox.ca/mediawiki/images/8/8c/Badanim2.avi Does anyone have any idea what I should look for? If I tweak the bones enough sometimes an animation will become fine, but other animations break. I don't think its a coding problem since the SDK apps do it too. Also should I be setting a key on every frame? Any help is apreciated. [Edited by - madox on January 30, 2007 10:32:07 AM]

Share this post


Link to post
Share on other sites
Advertisement
I'm doing pretty much exactly what the SkinnedMesh SDK demo does (slightly changed to fit into my own framework) for the indexed HLSL case. If I change the demo to load my x file, it has the same problem. I can go into details, but its all right from that demo. I can make the x file available when I get a chance.

Share this post


Link to post
Share on other sites
What plugin are you using to export the X file? Perhaps you should try some others, to narrow down the problem set.

Admiral

Ps: Spiders have eight legs [wink].

Share this post


Link to post
Share on other sites
Quote:
Original post by TheAdmiral
What plugin are you using to export the X file? Perhaps you should try some others, to narrow down the problem set.

Admiral

Ps: Spiders have eight legs [wink].


Heh well, I'm using the Maya5 plugin from whichever DX SDK it was that had it. Current SDKs don't have it. If the x files it creates are not expected to work in DX9 I'll have to look into buying some new software. I was hoping this was a simple known problem.

Here is one x file that doesnt animate as expected. http://madox.ca/mediawiki/images/b/bb/Badspider.zip

Spiders have eight legs but after six I grew weary of animating legs :)

Share this post


Link to post
Share on other sites
Hey guys - I've still been looking into this and I found something odd. I tried replacing my spider mesh with the tiny.x mesh from the SDK (the animated mesh of a woman walking). Tiny rendered fine in my app, and animated properly so I'll still convinced the problem is in the x file.

The Tiny mesh contains animation keys that have keyType = 4, but the help file that I have says the keys are rotation, scale, position, or matrix keys (using the integers 0, 1, 2, or 3, respectively). What is 4? Same as 3?

My mesh that the maya plug in generated contains 3 animation keys for each joint, one for each keyType 0,1,2. Does anyone know how these keys work? Maybe I can do a convertion to type 4 myself.

Share this post


Link to post
Share on other sites
The D3D SDK Mesh Viewer app also renders it wrong, so it's definitely somethign wrong with the mesh. If you watch it carefully, it almost looks as if that pair (triplet?) of legs is rotating the wrong direction. For example, instead of rotating 20 degrees, it's rotating 340. Check your Maya settings. I'm not familiar with the program, but if it can show you animation splines then you can see what's going on from Maya's point of view.

[edit] Are you storing animation matrix keyframes instead of or in addition to the normal animation spline keyframes? These always broke my models in Milkshape. Maybe it's the same with Maya.

Share this post


Link to post
Share on other sites
id recomend first of all just trying it out with "tiny.x" as i know that works perfectly using the method you have described,and i am yet to find a perfect exporter into the .x file

been looking to try out that kwxport but it seems to crash during installation

Share this post


Link to post
Share on other sites
To answer the above posts: Tiny.x does work fine and I don't know how to get matrix keysframes to export but I wish I did.

For some closure: I got my problem solved thanks to some advice I got. You need to loop through all your rotation keys computing dot products of every i, i+1 key pair. If the result is negative, you reverse the signs of the i+1 key. Seems to have fixed it up nicely. I don't know why DirectX doesn't just do this.

Here's my function that is a bit inefficient:

HRESULT fixupAnimations(ID3DXAnimationController* controller)
{
HRESULT hr = S_OK;

UINT numSets = controller->GetNumAnimationSets();
for (UINT i = 0; i < numSets; ++i) {
ID3DXAnimationSet* set;
ID3DXKeyframedAnimationSet* keyset;

if (FAILED( controller->GetAnimationSet(i, &set) )) continue;
if (FAILED( set->QueryInterface(IID_ID3DXKeyframedAnimationSet, (void**)&keyset) )) { set->Release(); continue; }
set->Release();

UINT numAnims = keyset->GetNumAnimations();
for (UINT j = 0; j < numAnims; ++j) {
UINT numKeys = keyset->GetNumRotationKeys(j);
D3DXKEY_QUATERNION* quats = (D3DXKEY_QUATERNION*)malloc(sizeof(D3DXKEY_QUATERNION) * numKeys);
if (FAILED( keyset->GetRotationKeys(j, quats) )) continue;

for (UINT k = 1; k < numKeys; ++k) {
FLOAT dot = D3DXQuaternionDot(&(quats[k-1].Value), &(quats[k].Value));
if (dot < 0.0f) {
quats[k].Value *= -1.0f;
keyset->SetRotationKey(j, k, &(quats[k]));
}
}
free(quats);
}
keyset->Release();
}

return hr;
}



[Edited by - madox on January 30, 2007 10:53:17 AM]

Share this post


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

  • Advertisement