Skip to content

Commit 97537e4

Browse files
porizouporizou
andauthored
fix(warp): infinite planes' broad-phase AABB was razor-thin, hiding the ground (#23)
MuJoCo's "infinite plane" convention (geom size[0] == size[1] == 0.0) is already correctly special-cased as unbounded in ray_plane_distance's actual intersection test, but update_aabbs_kernel/update_aabbs_batch_kernel used that literal 0 as the plane's broad-phase AABB half-extent instead. That makes the plane's bounding box for the BVH almost zero-width, so the BVH culls nearly every ray before the real intersection test ever runs - the ground becomes effectively invisible to raycasting while finite geoms (legs, boxes, etc.) are unaffected, since they don't hit this branch. Substitute a large-but-finite half-extent (1000m) for the AABB only when a plane's size is <= 0, leaving the actual intersection math (which already handles size 0 as infinite) untouched. Verified with a synthetic scene (floor + sensor at z=1.1m): straight-down rays now report distance ~1.100001 (previously 0, i.e. no hit) with this fix. Co-authored-by: porizou <h.mori@openreach.tech>
1 parent 988a219 commit 97537e4

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

‎src/mujoco_lidar/core_warp/kernels.py‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,23 @@ def update_aabbs_kernel(
4242
lower = wp.vec3(0.0, 0.0, 0.0)
4343
upper = wp.vec3(0.0, 0.0, 0.0)
4444
elif geom_type == 0:
45+
# MuJoCo's "infinite" plane convention is size[0] == size[1] == 0.0 (the
46+
# intersection test in ray_plane_distance already special-cases this as
47+
# unbounded). Using that literal 0 as the AABB half-extent instead makes
48+
# the plane's broad-phase bounding box razor-thin, so the BVH culls
49+
# almost every ray before the intersection test ever runs - the ground
50+
# becomes effectively invisible while finite geoms (legs, boxes) are
51+
# unaffected. Substitute a large-but-finite half-extent for the AABB
52+
# only, so the BVH actually considers rays anywhere near the ground.
53+
plane_x = geom_sizes[geom_id][0]
54+
plane_y = geom_sizes[geom_id][1]
55+
if plane_x <= 0.0:
56+
plane_x = 1000.0
57+
if plane_y <= 0.0:
58+
plane_y = 1000.0
4559
lower, upper = compute_oriented_box_aabb(
4660
pos,
47-
wp.vec3(geom_sizes[geom_id][0], geom_sizes[geom_id][1], 1.0e-3),
61+
wp.vec3(plane_x, plane_y, 1.0e-3),
4862
rot,
4963
)
5064
else:
@@ -79,9 +93,18 @@ def update_aabbs_batch_kernel(
7993
lower = wp.vec3(0.0, 0.0, 0.0)
8094
upper = wp.vec3(0.0, 0.0, 0.0)
8195
elif geom_type == 0:
96+
# See the identical branch in update_aabbs_kernel for why a literal 0
97+
# (MuJoCo's "infinite plane" convention) must not be used as the AABB
98+
# half-extent.
99+
plane_x = geom_sizes[geom_id][0]
100+
plane_y = geom_sizes[geom_id][1]
101+
if plane_x <= 0.0:
102+
plane_x = 1000.0
103+
if plane_y <= 0.0:
104+
plane_y = 1000.0
82105
lower, upper = compute_oriented_box_aabb(
83106
pos,
84-
wp.vec3(geom_sizes[geom_id][0], geom_sizes[geom_id][1], 1.0e-3),
107+
wp.vec3(plane_x, plane_y, 1.0e-3),
85108
rot,
86109
)
87110
else:

0 commit comments

Comments
 (0)