Skip to main content

Module terrain

Module terrain 

Source
Expand description

Heightfield-style terrain: a subdivided grid mesh in the XZ plane whose vertex heights (local Y) are edited by radial brush operations.

A terrain is a plain MeshInstance node, so rendering, undo, saving and glTF export work without any special cases. The brush functions operate on mesh-local positions; callers with transformed nodes must convert the brush center into local space first.

Enums§

BrushMode
How a brush stroke changes the heights inside its radius.

Functions§

add_terrain
Create a terrain grid node with the soil material attached.
add_water
Create a translucent water surface node at world height height.
brush
Apply one brush step to a terrain grid mesh in mesh-local space.
falloff
Smooth falloff 1.0 at the brush center, 0.0 at (and beyond) the radius.
grid_mesh
Subdivided terrain grid centred on the origin, lying on the XZ plane at y = 0 with normals pointing up. Shared vertices (indexed), so brushes deform the surface without seams.
grid_segments
Detect a grid produced by grid_mesh: (s+1)² shared vertices on a regular XZ lattice plus s²·6 indices in the builder’s winding pattern. Returns the segment count s.
material_by_name
Find or create a named material so repeated calls don’t pile up duplicates.
resample_grid
Resample a terrain grid to new_segments per axis by bilinearly sampling the height field; XZ extents are preserved, normals recomputed. Returns false when the mesh is not a grid_mesh lattice.
soil_material
Ground material for freshly created maps.
water_material
Translucent blue material for water surfaces.
water_mesh
Flat quad on the XZ plane at the given height, for a water surface.