Conitec 3d gamestudio-source development User Manual

Page of 21
3D Gamestudio Programmer's Manual
                        
© Conitec July 2002
                       20
The HMP5 terrain format
A terrain is basically a rectangular mesh of height values with one or several surface textures. It
is a simplified version of the GameStudio Model format, without all the data structures that are
unnecessary for terrain.
HMP file header
Once the file header is read, all the other terrain parts can be found just by calculating their
position in the file. Here is the format of the .HMP file header: 
typedef float vec3[3];
typedef struct { 
  char version[4];   // "HMP4" or "HMP5"; only the newer HMP5 format is described here
  long nu1,nu2,nu3;  // not used 
  float scale_z;     // height scale factor.
  float nu4,nu5;  
// not used 
  float offset_z;    // height offset.
  long nu6; 
// not used
  float ftrisize_x; // triangle X size 
  float ftrisize_y; // triangle Y size 
  float fnumverts_x; // number of mesh coordinates in X direction
  long numskins ;    // number of textures
  long nu8,nu9;
// not used
  long numverts;     // total number of mesh coordinates
  long nu10;      
// not used
  long numframes;    // number of frames
  long nu11;      
// not used
  long flags;        // always 0
  long nu12;     
// not used
} hmp_header;
The size of this header is 0x54 bytes (84).
The "HMP4" format is used by the A5 engine prior to 5.230, while the new "HMP5" format is
used by the A5 engine since version 5.230. The number of vertices in the rectangular mesh can
be determined by
int numverts_x = (int) fnumverts_x;
int numverts_y = numverts/numverts_x;
After the file header follow the textures and then the array of height values.
HMP texture format
The terrain surface textures are flat pictures. There can be more than one texture. By default, the
first texture is the terrain skin, and the second texture is the detail map. Further textures are not
used yet. You will find the first texture just after the model header, at offset
baseskin = 0x54
.
There are
numskins
textures to read. Each of these textures is in 16-bit 565 format (
type == 2
)
or 16-bit 4444 format (
type == 3
). If the texture contains mipmaps,
8
is added to the
type
. In
that case the 3 additional mipmap images follow immediately after the texture image. Detail
textures must always contain mipmaps. The texture width and height must be divisible by 8.
typedef word unsigned short;
typedef struct { 
  long skintype;     // 2 for 565 RGB, 3 for 4444 ARGB, 10 for 565 RGB with 3 mipmaps
  long width,height; // size of the texture
  word skin[skinwidth*skinheight]; 
// the texture image