Conitec 3d gamestudio a4 programmer 手册
A4 Programmer’s Manual © Conitec 2000 11
MDL skin format
The model skins are flat pictures that represent the texture that should be applied on the model.
There can be more than one skin. You will find the first skin just after the model header, at offset
MDL skin format
The model skins are flat pictures that represent the texture that should be applied on the model.
There can be more than one skin. You will find the first skin just after the model header, at offset
baseskin = 0x54
. There are
numskins
skins to read. Each of these model skins is either in 8-bit palettized
(
type
== 0) or in 16-bit 5-6-5 format (
type
== 2). The structure is:
typedef byte unsigned char;
typedef struct {
int skintype; // 0 for 8 bit (bpp == 1), 2 for 16 bit (bpp == 2)
byte skin[skinwidth*skinheight*bpp]; // the skin picture
} mdl_skin_t;
typedef struct {
int skintype; // 0 for 8 bit (bpp == 1), 2 for 16 bit (bpp == 2)
byte skin[skinwidth*skinheight*bpp]; // the skin picture
} mdl_skin_t;
8 bit skins are a table of bytes, which represent an index in the level palette. If the model is rendered
in overlay mode, index 0x00 indicates transparency. 16 bit skins are a table of shorts, which
represent a true colour with the upper 5 bits for the red, the middle 6 bits for the green, and the
lower 5 bits for the blue component. Green has one bit more because the human eye is more
sensitive to green than to other colours. If the model is rendered in overlay mode, colour value
0x0000 indicates transparency.
The width of skins should be a multiple of 4, to ensure long word alignement. The skin pictures are
usually made of as many pieces as there are independent parts in the model. For instance, for the a
player, there may be two pieces that defines the body, and two others that define the gun.
MDL skin vertices
The list of skin vertices indicates only the position on texture picture, not the 3D position. That's
because for a given vertex, the position on skin is constant, while the position in 3D space varies
with the animation. The list of skin vertices is made of these structures:
typedef struct
{
short u; // position, horizontally in range 0..skinwidth-1
short v; // position, vertically in range 0..skinheight-1
} mdl_uvvert_t;
mdl_uvvert_t skinverts[numskinverts];
{
short u; // position, horizontally in range 0..skinwidth-1
short v; // position, vertically in range 0..skinheight-1
} mdl_uvvert_t;
mdl_uvvert_t skinverts[numskinverts];
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,
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];
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];