Skip to content

Commit f0baf70

Browse files
authored
Ray normal fixes (#960)
* Add ray with normal * Ruff * Propagate ray normal changes * ruff * Fix tuple type check * Update ray to return -1 for non-hits * Small fixes * Ruff format * Simplify assert for vec3 * Add comment and adjust docstring
1 parent c915c40 commit f0baf70

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

mujoco_warp/_src/ray.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def _ray_cylinder(pos: wp.vec3, mat: wp.mat33, size: wp.vec3, pnt: wp.vec3, vec:
393393

394394
@wp.func
395395
def _ray_box(pos: wp.vec3, mat: wp.mat33, size: wp.vec3, pnt: wp.vec3, vec: wp.vec3) -> Tuple[float, vec6, wp.vec3]:
396-
"""Returns the distance and normal at which a ray intersects with a box."""
396+
"""Returns distance, per side information, and normal at which a ray intersects with a box."""
397397
all = vec6(-1.0, -1.0, -1.0, -1.0, -1.0, -1.0)
398398

399399
# bounding sphere test
@@ -812,9 +812,9 @@ def _ray(
812812
flg_static: bool,
813813
bodyexclude: wp.array(dtype=int),
814814
# Out:
815-
dist_out: wp.array(dtype=float, ndim=2),
816-
geomid_out: wp.array(dtype=int, ndim=2),
817-
normal_out: wp.array(dtype=wp.vec3, ndim=2),
815+
dist_out: wp.array2d(dtype=float),
816+
geomid_out: wp.array2d(dtype=int),
817+
normal_out: wp.array2d(dtype=wp.vec3),
818818
):
819819
worldid, rayid, tid = wp.tid()
820820

mujoco_warp/_src/ray_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def _assert_eq(a, b, name):
3535
np.testing.assert_allclose(a, b, err_msg=err_msg, atol=tol, rtol=tol)
3636

3737

38+
# TODO: Add tests comparing normal to engine implementation once available.
3839
class RayTest(absltest.TestCase):
3940
def test_ray_nothing(self):
4041
"""Tests that ray returns -1 when nothing is hit."""
@@ -49,7 +50,7 @@ def test_ray_nothing(self):
4950
normal_np = normal.numpy()[0, 0]
5051
_assert_eq(geomid_np, -1, "geom_id")
5152
_assert_eq(dist_np, -1, "dist")
52-
_assert_eq(normal_np, wp.vec3(0.0, 0.0, 0.0), "normal")
53+
_assert_eq(normal_np, 0, "normal")
5354

5455
def test_ray_plane(self):
5556
"""Tests ray<>plane matches MuJoCo."""
@@ -292,7 +293,7 @@ def test_ray_bodyexclude(self):
292293
normal_np = normal.numpy()[0, 0]
293294
_assert_eq(geomid_np, -1, "geom_id")
294295
_assert_eq(dist_np, -1, "dist")
295-
_assert_eq(normal_np, wp.vec3(0.0, 0.0, 0.0), "normal")
296+
_assert_eq(normal_np, 0, "normal")
296297

297298
def test_ray_invisible(self):
298299
"""Tests ray doesn't hit transparent geoms."""
@@ -311,7 +312,7 @@ def test_ray_invisible(self):
311312
normal_np = normal.numpy()[0, 0]
312313
_assert_eq(geomid_np, -1, "geom_id")
313314
_assert_eq(dist_np, -1, "dist")
314-
_assert_eq(normal_np, wp.vec3(0.0, 0.0, 0.0), "normal")
315+
_assert_eq(normal_np, 0, "normal")
315316

316317

317318
if __name__ == "__main__":

0 commit comments

Comments
 (0)