www.xbdev.net
xbdev - software development
Thursday March 28, 2024
home | contact | Support | 3D File Formats The bits and bytes...

Prt-3- .x File Format with Animation

 

 

Wwaaahoooo.....finally something cool.... animation....

Always makes me feel proud when I get something to animate...3D model character running around in my 3D world....as you can load Mesh's from your .x file, but when you want them to animate you have to master the Animation part of the .x file format.

 

Well as I think I'll do, I'll show you the formal definition of the Animation parts of the templates used:

 

Animation Animation0 {        // The name is chosen for convenience.
    { Frame that it applies to....;normally a reference } // so for example we could have {CubeFrameA} here
    AnimationKey {
    ...animation key data...
    }
   { ...more animation keys... }
}

 

 

 

Animations are then grouped into AnimationSets:

 

AnimationSet AnimationSet0 { // The name is chosen for convenience.

{ an animation—could be inline or a reference }

    { ... more animations ... }

}

 

We use AnimationSet's as we can do a "Walk" animation, a "Jump" animation set, which will be made up of loads of smaller animations...such as arm movement, leg movement etc

 

An example would be:

 

AnimationSet Walk {

      Animation {

            {Bip01}

            AnimationKey {

            ..

            }

      }

 

      Animation {

            {Bip01_Pelvis}

            AnimationKey {

                  ...

            }

      }

}

 

 

 

Well lets have a go at creating our CubeAnimation.x File....we'll have to mesh's...CubeA and CubeB...and CubeA will be the parent...and we'll make CubeB a child.......now for animation...we'll just have cubeA spin.

 

AnimationKey, the keyType member specifies whether the keys are rotation, scale or position keys (using the integers 0, 1, or 2 respectively).

 

 

xof 0303txt 0032

 

Header {

 1;

 0;

 1;

}

 

// use comments to seperate out the parts-------------

 

Mesh CubeA {

8;                                // 8 vertices

1.000000;1.000000;-1.000000;,     // vertex 0

-1.000000;1.000000;-1.000000;,    // vertex 1

-1.000000;1.000000;1.000000;,     // etc...

1.000000;1.000000;1.000000;,

1.000000;-1.000000;-1.000000;,

-1.000000;-1.000000;-1.000000;,

-1.000000;-1.000000;1.000000;,

1.000000;-1.000000;1.000000;;

 

12;                      // 12 faces

3;0,1,2;,                // face 0 has 3 vertices

3;0,2,3;,                // etc...

3;0,4,5;,

3;0,5,1;,

3;1,5,6;,

3;1,6,2;,

3;2,6,7;,

3;2,7,3;,

3;3,7,4;,

3;3,4,0;,

3;4,7,6;,

3;4,6,5;;               

}

 

//-----------------------------------------------------

 

Mesh CubeB {

8;                                // 8 vertices

1.000000;1.000000;-1.000000;,     // vertex 0

-1.000000;1.000000;-1.000000;,    // vertex 1

-1.000000;1.000000;1.000000;,     // etc...

1.000000;1.000000;1.000000;,

1.000000;-1.000000;-1.000000;,

-1.000000;-1.000000;-1.000000;,

-1.000000;-1.000000;1.000000;,

1.000000;-1.000000;1.000000;;

 

12;                      // 12 faces

3;0,1,2;,                // face 0 has 3 vertices

3;0,2,3;,                // etc...

3;0,4,5;,

3;0,5,1;,

3;1,5,6;,

3;1,6,2;,

3;2,6,7;,

3;2,7,3;,

3;3,7,4;,

3;3,4,0;,

3;4,7,6;,

3;4,6,5;;

}

 

//-----------------------------------------------------

//Bone structure stuff is here-------------------------

 

Frame CubeFrameA {

FrameTransformMatrix {

1.000000, 0.000000, 0.000000, 0.000000,

0.000000, 1.000000, 0.000000, 0.000000,

0.000000, 0.000000, 1.000000, 0.000000,

0.000000, 0.000000, 0.000000, 1.000000;;

}

    Frame CubeFrameB{

    FrameTransformMatrix {

    1.000000, 0.000000, 0.000000, 0.000000,

    0.000000, 1.000000, 0.000000, 0.000000,

    0.000000, 0.000000, 1.000000, 0.000000,

    0.000000, 0.000000, 0.000000, 1.000000;;

    }

    {CubeB}

    }

{CubeA}

}

 

//-----------------------------------------------------

//Our animation templates------------------------------

 

AnimationSet Spin { // our animation will be called spin

      Animation {

            {CubeFrameA}

            AnimationKey {

            2;             // Position keys

            9;             // 9 keys

            10; 3; -100.000000, 0.000000, 0.000000;;,

            20; 3; -75.000000, 0.000000, 0.000000;;,

            30; 3; -50.000000, 0.000000, 0.000000;;,

            40; 3; -25.500000, 0.000000, 0.000000;;,

            50; 3; 0.000000, 0.000000, 0.000000;;,

            60; 3; 25.500000, 0.000000, 0.000000;;,

            70; 3; 50.000000, 0.000000, 0.000000;;,

            80; 3; 75.500000, 0.000000, 0.000000;;,

            90; 3; 100.000000, 0.000000, 0.000000;;;

            }

 

      }

 

      Animation {

            {CubeFrameB}

            AnimationKey {

            2;             // Position keys

            9;             // 9 keys

            10; 3; -100.000000, 0.000000, 0.000000;;,

            20; 3; -75.000000, 0.000000, 0.000000;;,

            30; 3; -50.000000, 0.000000, 0.000000;;,

            40; 3; -25.500000, 0.000000, 0.000000;;,

            50; 3; 0.000000, 0.000000, 0.000000;;,

            60; 3; 25.500000, 0.000000, 0.000000;;,

            70; 3; 50.000000, 0.000000, 0.000000;;,

            80; 3; 75.500000, 0.000000, 0.000000;;,

            90; 3; 100.000000, 0.000000, 0.000000;;;

            }

      }

}

 

 

 

 

