Conitec 3d gamestudio-source development Manuel D’Utilisation

Page de 21
3D Gamestudio Programmer's Manual
                        
© Conitec July 2002
                       16
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
), in 16-bit 565 format (
type == 2
) or 16-bit 4444 format (
type ==
3
). The skin structure in the MDL3 and MDL4 format is: 
typedef byte unsigned char;
typedef struct { 
  int skintype;    // 0 for 8 bit (bpp == 1), 2 for 565 RGB, 3 for 4444 ARGB (bpp == 2) 
  byte skin[skinwidth*skinheight*bpp]; // the skin picture
} mdl_skin_t;
In the MDL5 format the skin is a little different, because now mipmaps can be stored and the
model skins have not necessarily the same size. If the skin contains mipmaps,
8
is added to the
skintype
. In that case the 3 additional mipmap images follow immediately after the skin
image. The texture width and height must be divisible by 8. 8 bit skins are not possible
anymore in combination with mipmaps.
typedef word unsigned short;
typedef struct { 
  long skintype;     // 2 for 565 RGB, 3 for 4444 ARGB, 10 for 565 mipmapped
11 for 444 mipmapped
  long width,height; // size of the texture
  word skin[skinwidth*skinheight]; 
// the texture image
  word skin1[skinwidth/2*skinheight/2];
// the 1st mipmap (if any)
  word skin2[skinwidth/4*skinheight/4];
// the 2nd mipmap (if any)
  word skin3[skinwidth/8*skinheight/8];
// the 3rd mipmap (if any)
} mdl5_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 in
565
format are a
table of unsigned 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. 16 bit alpha channel skins in
4444
format are represented as a table of unsigned shorts with 4 bits for each of the alpha, red, green,
and blue component.
The width and heights of skins should be a multiple of 4, to ensure long word alignement.
When using mipmaps, they must be a multiple of 8. 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];