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 |
|
Immutable Z-up terrain surface. |
|
World-owned static actors and optional registered render prims. |
|
Create closed stair rings and a central platform, including risers. |
|
Create a pyramid clipped at the central platform's corner height. |
|
Create random box tops and a flat raised central platform. |
Height-field terrain construction and mesh conversion.
- class kangengine.terrain.TerrainMesh(vertices, indices, *, max_triangles_per_chunk=250000)[python]¶
Immutable Z-up terrain surface. Cooking is cached per world/source mesh.
Mesh queries optionally require
kangengine[terrain](Warp). Terrain construction and PhysX collision do not require Warp or a graphics context.- create(
- world,
- *,
- position=(0.0, 0.0, 0.0),
- material=None,
- num_prims_per_leaf=4,
- weld_tolerance=0.0,
Create static GPU-compatible collision instances in a physics world.
- classmethod from_heightfield(
- terrain,
- *,
- center=True,
- slope_threshold=None,
- diagonal='anti',
Build from an existing SubTerrain or TerrainGrid without changing it.
- raycast(
- ray_starts: Tensor,
- ray_directions: Tensor,
- *,
- max_distance: float = 1000000.0,
Find the nearest mesh intersection along each ray.
- Parameters:
ray_starts (
Tensor) – Float32 CPU/CUDA tensor […, 3] in mesh coordinates, in metres. Keep CUDA inputs synchronized with the current stream.ray_directions (
Tensor) – Float32 tensor […, 3] on the same device. Leading dimensions broadcast with ray_starts. Directions are normalized internally; zero directions produce misses.max_distance (
float) – Maximum ray travel in metres.
- Return type:
tuple[Tensor,Tensor]- Returns:
Hit positions […, 3] and distances […] in metres, on the input device. Misses have +inf in every position component and distance.
- sample_height(positions, *, ray_start_height=None)¶
Return downward mesh hits at world XY on the input tensor’s device.
No hit returns -inf. A supplied ray_start_height matches a height scanner’s finite origin; otherwise rays start above the entire mesh.
- class kangengine.terrain.TerrainInstance(
- asset,
- world,
- *,
- position,
- material,
- num_prims_per_leaf=4,
- weld_tolerance=0.0,
World-owned static actors and optional registered render prims.
- add_visual(scene, path, *, material)¶
Register source meshes/materials through the normal scene API.
- raycast(
- ray_starts: Tensor,
- ray_directions: Tensor,
- *,
- max_distance: float = 1000000.0,
Query world-space rays against this translated terrain instance.
Inputs and results follow TerrainMesh.raycast, with starts and hit positions expressed in world coordinates. Distances remain in metres.
- Return type:
tuple[Tensor,Tensor]
- remove()¶
Remove instances before closing their world; cooked data stays cached.
- remove_visual()¶
Remove render prims before closing their scene/viewer.
- sample_height(positions, *, ray_start_height=None)¶
- kangengine.terrain.pyramid_stairs_mesh(
- *,
- size=(8.0, 8.0),
- step_height=0.1,
- step_width=0.3,
- platform_width=3.0,
- border_width=1.0,
- inverted=False,
Create closed stair rings and a central platform, including risers.
Dimensions follow IsaacLab’s pyramid stair convention: the first ring is one step above/below the border and the platform is one further step.
- kangengine.terrain.pyramid_sloped_mesh(
- *,
- size=(8.0, 8.0),
- slope=0.2,
- platform_width=2.0,
- border_width=0.25,
- horizontal_scale=0.1,
- vertical_scale=0.005,
- slope_threshold=0.75,
Create a pyramid clipped at the central platform’s corner height.
Unlike the legacy raised-platform heightfield generator, clipping keeps the platform continuous with the surrounding slopes. Negative slopes produce an inverted pyramid. The border remains at height zero.
- kangengine.terrain.random_grid_mesh(
- *,
- size=(8.0, 8.0),
- grid_width=0.45,
- grid_height=0.1,
- platform_width=2.0,
- rng=None,
Create random box tops and a flat raised central platform.
- 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: