DirectX File Cube Example
This section describes a simple cube and then shows how to add textures, frames, and animations to it.
A Simple Cube
This file defines a simple cube that has four red sides and two green sides. Notice in this file that optional information is being used to add information to the data object defined by the Mesh template.
Material RedMaterial { 1.000000;0.000000;0.000000;1.000000;; // R = 1.0, G = 0.0, B = 0.0 0.000000; 0.000000;0.000000;0.000000;; 0.000000;0.000000;0.000000;; } Material GreenMaterial { 0.000000;1.000000;0.000000;1.000000;; // R = 0.0, G = 1.0, B = 0.0 0.000000; 0.000000;0.000000;0.000000;; 0.000000;0.000000;0.000000;; } // Define a mesh with 8 vertices and 12 faces (triangles). Use // optional data objects in the mesh to specify materials, normals, // and texture coordinates. Mesh CubeMesh { 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;; // All required data has been defined. Now define optional data // using the hierarchical nature of the file format. MeshMaterialList { 2; // Number of materials used 12; // A material for each face 0, // face 0 uses the first 0, // material 0, 0, 0, 0, 0, 0, 1, // face 8 uses the second 1, // material 1, 1;; {RedMaterial} // References to the definitions {GreenMaterial} // of material 0 and 1 } MeshNormals { 8; // define 8 normals 0.333333;0.666667;-0.666667;, -0.816497;0.408248;-0.408248;, -0.333333;0.666667;0.666667;, 0.816497;0.408248;0.408248;, 0.666667;-0.666667;-0.333333;, -0.408248;-0.408248;-0.816497;, -0.666667;-0.666667;0.333333;, 0.408248;-0.408248;0.816497;; 12; // For the 12 faces, 3;0,1,2;, // define the normals 3;0,2,3;, 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;; } MeshTextureCoords { 8; // Define texture coords 0.000000;1.000000; // for each of the vertices 1.000000;1.000000; 0.000000;1.000000; 1.000000;1.000000; 0.000000;0.000000; 1.000000;0.000000; 0.000000;0.000000; 1.000000;0.000000;; } }Adding Textures
To add textures, use the hierarchical nature of the file format and add an optional TextureFilename data object to the Material data objects. So, the Material objects now read as follows:
Material RedMaterial { 1.000000;0.000000;0.000000;1.000000;; // R = 1.0, G = 0.0, B = 0.0 0.000000; 0.000000;0.000000;0.000000;; 0.000000;0.000000;0.000000;; TextureFilename { "tex1.ppm"; } } Material GreenMaterial { 0.000000;1.000000;0.000000;1.000000;; // R = 0.0, G = 1.0, B = 0.0 0.000000; 0.000000;0.000000;0.000000;; 0.000000;0.000000;0.000000;; TextureFilename { "win95.ppm"; } }Frames and Animations
This section shows how to add frames and animations to a simple cube.
Frames
A frame is expected to take the following structure:
Frame Aframe { // The frame name is chosen for convenience. FrameTransformMatrix { ...transform data... } [ Meshes ] and/or [ More frames] }Place the previously defined cube mesh inside a frame with an identity transform. Then apply an animation to this frame.
Frame CubeFrame { 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;; } {CubeMesh} // You could have the mesh inline, but this // uses an object reference instead. }AnimationSets and Animations
Animations and AnimationSets in the DirectX file format map directly to the Direct3D Retained Mode animation concepts.
Animation Animation0 { // The name is chosen for convenience. { Frame that it applies to&em;normally a reference } AnimationKey { ...animation key data... } { ...more animation keys... } }Animations are then grouped into AnimationSets: AnimationSet AnimationSet0 { // The name is chosen for convenience. { an animationcould be inline or a reference } { ... more animations ... } }
Now take the cube through an animation.
AnimationSet AnimationSet0 { Animation Animation0 { {CubeFrame} // Use the frame containing the cube 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;;; } } }
Top of Page
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.