.THM in IGI 2 -- Terrain Heightmap Metadata

1. Architectural Role & Engine Purpose

The THM (Terrain Heightmap & Geomorphing File) format stores multi-resolution terrain quadtrees, bounding box hierarchies, and crack-free geomorphing morph weights in I.G.I. 2: Covert Strike.

In IGI 2, terrain rendering was redesigned to eliminate noticeable LOD "popping". The THM file provides precomputed quadtree metadata and morphing factors, allowing vertices between adjacent quadtree nodes to transition smoothly in height without visible seams or cracks.

2. Binary File Layout & Memory Map Diagram

A THM file contains quadtree dimensions, node bounding boxes, and geomorphing interpolation coefficients:

IGI 2 THM TERRAIN — QUADTREE GEOMORPHING METADATA LAYOUT 0x00: Terrain Quadtree Header (24 Bytes) THM METADATA Magic "THM " | Version | Quadtree Depth (e.g. 5) | Tile Count | Min/Max Valley Elevations magic[4], version, quadtree_depth, tile_count, min_height, max_height Quadtree Node Spatial Bounding Records (32 Bytes per Tile) 32B TILE NODE Bounding Center XYZ (float[3]) | Bounding Extents XYZ (float[3]) | Screen Error Metric (float) | Child Indices (uint16[4]) Precomputed hierarchical spatial bounding boxes stored in heightmaps.res Crack-Free Geomorphing Morph Tables GEOMORPHING Continuous interpolation weights blending adjacent terrain LOD levels smoothly Completely eliminates terrain popping without T-junction cracking

3. Crack-Free Geomorphing Terrain Pipeline Diagram

During the terrain render loop, geomorphing morph weights smoothly blend adjacent LOD levels:

IGI 2 THM — CRACK-FREE GEOMORPHING TERRAIN PIPELINE 1. SCREEN ERROR • Camera Advances Forward • Error = (Size / Distance) • Compare vs Threshold 2. MORPH WEIGHT • Continuous Factor • Alpha = (Dist - D0)/(D1-D0) • Alpha between 0.0 & 1.0 3. HEIGHT LERP • Vertex Height Morph • Lerp(Detailed, Coarse, A) • Smooth Elevation Blend 4. ZERO POPPING • Zero T-Junctions • Continuous Horizon • DirectX 8 Hardware

4. C++ Struct Definitions

#pragma pack(push, 1)
struct ThmHeader {
    char     magic[4];       // "THM "
    uint32_t version;        // 2
    uint32_t quadtree_depth; // Quadtree levels (e.g. 5)
    uint32_t tile_count;     // Number of quadtree nodes
    float    min_height;     // Valley minimum
    float    max_height;     // Mountain peak
};
static_assert(sizeof(ThmHeader) == 24, "ThmHeader must be 24 bytes");
#pragma pack(pop)