Skip to content

Commit c0c6095

Browse files
authored
[BUG FIX] Fix 'discrete_obstacles_terrain' being completely flat. (#1972)
1 parent 3cd6708 commit c0c6095

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

genesis/ext/isaacgym/terrain_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def discrete_obstacles_terrain(terrain, max_height, min_size, max_size, num_rect
179179

180180
start_x, end_x = (terrain.width - platform_size) // 2, (terrain.width + platform_size) // 2
181181
start_y, end_y = (terrain.length - platform_size) // 2, (terrain.length + platform_size) // 2
182-
terrain.height_field_raw[:] = 0.0
182+
terrain.height_field_raw[start_x:end_x, start_y:end_y] = 0
183183

184184
return terrain
185185

tests/test_rigid_physics.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,33 @@ def test_terrain_generation(request, show_viewer):
21562156
assert_allclose(terrain_mesh.verts, terrain_2_mesh.verts, tol=gs.EPS)
21572157

21582158

2159+
@pytest.mark.required
2160+
def test_discrete_obstacles_terrain():
2161+
scene = gs.Scene()
2162+
terrain = scene.add_entity(
2163+
gs.morphs.Terrain(
2164+
n_subterrains=(1, 1),
2165+
subterrain_size=(6.0, 6.0),
2166+
horizontal_scale=0.5,
2167+
vertical_scale=0.5,
2168+
subterrain_types=[["discrete_obstacles_terrain"]],
2169+
subterrain_parameters={
2170+
"discrete_obstacles_terrain": {
2171+
"max_height": 1.0,
2172+
"platform_size": 1.0,
2173+
}
2174+
},
2175+
)
2176+
)
2177+
scene.build()
2178+
height_field = terrain.geoms[0].metadata["height_field"]
2179+
platform = height_field[5:7, 5:7]
2180+
2181+
assert height_field.max().item() == 2.0
2182+
assert height_field.min().item() == -2.0
2183+
assert (platform == 0.0).all()
2184+
2185+
21592186
def test_mesh_to_heightfield(tmp_path, show_viewer):
21602187
horizontal_scale = 2.0
21612188
path_terrain = os.path.join(get_assets_dir(), "meshes", "terrain_45.obj")

0 commit comments

Comments
 (0)