mjlab.terrains#
Classes
Core#
- class mjlab.terrains.TerrainEntity[source]#
Bases:
EntityTerrain entity.
The terrain is a grid of sub-terrain patches (num_rows x num_cols), each with a spawn origin. When num_envs exceeds the number of patches, environment origins are sampled from the sub-terrain origins.
Note
Environment allocation for procedural terrain: Columns (terrain types) are evenly distributed across environments, but rows (difficulty levels) are randomly sampled. This means multiple environments can spawn on the same (row, col) patch, leaving others unoccupied, even when num_envs > num_patches.
See FAQ: “How does env_origins determine robot layout?”
- __init__(cfg: TerrainEntityCfg, device: str) None[source]#
- configure_env_origins(origins: ndarray | Tensor | None = None) None[source]#
Configure the origins of the environments based on the terrain.
- class mjlab.terrains.TerrainEntityCfg[source]#
Configuration for terrain as an entity.
- terrain_type: Literal['generator', 'plane'] = 'plane'#
Type of terrain to generate. “generator” uses procedural terrain with sub-terrain grid, “plane” creates a flat ground plane.
- terrain_generator: TerrainGeneratorCfg | None = None#
Configuration for procedural terrain generation. Required when terrain_type is “generator”.
- env_spacing: float | None = 2.0#
Distance between environment origins when using grid layout. Required for “plane” terrain or when no sub-terrain origins exist.
- max_init_terrain_level: int | None = None#
Maximum initial difficulty level (row index) for environment placement in curriculum mode. None uses all available rows.
- num_envs: int = 1#
Number of parallel environments to create. This will get overridden by the scene configuration if specified there.
- textures: tuple[spec_cfg.TextureCfg, ...]#
Textures for the ground plane. Defaults to a checker pattern. Set to
()to disable textures (e.g. when usingdr.geom_rgba).
- materials: tuple[spec_cfg.MaterialCfg, ...]#
Materials for the ground plane. Defaults to the checker material. Set to
()to disable materials (e.g. when usingdr.geom_rgba).
- build() TerrainEntity[source]#
Build entity instance from this config.
Override in subclasses to return custom Entity types.
- class mjlab.terrains.TerrainGenerator[source]#
Generates 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): Columns are deterministically assigned to terrain types based on proportions. All patches in a column share the same terrain type, with difficulty increasing along rows. Use this to ensure each terrain type occupies specific column(s).
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.
- __init__(cfg: TerrainGeneratorCfg, device: str = 'cpu') None[source]#
- class mjlab.terrains.TerrainGeneratorCfg[source]#
-
- curriculum: bool = False#
Controls terrain allocation mode:
curriculum=True: Each column gets ONE terrain type (deterministic allocation). Difficulty increases along rows. Use this to ensure each terrain type occupies its own column(s).
curriculum=False: Every patch is randomly sampled from all terrain types. Proportions control sampling probability. Use this for random variety.
Example: With 2 terrain types and num_cols=2, curriculum=True gives one terrain per column. curriculum=False gives a random mix of both types in all patches.
- 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. Represents terrain type variants. Note: Environments are evenly distributed across columns (not random).
- color_scheme: Literal['height', 'random', 'none'] = 'height'#
Coloring strategy for terrain geometry. “height” colors by elevation, “random” assigns random colors, “none” uses uniform gray.
- sub_terrains: dict[str, SubTerrainCfg]#
Named sub-terrain configurations to populate the grid.
- class mjlab.terrains.SubTerrainCfg[source]#
- proportion: float = 1.0#
Terrain type allocation weight (behavior depends on curriculum mode):
curriculum=True: Controls column allocation. Normalized proportions determine how many columns each terrain type occupies via cumulative distribution. Example: proportions [0.5, 0.5] with num_cols=2 gives one terrain per column.
curriculum=False: Sampling probability for each patch. Each patch independently samples a terrain type weighted by normalized proportions.
- flat_patch_sampling: dict[str, FlatPatchSamplingCfg] | None = None#
Named flat-patch sampling configurations, or None to disable.
- class mjlab.terrains.FlatPatchSamplingCfg[source]#
Configuration for sampling flat patches on a heightfield surface.
- 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.
Heightfield Terrains#
- class mjlab.terrains.HfDiscreteObstaclesTerrainCfg[source]#
Bases:
SubTerrainCfg- obstacle_height_mode: Literal['choice', 'fixed'] = 'choice'#
How obstacle heights are chosen. “choice” randomly picks from [-h, -h/2, h/2, h] (mix of pits and bumps); “fixed” uses h for all obstacles.
- obstacle_height_range: tuple[float, float]#
Min and max obstacle height, in meters. Interpolated by difficulty.
- platform_width: float = 1.0#
Side length of the obstacle-free flat square at the terrain center, in meters.
- vertical_scale: float = 0.005#
Heightfield height resolution, in meters per integer unit of the noise array.
- base_thickness_ratio: float = 1.0#
Ratio of the heightfield base thickness to its maximum surface height.
- border_width: float = 0.0#
Width of the flat border around the terrain edges, in meters. Must be >= horizontal_scale if non-zero.
- square_obstacles: bool = False#
If True, obstacles have equal width and length. If False, each dimension is sampled independently.
- class mjlab.terrains.HfPerlinNoiseTerrainCfg[source]#
Bases:
SubTerrainCfg
- class mjlab.terrains.HfRandomUniformTerrainCfg[source]#
Bases:
SubTerrainCfg- noise_step: float = 0.005#
Height quantization step, in meters. Sampled heights are multiples of this value within noise_range.
- downsampled_scale: float | None = None#
Spacing between randomly sampled height points before interpolation, in meters. If None, uses horizontal_scale. Must be >= horizontal_scale.
- vertical_scale: float = 0.005#
Heightfield height resolution, in meters per integer unit of the noise array.
- base_thickness_ratio: float = 1.0#
Ratio of the heightfield base thickness to its maximum surface height.
- class mjlab.terrains.HfPyramidSlopedTerrainCfg[source]#
Bases:
SubTerrainCfg- slope_range: tuple[float, float]#
Range of slope gradients (rise / run), interpolated by difficulty.
- platform_width: float = 1.0#
Side length of the flat square platform at the terrain center, in meters.
- border_width: float = 0.0#
Width of the flat border around the terrain edges, in meters. Must be >= horizontal_scale if non-zero.
- vertical_scale: float = 0.005#
Heightfield height resolution, in meters per integer unit of the noise array.
- class mjlab.terrains.HfWaveTerrainCfg[source]#
Bases:
SubTerrainCfg- amplitude_range: tuple[float, float]#
Min and max wave amplitude, in meters. Interpolated by difficulty.
- vertical_scale: float = 0.005#
Heightfield height resolution, in meters per integer unit of the noise array.
- base_thickness_ratio: float = 0.25#
Ratio of the heightfield base thickness to its maximum surface height.
Primitive (Box) Terrains#
- class mjlab.terrains.BoxFlatTerrainCfg[source]#
Bases:
SubTerrainCfg
- class mjlab.terrains.BoxInvertedPyramidStairsTerrainCfg[source]#
Bases:
BoxPyramidStairsTerrainCfg
- class mjlab.terrains.BoxNarrowBeamsTerrainCfg[source]#
Bases:
SubTerrainCfg
- class mjlab.terrains.BoxNestedRingsTerrainCfg[source]#
Bases:
SubTerrainCfg
- class mjlab.terrains.BoxOpenStairsTerrainCfg[source]#
Bases:
SubTerrainCfg
- class mjlab.terrains.BoxPyramidStairsTerrainCfg[source]#
Bases:
SubTerrainCfgConfiguration for a pyramid stairs terrain.
- border_width: float = 0.0#
Width of the flat border frame around the staircase, in meters. Ignored when holes is True.
- step_height_range: tuple[float, float]#
Min and max step height, in meters. Interpolated by difficulty.
- class mjlab.terrains.BoxRandomGridTerrainCfg[source]#
Bases:
SubTerrainCfg- grid_height_range: tuple[float, float]#
Min and max grid cell height bound, in meters. Interpolated by difficulty. At a given difficulty, cell heights are sampled uniformly from [-bound, +bound].
- holes: bool = False#
If True, only the cross-shaped region around the center platform has grid cells.
- merge_similar_heights: bool = False#
If True, adjacent cells with similar heights are merged into larger boxes to reduce geom count.
- class mjlab.terrains.BoxRandomSpreadTerrainCfg[source]#
Bases:
SubTerrainCfg
- class mjlab.terrains.BoxRandomStairsTerrainCfg[source]#
Bases:
SubTerrainCfg
- class mjlab.terrains.BoxSteppingStonesTerrainCfg[source]#
Bases:
SubTerrainCfg
- class mjlab.terrains.BoxTiltedGridTerrainCfg[source]#
Bases:
SubTerrainCfg