ke.terrain¶
Terrain generation, heightfields, and terrain-to-mesh conversion workflows.
API overview¶
Discrete height-field terrain buffer. |
|
Large height-field assembled from multiple overlapping sub-terrains. |
|
Add discrete uniform random heights to the terrain. |
|
Add a linear slope along the terrain width axis. |
|
Add a pyramid slope clipped to a flat center platform. |
|
Add stairs along the terrain width axis. |
|
Add sinusoidal waves along both terrain axes. |
|
Scatter axis-aligned rectangular height obstacles. |
|
Convert a 2D height array in meters to |
|
Pure Python height field to |
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,
Discrete height-field terrain buffer.
height_field_rawstores 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,
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,
Scatter axis-aligned rectangular height obstacles.
- Return type:
- kangengine.terrain.height_field_to_mesh(
- heights,
- *,
- horizontal_scale: float = 1.0,
- up_axis=<UpAxis.Y: 1>,
- center: bool = True,
- backend: str = 'cpp',
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,
Pure Python height field to
scene.MeshDataconversion.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,
Add a pyramid slope clipped to a flat center platform.
- Return type:
- kangengine.terrain.random_uniform_terrain(
- terrain: SubTerrain,
- min_height: float,
- max_height: float,
- step: float = 0.02,
- rng=None,
Add discrete uniform random heights to the terrain.
- Return type:
- kangengine.terrain.sloped_terrain(
- terrain: SubTerrain,
- slope: float = 1.0,
Add a linear slope along the terrain width axis.
- Return type:
- kangengine.terrain.stairs_terrain(
- terrain: SubTerrain,
- step_width: float,
- step_height: float,
Add stairs along the terrain width axis.
- Return type:
- kangengine.terrain.wave_terrain(
- terrain: SubTerrain,
- num_waves: float = 2.0,
- amplitude: float = 0.2,
Add sinusoidal waves along both terrain axes.
- Return type: