MAT Files


MAT Files General

MAT files contain image information .This could be solid colors or textures, there could be several textures or colors in one file. The textures are of the mip-map type.That is one larger texture with several more smaller ones each with less detail. These are used to change the detail of the textures shown to the player by the engine.

This is a function of distance as specified in the JKL Section: Header /Mipmap Distances.

The file is structured in 2 parts if the MAT is a color one, or 3 parts, if it is a texture one.

Color = Solid color value

File structure:
{Color MAT}
MATHeader
ColorHeaders

{Texture MAT}
MATHeader
TextureHeaders
TextureDatas

The header for an Mat file is:

Mat:

TMatHeader = record
array[0..3] of char;     {'MAT ' - notice space after MAT}
ver:Longint;             {Apparently - version = 0x32 ('2')}
Type:Longint;            {0 = colors(TColorHeader) , 1= ?, 2= texture(TTextureHeader)}
NumOfTextures:Longint;   {number of textures or colors}
NumOfTextures1: Longint; { In color MATs, it's 0, in TX ones, it's equal to numOfTextures }
Longint;                 { = 0 }
LongInt;                 { = 8 }
array[0..11]of longint;  {unknown. Some pad?}
end;


Depending on the Type in TMatHeader there will be either NumOfTextures*TColorHeader or NumOfTextures * TTextureHeader

COLOR MAT:

TColorHeader = record
textype:longint;         {0 = color, 8= texture}
colornum:longint;        {Color index from the CMP palette}
array[0..3]of Longint;   {each = 0x3F800000 (check cmp header )}
end;

The TColorHeader is repeated NumOfTextures times.

TEXTURE MAT:

TTextureHeader = record
textype:longint;         {0 = color, 8= texture}
colornum:longint;        {unknown use}
array[0..3]of Longint;   {each longint = 0x3F800000 (check cmp header )}
array[0..1]of Longint;   {unknown}
Longint;                 {=0xBFF78482}
CurrentTXNum:Longint     {number of corresponding texture, beginning with 0, ranging to NumOfTextures-1}
end;


The TTextureHeaders are followed by NumOfTextures * the mipmap information(incl. actual textures).


TTextureData = record
SizeX:Longint;             {horizontal size of first MipMap, must be divisable by 2}
SizeY:Longint;             {Vertical size of first MipMap ,must be divisable by 2}
Pad:array[0..2]of LongInt; {padding = 0 }
NumMipMaps:LongInt;        {Number of mipmaps in texture largest one first.}
end;

The TTextureData is followed by actual texture data. The graphics are uncompressed; the top left corner is the start; lines are read first. The main texture is directly followed by rest MipMaps (whole number is NumMipMaps).