ke.terrain

Terrain generation, heightfields, and terrain-to-mesh conversion workflows.

API overview

SubTerrain

Discrete height-field terrain buffer.

TerrainGrid

Large height-field assembled from multiple overlapping sub-terrains.

random_uniform_terrain

Add discrete uniform random heights to the terrain.

sloped_terrain

Add a linear slope along the terrain width axis.

pyramid_sloped_terrain

Add a pyramid slope clipped to a flat center platform.

stairs_terrain

Add stairs along the terrain width axis.

wave_terrain

Add sinusoidal waves along both terrain axes.

discrete_obstacles_terrain

Scatter axis-aligned rectangular height obstacles.

height_field_to_mesh

Convert a 2D height array in meters to scene.MeshData.

height_field_to_mesh_python

Pure Python height field to scene.MeshData conversion.

Height-field terrain construction and mesh conversion.

class kangengine.terrain.SubTerrain(
width: int,
length: int,
horizontal_scale: float = 0.05,
vertical_scale: float = 0.005,
) None[python]

Discrete height-field terrain buffer.

height_field_raw stores integer height units. Convert to meters with height_meters() before building render/physics meshes.

height_meters() ndarray
Return type:

ndarray

horizontal_scale = 0.05
to_mesh(*, up_axis=<UpAxis.Y: 1>, center: bool = True, backend: str = 'cpp')
vertical_scale = 0.005
width
length
class kangengine.terrain.TerrainGrid(
rows: int,
cols: int,
tile_width: int,
tile_length: int,
*,
horizontal_scale: float = 0.05,
vertical_scale: float = 0.005,
)[python]

Large height-field assembled from multiple overlapping sub-terrains.

Adjacent tiles share one vertex row/column, so the final mesh is continuous instead of being a set of separate islands.

fill(
generator: Callable[[SubTerrain, int, int], SubTerrain],
)

Generate every tile with generator(tile, row, col).

height_meters() ndarray
Return type:

ndarray

property length
set_tile(row: int, col: int, tile: SubTerrain)

Copy a sub-terrain into the grid at tile coordinates.

tile_origin(row: int, col: int) tuple[int, int]
Return type:

tuple[int, int]

to_mesh(*, up_axis=<UpAxis.Y: 1>, center: bool = True, backend: str = 'cpp')
property width
kangengine.terrain.discrete_obstacles_terrain(
terrain: SubTerrain,
max_height: float,
min_size: float,
max_size: float,
num_rects: int,
platform_size: float = 1.0,
rng=None,
) SubTerrain[python]

Scatter axis-aligned rectangular height obstacles.

Return type:

SubTerrain

kangengine.terrain.height_field_to_mesh(
heights,
*,
horizontal_scale: float = 1.0,
up_axis=<UpAxis.Y: 1>,
center: bool = True,
backend: str = 'cpp',
)[python]

Convert a 2D height array in meters to scene.MeshData.

kangengine.terrain.height_field_to_mesh_python(
heights,
*,
horizontal_scale: float = 1.0,
up_axis=<UpAxis.Y: 1>,
center: bool = True,
)[python]

Pure Python height field to scene.MeshData conversion.

This is useful for prototyping terrain generators without adding new C++ bindings. Use height_field_to_mesh() with the default backend="cpp" when mesh generation itself becomes a hot path.

kangengine.terrain.pyramid_sloped_terrain(
terrain: SubTerrain,
slope: float = 1.0,
platform_size: float = 1.0,
) SubTerrain[python]

Add a pyramid slope clipped to a flat center platform.

Return type:

SubTerrain

kangengine.terrain.random_uniform_terrain(
terrain: SubTerrain,
min_height: float,
max_height: float,
step: float = 0.02,
rng=None,
) SubTerrain[python]

Add discrete uniform random heights to the terrain.

Return type:

SubTerrain

kangengine.terrain.sloped_terrain(
terrain: SubTerrain,
slope: float = 1.0,
) SubTerrain[python]

Add a linear slope along the terrain width axis.

Return type:

SubTerrain

kangengine.terrain.stairs_terrain(
terrain: SubTerrain,
step_width: float,
step_height: float,
) SubTerrain[python]

Add stairs along the terrain width axis.

Return type:

SubTerrain

kangengine.terrain.wave_terrain(
terrain: SubTerrain,
num_waves: float = 2.0,
amplitude: float = 0.2,
) SubTerrain[python]

Add sinusoidal waves along both terrain axes.

Return type:

SubTerrain