CHEXAUMODULE
Overview
The CHEXAUMODULE is a multi-threaded procedural runtime spawner for repeatable meshes (foliage, trees, rocks, etc.) based on hexagonal or square grid patterns. It generates HierarchicalInstancedStaticMeshComponent instances around the player in real-time, with probabilistic mesh selection, biome filtering, slope filtering, altitude filtering and room-type filtering.
Depends on CCOREUMODULE.
| Functionalities | Overview |
|---|---|
| Data | Configuration structures: FCMeshStruct, FCMeshProbaStruct, FCHexaMakerStruct, FCHexaSpawnerDataStruct |
| CHexaSpawner | Spawner actor that drives generation, tracks a pawn and manages banned areas |
| CHexamaker | Async hexagonal generation engine with ISM management, tile calculation and removal |
| Blueprint | UCHexaBPLibrary (ready for extension, currently empty) |
Architecture
The generation pipeline works as follows:
ACHexaSpawneris placed in the level with a reference to aDataTablerow (FCHexaSpawnerDataStruct) and a pawn to track.- On tick, the spawner delegates to
UCHexamaker::buildASyncwhich computes tile UV coordinates around the pawn asynchronously. - Tiles are calculated in parallel (
ParallelFor) with probabilistic mesh selection and multi-criteria filtering (biome, slope, altitude, room). - Mesh data is queued and processed on the game thread (
updateISM_sync), creatingUHierarchicalInstancedStaticMeshComponentinstances. - Each
FCHexaMakerStructdefines an independent placement layer (e.g. trees, rocks, grass) with its own parameters. - The system supports banned areas (
bannedArea) to exclude regions from placement.
Placement Patterns
The module supports two grid patterns via the HexaPattern enum.
HEXAGONE — Hexagonal grid (flat-top)
Uses the axial coordinate system (q, r) with cube conversion (q, r, s = -q-r). The spawn area around the player forms a hexagon.
Each hexagonal cell is defined by 6 vertices around the center, with size = radius from center to vertex.
Axial-to-pixel conversion: pixel.X = tileSize × (√3 × q + √3/2 × r), pixel.Y = tileSize × 1.5 × r.
The spawn zone is bounded by the cubic condition q² + r² + s² ≤ nbHexaAround², producing a hexagonal shape around the player.
SQUARE — Square grid
Uses a regular grid layout. The spawn area forms a square around the player. Direct conversion: pixel.X = q × tileSize, pixel.Y = r × tileSize.
Placement Variations
Within each cell (hexagonal or square), the module offers several variations controlled by FCHexaMakerStruct:
Jitter (dispersion)
jitterForce randomly offsets the mesh from the cell center, avoiding a too-regular appearance. The offset is computed as a random value between minJitterForce × tileSize and maxJitterForce × tileSize, applied independently on X and Y with a random sign.
Random rotation
If rotate = true, each mesh receives a random Y rotation [0°, 360°].
Random scale
Each mesh receives a uniform random scale between minScalePercent and maxScalePercent.
Align to slope (alignToSlope)
When enabled, mesh rotation is adapted to follow the terrain slope via WorldUtility::bendRotatorOnSlope.
Altitude filter (withBound)
Restricts placement between above and below Z values.
Normal filter (withNormal)
Restricts placement based on terrain slope (zMinNornal → zMaxNornal, 0=vertical, 0.5=45°, 1=horizontal).
Biome selection
The biomeNoise singleton (UCNoisator) provides a noise value per position. Placement is filtered between biomeSelectLowerBound and biomeSelectUpperBound. When both bounds are equal (default 0=0), the filter is disabled.
Room type filter (roomType)
With CROOMUMODULE, placement can be restricted to:
ROOM: inside rooms only (with distance-to-center filtering viameshSelectRateDistanceToRoomLowerBound/UpperBound)CORRIDOR: inside corridors only (with distance-to-edge filtering viameshSelectRateDistanceToEdgeLowerBound/UpperBound)WALL: outside rooms and corridors onlyUNSET: no room filtering (default)