Skip to content
Asp Adm (Alexey Kirillov) edited this page Jan 6, 2019 · 6 revisions

На русском

Format: SEC

Description

Map chunk (section)

Visualization

sec structure png image

Structure

File contain one header:

struct header
{
    uint magic; // 74 F7 4B CF

    byte liquids;
};

After header lay data arrays:

struct vertex
{
    signed byte x_offset;
    signed byte y_offset;
    ushort altitude; // z coord

    uint packed_normal;
};

struct vertex land_vertex_array[33][33];

If liquids != 0 there are additional vertex table:

struct vertex liquids_vertex_array[33][33];

After that lay texture information:

ushort land_textures[16][16];

If liquids != 0 there are additional textures table:

ushort liquids_textures[16][16];

After that if liquids != 0:

ushort liquids_tile_material_index[16][16];

Materials are declared in MP file.
If material index == 65535, tile not textured.

Additional information

Normal unpacking

10 bits for z, 11 for x and y

uint packed_normal;

float x = ((float)((packed_normal >> 11) & 0x7FF) - 1000.0f) / 1000.0f;
float y = ((float)(packed_normal & 0x7FF) - 1000.0f) / 1000.0f;
float z = (float)(packed_normal >> 22) / 1000.0f;

Texture information

6 bits for tile index, 8 for texture number, 2 for rotation

ushort texture;

byte tile_index = f & 63;
byte texture_index = (f >> 6) & 255;
byte rotation = (f >> 14) & 3;

Getting landscape

Vertices are stored as 33 elements in each of 33 rows, i.e. forms 32x32 cells. Length of cell by side is 1 meter.
Vertex position:
x = x_index + x_offset / 254
y = y_index + y_offset / 254
z = altitude / 65535 * max_altitude (from .mp file)

Vertices are joined in polygons with saw-like pattern; 4 vertices forms 2 triangle polygons:

 0   1 2
   *-*-*
   |\|\| ~
33 *-*-*
   |\|\| ~
66 *-*-*
    ~ ~  ~

Texture lay on 4 cells, i.e. 16x16 tiles on map. Length of tile by side - 2 meters. Tile can be rotated by 0, 90, 180 or 270 degrees.

Clone this wiki locally