I will not be more than the purpose and significance of building your own 3D model file. There are some ways to achieve this, I have used the D3DSDK (2004summer) version to reach this, my methods and ideas are as follows:
1) Read the .x file with D3DX, you need to read the Frame, FrametransMatrix, Mesh, AnimationSet, Animation, AnimationKey;
2) Translate into the documents you need, here I have built 4 files, including .m gear (stores Mesh) ,. F file (storage frame) ,. A file (store animationSet) and .z file, store 3 The index of the file. These four files can modify partial properties to achieve a shared texture, animation, etc.
3) Complete the code of reading these four documents and build a list of corresponding lists, what is tree
4) RENDER reads the model
The .m gear format is as follows (the most complicated is this file):
Mesh number
{// cycle, MESH number
Name
Nummaterials
{// cycle, Nummaterials number
Matd3D
TextureFileName
}
FVF
Numfaces
Numvertices
NumBytespervertex
True / false // Indicates if there is SkinInfo
{
Numbones
{// Numbones
Bonename
NumboneInfluences
Vertices
Weights
BoneoffsetMatrix
}
}
VertexBuffersize
VertexBuffer
IndexBuffersize
Indexbuffer
.F file saved is a binary tree, the file format is not well described, but the Frame's binary tree structure and TransformationMatrix are written.
The file format is as follows:
AnimationSet quantity
{//cycle
Name
Length
ANIMATION quantity
{//cycle
Animation name
TranslationKeys // Each key contains time and conversion Key
ScaleKeys
RotationKeys
MatrixKeys
}
}
The first thing to do is reading .x file, pseudo code as follows:
D3DXFileCreate
Registertemplates (D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES) // variables have declarations in rmxfguid.h
CreateEnumObject If you use Uincode, the second parameter is changed to D3DXF_FileLoad_FromWFile
PD3DXENUM-> GetChildren (& DWData);
For (DWORD DW = 0; DW PD3DXENUM-> GetChild (dw, & pd3dxdata); PARSEOBJECT (PD3DXDATA); } PARSEOBJECT (ID3DXFiledata * pdataobj) { PDataobj-> GetType (& TYPE); IF (Type == frame) { // do something } Else IF (...) {...} } There may be LoadMesh in PARSEObject, this time you don't have to save the texture file name. Don't forget to use the d3dxmeshopt_attrsort parameter after the LOAD is complete. Since the format of the file has been given, the other code is actually the reading and writing of the file, which is not coming. The code of the Render section is not complicated, that is, the DrawIndexedPrimitive function, it is not coming.