A simple x-file example: a plane has 4 vertices ( You can save it as a .x file or download the example file: DeclData_Plane1_2011.zip );
each vertex has these elements: position, normal, texcoord, then the layout is:
xof 0303txt 0032 Frame Plane1 { FrameTransformMatrix { 1.0, 0, 0, 0, 0, 0, -1.0, 0, 0, 1.0, 0, 0, 0, 0, 0, 1.0;; } Mesh Plane1 { 4; -100.0; 0; 100.0;, 100.0; 0; 100.0;, -100.0; 0; -100.0;, 100.0; 0; -100.0;; 2; 3;0,1,2;, 3;3,2,1;; MeshMaterialList { 1; 2; 0, 0; Material { 0.1; 0.2; 0.5; 1.0;; 0.0; 0.0; 0.0; 0.0;; 0.0; 0.0; 0.0;; } } DeclData { 2; // nElements == 2 2;0;3;0;, // type == 2 (Float3); usage == 3 (Normal) 1;0;5;0;; // type == 1 (Float2); usage == 5 (Texcoord) 20; // nDWords == 20; Normal and Texcoord use 5 DWORDs, so 4 * 5 = 20 0, // normal0.x == 0 1065353216, // normal0.y == 1.0 0, // normal0.z == 0 0, // tex0.x == 0 0, // tex0.y == 0 0, // normal1.x == 0 1065353216, // normal1.y == 1.0 0, // normal1.y == 0 1065353216, // tex1.x == 1.0 0, // tex1.y == 0 0, // normal2.x == 0 1065353216, // normal2.y == 1.0 0, // normal2.z == 0 0, // tex2.x == 0 1065353216, // tex2.y == 1 0, // normal3.x == 0 1065353216, // normal3.y == 1.0 0, // normal3.z == 0 1065353216, // tex3.x == 1.0 1065353216; // tex3.y == 1.0 } } }
The reason of using DWORD (unsigned int) in X file is because it has no precision problem with floats.
You can use the following code to convert DWORD to float:
DWORD d = 1065353216; // suppose you have load a DWORD from DeclData in x-file float f = *(float*)&d; // convert it back to float printf("%f", f); // should be 1.0
Leave a Reply