A word of the wiser....as I've show above...you don't have to put it inline...you can use a reference {CubeB} for example...but I would recommend putting your meshes inline.

 

As show:

 

 

 

xof 0303txt 0032

 

Header {

 1;

 0;

 1;

}

 

 

//-----------------------------------------------------

//Bone structure stuff is here-------------------------

 

Frame CubeFrameA {

FrameTransformMatrix {

1.000000, 0.000000, 0.000000, 0.000000,

0.000000, 1.000000, 0.000000, 0.000000,

0.000000, 0.000000, 1.000000, 0.000000,

0.000000, 0.000000, 0.000000, 1.000000;;

}

    Frame CubeFrameB{

    FrameTransformMatrix {

    1.000000, 0.000000, 0.000000, 0.000000,

    0.000000, 1.000000, 0.000000, 0.000000,

    0.000000, 0.000000, 1.000000, 0.000000,

    0.000000, 0.000000, 0.000000, 1.000000;;

    }

     Mesh CubeB {

     8;                                // 8 vertices

     1.000000;1.000000;-1.000000;,     // vertex 0

    -1.000000;1.000000;-1.000000;,    // vertex 1

    -1.000000;1.000000;1.000000;,     // etc...

    1.000000;1.000000;1.000000;,

    1.000000;-1.000000;-1.000000;,

    -1.000000;-1.000000;-1.000000;,

    -1.000000;-1.000000;1.000000;,

    1.000000;-1.000000;1.000000;;

 

    12;                      // 12 faces

    3;0,1,2;,                // face 0 has 3 vertices

    3;0,2,3;,                // etc...

    3;0,4,5;,

    3;0,5,1;,

    3;1,5,6;,

    3;1,6,2;,

    3;2,6,7;,

    3;2,7,3;,

    3;3,7,4;,

    3;3,4,0;,

    3;4,7,6;,

    3;4,6,5;;

    }

    }

Mesh CubeA {

8;                                // 8 vertices

1.000000;1.000000;-1.000000;,     // vertex 0

-1.000000;1.000000;-1.000000;,    // vertex 1

-1.000000;1.000000;1.000000;,     // etc...

1.000000;1.000000;1.000000;,

1.000000;-1.000000;-1.000000;,

-1.000000;-1.000000;-1.000000;,

-1.000000;-1.000000;1.000000;,

1.000000;-1.000000;1.000000;;

 

12;                      // 12 faces

3;0,1,2;,                // face 0 has 3 vertices

3;0,2,3;,                // etc...

3;0,4,5;,

3;0,5,1;,

3;1,5,6;,

3;1,6,2;,

3;2,6,7;,

3;2,7,3;,

3;3,7,4;,

3;3,4,0;,

3;4,7,6;,

3;4,6,5;;               

}

}

 

//-----------------------------------------------------

//Our animation templates------------------------------

 

AnimationSet Spin { // our animation will be called spin

      Animation {

            {CubeFrameA}

            AnimationKey {

            2;             // Position keys

            9;             // 9 keys

            10; 3; -10.000000, 0.000000, 0.000000;;,

            20; 3; -75.000000, 0.000000, 0.000000;;,

            30; 3; -50.000000, 0.000000, 0.000000;;,

            40; 3; -25.500000, 0.000000, 0.000000;;,

            50; 3; 0.000000, 0.000000, 0.000000;;,

            60; 3; 25.500000, 0.000000, 0.000000;;,

            70; 3; 50.000000, 0.000000, 0.000000;;,

            80; 3; 75.500000, 0.000000, 0.000000;;,

            90; 3; 100.000000, 0.000000, 0.000000;;;

            }

 

      }

 

      Animation {

            {CubeFrameB}

            AnimationKey {

            2;             // Position keys

            9;             // 9 keys

            10; 3; -10.000000, 0.000000, 0.000000;;,

            20; 3; -75.000000, 0.000000, 0.000000;;,

            30; 3; -50.000000, 0.000000, 0.000000;;,

            40; 3; -25.500000, 0.000000, 0.000000;;,

            50; 3; 0.000000, 0.000000, 0.000000;;,

            60; 3; 25.500000, 0.000000, 0.000000;;,

            70; 3; 50.000000, 0.000000, 0.000000;;,

            80; 3; 75.500000, 0.000000, 0.000000;;,

            90; 3; 100.000000, 0.000000, 0.000000;;;

            }

      }

}

 

 

 

I hope all this knowledge is sinking in.....

 

Now I think its best to refresh on the main parts...as there's a hell of a lot of stuff in a .x 3D file....and to digest it all in one go is a big thing...don't want you choking on it..heheh

 

 

***1*** Head of our monster .x file

xof 0303txt 0032

Header {
1;
0;
1;
}
 

 

 

***2*** Our two main parts!..the meat of it all is contained in these two

 

Frame CubeFrameA

{

 

}

// multiple Frames...

 

AnimationSet Spin

{

 

}

// multiple AnimationSets

 

 

Those our the meat and potato's of it....

 

 

 

 

 

 

 

 

 

 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2024 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.