RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

server/commands - Camera & Input Commandsge_utils - Game Engine Utility Functionsmain.lua - GE Lua Entry Point & Game Loopmap.lua - Navigation Graph (AI Road Map)screenshot.lua - Screenshot Systemserver/server - Level Loading & Game ServerserverConnection - Client-Server Connection Manager`setSpawnpoint` - Default Spawn Point Persistence`simTimeAuthority` - Simulation Time & Bullet Time Control`spawn` - Vehicle Spawning & Safe Placement`suspensionFrequencyTester` - Suspension Natural Frequency Analysis
Auto AnnotationBoosterCalibrate ESCCompile ImpostersCompile MeshesConfig List GeneratorDecal Roads EditorDependency TreeDoc CreatorExport (glTF)Follow The White RabbitForest GeneratorGround Model DebugInput System UtilsInstanced Line Render DemoJBeam StatsLog StreamsMap TilesNode Beam ExportNode StreamPhotomodePrecompile ShadersPrecompile VehiclesProcedural Track (Gymkhana Generator)Rectangle GeneratorRender Components APIResave MaterialsRich PresenceSave Dynamic DataScreenshot Creator (Vehicle Thumbnails)ShowroomSort LinesStep HandlerTerrain GeneratorTest Extension ProxiesTest JSON Files Syntaxutil/vehicleRopeDebug - Rope Physics Debug UIutil/worker - Batch Job Workerutil/wsTest - WebSocket Test Server

UI

Resources

BeamNG Game Engine Lua Cheat SheetGE Developer RecipesMCP Server Setup

// RLS.STUDIOS=true

Premium Mods for BeamNG.drive. Career systems, custom vehicles, and immersive gameplay experiences.

Index

HomeProjectsPatreon

Socials

DiscordPatreon (RLS)Patreon (Vehicles)

© 2026 RLS Studios. All rights reserved.

Modding since 2024

API ReferenceGE Extensionsutil

Terrain Generator

Creates terrain blocks from heightmap arrays, PNG files, or project directories with full material support.

Creates terrain blocks from heightmap arrays, PNG files, or project directories with full material support.


Overview

util_terrainGenerator provides an OOP interface for generating TerrainBlock objects. You can set heightmaps from Lua arrays or PNG files, configure materials from JSON, set texture layer maps, and create the final terrain. Supports import/export of terrain data.

Module path: lua/ge/extensions/util/terrainGenerator.lua Note: Used via require, returns a constructor.


Exports (M)

FunctionSignatureDescription
new(data?) → objectCreates a new terrain generator instance.

Instance Methods (C)

MethodSignatureDescription
init(data?)Initializes with optional config (scale, height, name, paths).
saveBitmap(path?)Saves the current heightmap bitmap as PNG.
loadBitmap(path?)Loads a heightmap from a PNG file.
getMaxHeight() → numberReturns the current terrain's max height.
setTerrainOffset(vec3)Repositions the terrain block.
centerTerrain()Centers the terrain so origin is at the middle.
setPoint(x, y, z)Sets a single heightmap pixel.
setBitmapFromArray(array)Creates heightmap from a 2D Lua array. Dimensions auto-padded to 128 multiples.
resetUserDir(dir?)Clears heightmap/holemap/layermap files in a directory.
resetTerrain(deleteOnly?)Deletes existing terrain; optionally recreates a blank TerrainBlock.
getTextureMap(path, matName?) → tableReturns a texture map data entry for a material.
exportTerrainMaps(dir?, prefix?)Exports current terrain's height/hole/layer maps as PNGs.
setPngData(path, size, height, scale, flipY)Directly sets heightmap file and parameters.
setUserDir(dir)Sets project directory; auto-discovers heightmaps, holemaps, and materials JSON.
setDefaultMaterial()Creates a default grid material (from smallgrid).
setMaterials(matData?)Loads terrain materials from JSON file, direct table, or existing terrain.
setTextureMaps()Discovers and matches layer map PNGs to materials. Creates blank maps for unmatched.
createTerrain()Creates the actual TerrainBlock from all configured data.

Internals

Init Data

{
  terrainScale = 1,        -- Grid size
  terrainHeight = maxHeight, -- Max height value
  name = "temp",           -- Generic name for files
  terrainName = "theTerrain", -- Scenetree object name
  userDir = "temp/",       -- Project directory
  heightMap = "temp/temp_heightMap.png",
  holeMap = "",
  textureMaps = nil,
  materials = nil,
}

Bitmap Format

Uses GBitmap with GFXFormatR16 (16-bit grayscale). Height values are mapped to [0, 65535] based on terrainHeight.

Material System

Supports both v1 materials (diffuseMap, normalMap, detailMap, macroMap) and v1.5 materials (TerrainMaterialTextureSet with baseColor/normal/roughness/ao/height texture properties).

Terrain Creation Flow

  1. Reset/delete existing terrain.
  2. Create new TerrainBlock registered in MissionGroup.
  3. Load heightmap bitmap, configure scale/height.
  4. Set materials and texture maps.
  5. Call terrain:importMaps() with all data.
  6. Save terrain file.

How It Works

  1. Create instance: local gen = require('util/terrainGenerator').new().
  2. Set heightmap via array or PNG.
  3. Configure materials (JSON or defaults).
  4. Call createTerrain() to build.
  5. Optionally centerTerrain().

Lua Examples

extensions.load('util/terrainGenerator')
local gen = util_terrainGenerator.new()

-- Create from array
local arr = {}
for x = 1, 256 do
  arr[x] = {}
  for y = 1, 256 do
    arr[x][y] = randomGauss3() / 5
  end
end
gen:setBitmapFromArray(arr)
gen:createTerrain()
gen:centerTerrain()

-- Create from project directory
local gen2 = util_terrainGenerator.new({name = "myLevel"})
gen2:setUserDir("/levels/myLevel/terrainProject/")
gen2:createTerrain()

-- Export existing terrain
gen:exportTerrainMaps("/temp/export/", "myTerrain")

Additional Exports

  • M.new - (undocumented)

Step Handler

A sequential step-execution system for orchestrating multi-step gameplay sequences (fades, vehicle spawns, level loads, waits, traffic).

Test Extension Proxies

Demonstration/test extension showing how to use `newExtensionProxy` to fan out extension hooks to multiple object instances.

On this page

OverviewExports (M)Instance Methods (C)InternalsInit DataBitmap FormatMaterial SystemTerrain Creation FlowHow It WorksLua ExamplesAdditional Exports