A Node.js tool for generating seamlessly connected heightmaps for the fighter jet terrain system.
- 8 Distinct Terrain Types: Mountains, Plains, Canyons, Hills, Valleys, Plateaus, Badlands, Highlands
- Seamless Edge Stitching: Automatically connects adjacent heightmaps without visible seams
- Erosion Simulation: Thermal and hydraulic erosion for realistic terrain features
- Debug Visualization: Generates color-coded preview images for each terrain type
- Configurable Parameters: Adjustable heightmap size, erosion settings, and stitch zones
cd tools/heightmap-generator
npm installnpm run generate# Convert single image
npm run convert terrain.png
# Convert with output directory
npm run convert terrain.png ./output
# Batch convert all images in directory
npm run convert -- --batch ./images ./outputnode generate.js --width 512 --height 512 --output ./custom-output --debug--width <number>: Heightmap width (default: 256)--height <number>: Heightmap height (default: 256)--output <dir>: Output directory (default: ./output)--no-images: Skip generating preview images--stitch-size <number>: Edge stitching size in pixels (default: 32)--debug: Enable debug output
The generator creates:
heightmap_mountains.bin- Raw height data for mountains regionheightmap_plains.bin- Raw height data for plains regionheightmap_canyons.bin- Raw height data for canyons region- ... (8 total heightmap files)
preview_mountains.png- Color-coded visualizationpreview_plains.png- Color-coded visualization- ... (8 total preview images)
metadata.json- Complete generation settings and region information
| Region | Base Height | Roughness | Erosion | Description |
|---|---|---|---|---|
| Mountains | 0.8 | 0.9 | Thermal | High peaks with sharp ridges |
| Plains | 0.2 | 0.3 | None | Flat grasslands with gentle hills |
| Canyons | 0.1 | 0.7 | Hydraulic | Deep carved valleys |
| Hills | 0.4 | 0.5 | Light | Moderate elevation slopes |
| Valleys | 0.05 | 0.4 | Hydraulic | Low drainage areas |
| Plateaus | 0.6 | 0.2 | Thermal | Elevated flat regions |
| Badlands | 0.3 | 0.8 | Thermal | Eroded complex formations |
| Highlands | 0.5 | 0.6 | Light | Elevated moderate terrain |
The generator automatically creates seamless transitions between adjacent heightmaps:
- Grid Layout: Arranges 8 heightmaps in a 3x3 grid (excluding center)
- Edge Detection: Identifies adjacent regions
- Height Averaging: Calculates average height at boundaries
- Gradient Blending: Applies smooth transition over stitch zone
- Continuity Enforcement: Ensures no visible seams between regions
The generated .bin files can be loaded directly into the Three.js terrain system:
// Load heightmap data
const heightmapData = await fetch('heightmap_mountains.bin')
.then(response => response.arrayBuffer())
.then(buffer => new Uint8Array(buffer));
// Create texture
const heightTexture = new THREE.DataTexture(
heightmapData, 256, 256, THREE.RedFormat, THREE.UnsignedByteType
);node generate.js --width 512 --height 512 --output ./hiresnode generate.js --debug --output ./debug-outputnode generate.js --stitch-size 64 --output ./smooth-transitions# Convert single custom heightmap
npm run convert my-terrain.png
# Batch convert terrain images
npm run convert -- --batch ./terrain-images ./output- Noise Algorithm: Improved Perlin Noise with deterministic seeding
- Erosion Models: Thermal (slope-based) and Hydraulic (water-based)
- File Format: Raw binary data compatible with Three.js DataTexture
- Color Coding: Terrain-specific color schemes for easy visual debugging
Out of Memory: Reduce heightmap size or disable preview image generation
node generate.js --width 128 --height 128 --no-imagesVisible Seams: Increase stitch size for smoother transitions
node generate.js --stitch-size 64Generation Too Slow: Run without debug mode and preview images
node generate.js --no-images