Conitec 3d gamestudio-source development 用户手册

下载
页码 21
3D Gamestudio Programmer's Manual
                        
© Conitec July 2002
                       15
The MDL5 model format
Despite the engine uses model files with .MDL extension, it's internal MDL5 format differs
from the Quake .MDL format. A wireframe mesh, made of triangles, gives the general shape of
a model. 3D vertices define the position of triangles. For each triangle in the wireframe, there
will be a corresponding triangle cut from the skin picture. Or, in other words, for each 3D
vertex of a triangle that describes a XYZ position, there will be a corresponding 2D vertex
positioned that describes a UV position on the skin picture.
It is not necessary that the triangle in 3D space and the triangle on the skin have the same shape
(in fact, it is normally not possible for all triangles), but they should have shapes roughly
similar, to limit distortion and aliasing. Several animation frames of a model are just several
sets of 3D vertex positions. The 2D vertex positions always remain the same.
A MDL file contains:
- A list of skin textures in 8-bit palettized, 16-bit 565 RGB or 16 bit 4444 ARGB format. 
- A list of skin vertices, that are just the UV position of vertices on the skin texture. 
- A list of triangles, which describe the general shape of the model. 
- A list of animation frames. Each frame holds a list of 3D vertices. 
- A list of bone vertices, which are used for creating the animation frames.
MDL file header
Once the file header is read, all the other model parts can be found just by calculating their
position in the file. Here is the format of the .MDL file header: 
typedef float vec3[3];
typedef struct { 
  char version[4];   // "MDL3", "MDL4", or "MDL5"
  long unused1;      // not used 
  vec3 scale;        // 3D position scale factors.
  vec3 offset;       // 3D position offset.
  long unused2;      // not used 
  vec3 unused3;      // not used
  long numskins ;    // number of skin textures
  long skinwidth;    // width of skin texture, for MDL3 and MDL4;
  long skinheight;   // height of skin texture, for MDL3 and MDL4;
  long numverts;     // number of 3d wireframe vertices
  long numtris;      // number of triangles surfaces
  long numframes;    // number of frames
  long numskinverts; // number of 2D skin vertices
  long flags;        // always 0
  long numbones;     // number of bone vertices (not used yet)
} mdl_header;
The size of this header is 0x54 bytes (84).
The MDL3 format is used by the A4 engine, while the newer MDL4 and MDL5 formats are
used by the A5 engine, the latter supporting mipmaps. After the file header follow the skins,
the skin vertices, the triangles, the frames, and finally the bones (in future versions).