unilab.terrains.terrain_generator¶
Classes
Configuration for sampling flat patches on a heightfield surface. |
|
Merged terrain heightfield ready to be exported as a single PNG asset. |
|
Compact world-space sampler for a generated hfield surface. |
|
SubTerrainCfg(proportion: 'float' = 1.0, size: 'tuple[float, float]' = (10.0, 10.0), flat_patch_sampling: 'dict[str, FlatPatchSamplingCfg] | None' = None) |
|
Generates procedural terrain grids with configurable difficulty. |
|
TerrainGeneratorCfg(*, seed: 'int | None' = None, curriculum: 'bool' = False, size: 'tuple[float, float]', horizontal_scale: 'float' = 0.05, vertical_scale: 'float' = 0.005, border_width: 'float' = 0.0, num_rows: 'int' = 1, num_cols: 'int' = 1, sub_terrains: 'dict[str, SubTerrainCfg]' = <factory>, difficulty_range: 'tuple[float, float]' = (0.0, 1.0), add_lights: 'bool' = False) |
|
Backend-agnostic heightfield data for one sub-terrain patch. |
|
TerrainOutput(origin: 'np.ndarray', heightfield: 'TerrainHeightField', flat_patches: 'dict[str, np.ndarray] | None' = None) |
- class unilab.terrains.terrain_generator.FlatPatchSamplingCfg[source]¶
Bases:
objectConfiguration for sampling flat patches on a heightfield surface.
- Parameters:
-
max_height_diff:
float= 0.05¶ Maximum allowed height variation within the patch footprint, in meters.
-
x_range:
tuple[float,float] = (-1000000.0, 1000000.0)¶ Allowed range of x coordinates for sampled patches, in meters.
-
y_range:
tuple[float,float] = (-1000000.0, 1000000.0)¶ Allowed range of y coordinates for sampled patches, in meters.
-
z_range:
tuple[float,float] = (-1000000.0, 1000000.0)¶ Allowed range of z coordinates (world height) for sampled patches, in meters.
-
grid_resolution:
float|None= None¶ Resolution of the grid used for flat-patch detection, in meters. When
None(default), the terrain’s ownhorizontal_scaleis used. Set to a smaller value (e.g. 0.025) for finer boundary precision at the cost of a larger intermediate grid.
- __init__(num_patches=10, patch_radius=0.5, max_height_diff=0.05, x_range=(-1000000.0, 1000000.0), y_range=(-1000000.0, 1000000.0), z_range=(-1000000.0, 1000000.0), grid_resolution=None)¶
- class unilab.terrains.terrain_generator.TerrainHeightField[source]¶
Bases:
objectBackend-agnostic heightfield data for one sub-terrain patch.
- Parameters:
- __init__(noise, size, horizontal_scale, vertical_scale, elevation_min, elevation_max, max_physical_height, base_thickness, z_offset)¶
- class unilab.terrains.terrain_generator.TerrainOutput[source]¶
Bases:
objectTerrainOutput(origin: ‘np.ndarray’, heightfield: ‘TerrainHeightField’, flat_patches: ‘dict[str, np.ndarray] | None’ = None)
- Parameters:
-
heightfield:
TerrainHeightField¶ Backend-agnostic heightfield data.
- class unilab.terrains.terrain_generator.GeneratedTerrain[source]¶
Bases:
objectMerged terrain heightfield ready to be exported as a single PNG asset.
- Parameters:
- class unilab.terrains.terrain_generator.HeightfieldSurfaceSampler[source]¶
Bases:
objectCompact world-space sampler for a generated hfield surface.
- class unilab.terrains.terrain_generator.SubTerrainCfg[source]¶
Bases:
ABCSubTerrainCfg(proportion: ‘float’ = 1.0, size: ‘tuple[float, float]’ = (10.0, 10.0), flat_patch_sampling: ‘dict[str, FlatPatchSamplingCfg] | None’ = None)
- Parameters:
-
proportion:
float= 1.0¶ Robot spawning weight for this terrain type.
In curriculum mode, controls how many robots are spawned on this terrain’s column relative to other terrain types. Each terrain type always gets exactly one column; proportion only affects spawning distribution.
In random mode, controls the sampling probability for each patch.
-
flat_patch_sampling:
dict[str,FlatPatchSamplingCfg] |None= None¶ Named flat-patch sampling configurations, or None to disable.
- class unilab.terrains.terrain_generator.TerrainGeneratorCfg[source]¶
Bases:
objectTerrainGeneratorCfg(*, seed: ‘int | None’ = None, curriculum: ‘bool’ = False, size: ‘tuple[float, float]’, horizontal_scale: ‘float’ = 0.05, vertical_scale: ‘float’ = 0.005, border_width: ‘float’ = 0.0, num_rows: ‘int’ = 1, num_cols: ‘int’ = 1, sub_terrains: ‘dict[str, SubTerrainCfg]’ = <factory>, difficulty_range: ‘tuple[float, float]’ = (0.0, 1.0), add_lights: ‘bool’ = False)
- Parameters:
-
curriculum:
bool= False¶ Controls terrain allocation mode:
- curriculum=True: Each terrain type gets exactly ONE column. The generator uses
len(sub_terrains)columns regardless ofnum_cols. Difficulty increases along rows. Theproportionfield controls how many robots are spawned per column, not column count.
- curriculum=False: Every patch is randomly sampled from all terrain types.
Proportions control sampling probability. Use this for random variety.
-
size:
tuple[float,float]¶ Width and length of each sub-terrain patch, in meters. Both components must be integer multiples of
horizontal_scale.
-
horizontal_scale:
float= 0.05¶ Heightfield grid resolution along x and y, in meters per cell. Shared by every sub-terrain (overwritten in
TerrainGenerator__init__). All length-like sub-terrain parameters (step_width, platform_width, border_width, etc.) must be integer multiples of this value.
- __init__(*, seed=None, curriculum=False, size, horizontal_scale=0.05, vertical_scale=0.005, border_width=0.0, num_rows=1, num_cols=1, sub_terrains=<factory>, difficulty_range=(0.0, 1.0), add_lights=False)¶
-
vertical_scale:
float= 0.005¶ Heightfield height resolution, in meters per integer unit of the noise array. Shared by every sub-terrain (overwritten in
TerrainGenerator__init__).
-
border_width:
float= 0.0¶ Width of the flat border around the entire terrain grid, in meters. Must be an integer multiple of
horizontal_scaleif non-zero. The border is a flat hfield slab whose top surface is flush with the inner-terrain floor at z=0; it is NOT a wall.
-
num_rows:
int= 1¶ Number of sub-terrain rows in the grid. Represents difficulty levels in curriculum mode. Note: Environments are randomly assigned to rows, so multiple envs can share the same patch.
-
num_cols:
int= 1¶ Number of sub-terrain columns in the grid.
In curriculum mode the generator ignores this value and uses one column per terrain type (
len(sub_terrains)). In random mode it is used as-is.
-
sub_terrains:
dict[str,SubTerrainCfg]¶ Named sub-terrain configurations to populate the grid.
- class unilab.terrains.terrain_generator.TerrainGenerator[source]¶
Bases:
objectGenerates procedural terrain grids with configurable difficulty.
Creates a grid of terrain patches where each patch can be a different terrain type. Supports two modes:
- Random mode (curriculum=False): Every patch independently samples a
terrain type weighted by proportions. Results in random variety across all patches.
- Curriculum mode (curriculum=True): Each terrain type gets exactly one column
(the generator uses
len(sub_terrains)columns regardless ofnum_cols). Difficulty increases along rows. Theproportionfield controls robot spawning distribution, not column count.
Terrain types are weighted by proportion and their geometry is generated based on a difficulty value in the configured range. The grid is centered at the world origin. A border can be added around the entire grid along with optional overhead lighting.
- Parameters:
cfg (
TerrainGeneratorCfg)device (
str)
- __init__(cfg, device='cpu')[source]¶
- Parameters:
cfg (
TerrainGeneratorCfg)device (
str)