Conitec 3d gamestudio-source development 用户手册

下载
页码 21
3D Gamestudio Programmer's Manual
                        
© Conitec July 2002
                       17
u and v are the pixel position on the skin picture. The skin vertices are stored in a list, that is
stored at offset
basestverts = baseskin + skinsize
.
skinsize
is the sum of the size of all
skin pictures. If they are all 8-bit skins, then
skinsize = (4 + skinwidth * skinheight) *
numskins
. If they are 16-bit skins without mipmaps, then
skinsize =
(4 + skinwidth *
skinheight * 2) * numskins
MDL mesh triangles
The model wireframe mesh is made of a set of triangle facets, with vertices at the boundaries.
Triangles should all be valid triangles, not degenerates (like points or lines). The triangle face
must be pointing to the outside of the model. Only vertex indexes are stored in triangles. Here
is the structure of triangles: 
typedef struct { 
short index_xyz[3]; // Index of 3 3D vertices in range 0..numverts
short index_uv[3];  // Index of 3 skin vertices in range 0..numskinverts
} mdl_triangle_t;
mdl_triangle_t triangles[numtris];
At offset
basetri = baseverts + numskinverts * sizeof(uvvert_t)
in the .MDL file
you will find the triangle list. 
MDL frames
A model contains a set of animation frames, which can be used in relation with the behavior of
the modeled entity, so as to display it in various postures (walking, attacking, spreading its
guts all over the place, etc). Basically the frame contains of vertex positions and normals.
Because models can have ten thousands of vertices and hundreds of animation frames, vertex
posistion are packed, and vertex normals are indicated by an index in a fixed table, to save disk
and memory space. 
Each frame vertex is defined by a 3D position and a normal for each of the 3D vertices in the
model. In the MDL3 format, the vertices are always packed as bytes; in the MDL4 format that is
used by the A5 engine they can also be packed as words (unsigned shorts). Therefore the MDL4
format allows more precise animation of huge models, and inbetweening with less distortion.
typedef struct { 
  byte  rawposition[3];   // X,Y,Z coordinate, packed on 0..255
  byte  lightnormalindex; // index of the vertex normal
} mdl_trivertxb_t;
typedef struct { 
  unsigned short rawposition[3];   // X,Y,Z coordinate, packed on 0..65536
  byte  lightnormalindex; // index of the vertex normal
  byte  unused;
} mdl_trivertxs_t;
To get the real X coordinate from the packed coordinates, multiply the X coordinate by the X
scaling factor, and add the X offset. Both the scaling factor and the offset for all vertices can be
found in the 
mdl_header
 struct. The formula for calculating the real vertex positions is: 
float position[i] = (scale[i] * rawposition[i] ) + offset[i];