Sign in to follow this  

X File Animation Keys are a MESS

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

I've just recently started trying to use the X file format to load in animations. [sad] I have a serious glitch. [sad] This is the first keyframe matrix for the pelvis (or hip), which has absolutely no keyframes ([sad]) defined in the animation. Which I assumed would mean that it would contain identity matrices as the only keys. Here's what I get for the hip, pulled directly from the file: [sad]
 0.000000,  1.000000,   -0.000001,  0.000000
-0.000001,  0.000001,    1.000000,  0.000000
 1.000000,  0.000000,    0.000001,  0.000000
-0.720993,  0.000000,    0.000000,  1.000000

Doesn't look like an ID matrix to me. It almost looks like a damn offset matrix. It's not just the hip either; other bones are whacky as well. When converted to a quaternion, this hip matrix is 0.5, 0.5, 0.5, 0.5 as opposed to my expectations of 0,0,0,1. Anyone have a clue about what the hell is going on here? I've tried swapping the vector coordinates. As it looks like Z = X, Y = Z, and X = Y. But it doesn't work for other bones; just the hip. For any experienced X-File parser programmers, here is the small snip of code where I locate these matrices:


//------------------------------------------------
//
//              Loading Structure
//
//------------------------------------------------

struct KDxFileMatKey
{
    DWORD               Time;                   // Time of the frame
    DWORD               Floats;                 // No clue
    D3DXMATRIX          Matrix;                 // The frame transform
};

//------------------------------------------------
//
//                    Parser
//
//------------------------------------------------

VOID CAnimationConverterDlg::ParseData(KDxDataPak *Data)        // Parse for animations
{
    switch(Data->Type)
    {
        case DxAnimKey:
        {

            BYTE *AnimData;
            SIZE_T DataSize = 0;

            // Lock the data
            Data->Data->Lock(&DataSize, (const VOID**) &AnimData);

            // Check key type
            if(((DWORD*)AnimData)[0] != 4)
            {
                MessageBox("Only matrix keyframes are supported");
                exit(1);
            }

            // Get number of keys
            ULONG num_keys = ((DWORD*)AnimData)[1];

            // Move passed key-type + key-count
            AnimData += sizeof(DWORD) * 2;

            // Get Bone Index, then create anim
            INT bi = GetBoneIndex(Data->Name);

            // Allocate
            Bones[bi].Name = Data->Name;
            Bones[bi].nKeys = num_keys;
            Bones[bi].Keys = new D3DXMATRIX[ num_keys ];
            Bones[bi].Time = new FLOAT[ num_keys ];

            // Set all keys
            KDxFileMatKey *FileKey = (KDxFileMatKey*) AnimData;
            for(ULONG m=0; m<num_keys; m++)
            {
                // Key properties
                Bones[bi].Keys[m] = FileKey->Matrix;
                Bones[bi].Time[m] = FLOAT( FileKey->Time );

                // Check total time
                if(Time < Bones[bi].Time[m])
                    Time = Bones[bi].Time[m];

                // Next key
                FileKey++;
            }

            // Unlock
            Data->Data->Unlock();


        } break;
    }

    // Parse Children
    KDxDataPak *pk = Data->FP;
    while(pk)
    {
        ParseData(pk);
        pk = pk->R;
    }
}



I know the file-reading offset locations are correct, because all of the time and key-count values are accurate. The matrices are just totally #%$&ed. Oh, here's another strange thing I've noticed. Have any of you ever realized how totally deranged the hierarchy structure of these damn meshes are? Here is Tiny's hierarchy in bracket form. Can anyone tell me why the arms are children of the neck (instead of the upper spine)? Or why the legs are children of the spine (instead of the pelvis)? Does this make sense to anyone? The legs are connected to the pelvis; physically connected. Yet they are children of the spine, which is connected to the opposite end of the pelvis. This is not related to my above problem, as I've tried manually swapping these in the hierarchy.
Bip01_Pelvis
{
    Bip01_Spine
    {
        Bip01_Spine1
        {
            Bip01_Spine2
            {
                Bip01_Spine3
                {
                    Bip01_Neck
                    {
                        Bip01_Head
                        Bip01_L_Clavicle
                        {
                            Bip01_L_UpperArm
                            {
                                Bip01_L_Forearm
                                {
                                    Bip01_L_Hand
                                    {
                                        Bip01_L_Finger0
                                        {
                                            Bip01_L_Finger01
                                            {
                                                Bip01_L_Finger02
                                            }
                                        }
                                        Bip01_L_Finger1
                                        {
                                            Bip01_L_Finger11
                                            {
                                                Bip01_L_Finger12
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        Bip01_R_Clavicle
                        {
                            Bip01_R_UpperArm
                            {
                                Bip01_R_Forearm
                                {
                                    Bip01_R_Hand
                                    {
                                        Bip01_R_Finger0
                                        {
                                            Bip01_R_Finger01
                                            {
                                                Bip01_R_Finger02
                                            }
                                        }
                                        Bip01_R_Finger1
                                        {
                                            Bip01_R_Finger11
                                            {
                                                Bip01_R_Finger12
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        Bip01_L_Thigh
        {
            Bip01_L_Calf
            {
                Bip01_L_Foot
                {
                    Bip01_L_Toe0
                }
            }
        }
        Bip01_R_Thigh
        {
            Bip01_R_Calf
            {
                Bip01_R_Foot
                {
                    Bip01_R_Toe0
                }
            }
        }
    }
}
I'm almost willing to sell a part of my soul for help, but I'm gonna hold off on that for a while. You'll still have my undying respect and appreciation [smile] [Edited by - Jiia on September 13, 2004 1:34:39 AM]

Share this post


Link to post
Share on other sites
I need to add a few things here. This is the text line directly from the Ascii version .x file of the above hip matrix:


// Exactly as in the .x file..

0;16;0.000000,1.000000,-0.000001,0.000000,-0.000001,0.000001,1.000000,0.000000,1.000000,0.000000,0.000001,0.000000,-0.720993,0.000000,-0.000000,1.000000;;

// In column format..

0;16;
0.000000, 1.000000, -0.000001, 0.000000,
-0.000001, 0.000001, 1.000000, 0.000000,
1.000000, 0.000000, 0.000001, 0.000000,
-0.720993, 0.000000, -0.000000, 1.000000;;



This is the first key frame of the pelvis bone, directly from the Tiny.x file in the DirectX 9c SDK.


// Exactly as in the .x file..

-0.000000,0.003123,0.999995,0.000000,1.000000,0.000001,0.000000,0.000000,-0.000001,0.999995,-0.003123,0.000000,-2.498093,-1.716894,0.000001,1.000000;;

// In column format..

-0.000000, 0.003123, 0.999995, 0.000000,
1.000000, 0.000001, 0.000000, 0.000000,
-0.000001, 0.999995, -0.003123, 0.000000,
-2.498093, -1.716894, 0.000001, 1.000000;;


Tiny is animating, but her hip is rotating very little. Not enough to account for the X = Z in that above matrix, top row. How do I need to modify these keys to make them make sense?

Help is very appreciated. Thanks again [sad]

Share this post


Link to post
Share on other sites

This topic is 4838 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this