-
Notifications
You must be signed in to change notification settings - Fork 51
Adds raycast implementation and tests #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
# Conflicts: # mujoco_warp/_src/io.py # mujoco_warp/_src/types.py
I assume the tests currently fail because wp.tile_argmin was only merged yesterday into warp and might not yet be in the warp build we are using. Will investigate more on Monday. |
mujoco_warp/_src/io.py
Outdated
m.mesh_vertadr = wp.array(mjm.mesh_vertadr, dtype=wp.int32, ndim=1) | ||
m.mesh_vertnum = wp.array(mjm.mesh_vertnum, dtype=wp.int32, ndim=1) | ||
m.mesh_vert = wp.array(mjm.mesh_vert, dtype=wp.vec3, ndim=1) | ||
m.mesh_faceadr = wp.array(mjm.mesh_faceadr, dtype=wp.int32, ndim=1) | ||
m.mesh_face = wp.array(mjm.mesh_face, dtype=wp.int32, ndim=2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since mesh_face
is (nmeshface, 3)
this array could be wp.array(mjm.mesh_face, dtype=wp.vec3i, ndim=1)
mujoco_warp/_src/ray_test.py
Outdated
class RayTest(absltest.TestCase): | ||
def test_ray_nothing(self): | ||
"""Tests that ray returns -1 when nothing is hit.""" | ||
m, d, _, _ = test_util.fixture("ray.xml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
following the convention of other tests:
mjm, mjd, m, d = ...
then it is not necessary to call mujoco.mj_forward
, mjwarp.put_model
, and mjwarp.put_data
below since these functions are called by test_util.fixture
.
mujoco_warp/_src/ray_test.py
Outdated
|
||
def test_ray_plane(self): | ||
"""Tests ray<>plane matches MuJoCo.""" | ||
m, d, _, _ = test_util.fixture("ray.xml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mjm, mjd, m, d = ...
mujoco_warp/_src/ray_test.py
Outdated
|
||
def test_ray_sphere(self): | ||
"""Tests ray<>sphere matches MuJoCo.""" | ||
m, d, _, _ = test_util.fixture("ray.xml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mjm, mjd, m, d = ...
mujoco_warp/_src/ray_test.py
Outdated
|
||
def test_ray_capsule(self): | ||
"""Tests ray<>capsule matches MuJoCo.""" | ||
m, d, _, _ = test_util.fixture("ray.xml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mjm, mjd, m, d = ...
mujoco_warp/_src/ray_test.py
Outdated
|
||
def test_ray_box(self): | ||
"""Tests ray<>box matches MuJoCo.""" | ||
m, d, _, _ = test_util.fixture("ray.xml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mjm, mjd, m, d = ...
_assert_eq(dist_np, mj_dist, "dist") | ||
|
||
def test_ray_mesh(self): | ||
"""Tests ray<>mesh matches MuJoCo.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mjm, mjd, m, d = ...
mujoco_warp/_src/ray_test.py
Outdated
|
||
def test_ray_geomgroup(self): | ||
"""Tests ray geomgroup filter.""" | ||
m, d, _, _ = test_util.fixture("ray.xml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mjm, mjd, m, d = ...
mujoco_warp/_src/ray_test.py
Outdated
|
||
def test_ray_flg_static(self): | ||
"""Tests ray flg_static filter.""" | ||
m, d, _, _ = test_util.fixture("ray.xml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mjm, mjd, m, d = ...
mujoco_warp/_src/ray_test.py
Outdated
|
||
def test_ray_bodyexclude(self): | ||
"""Tests ray bodyexclude filter.""" | ||
m, d, _, _ = test_util.fixture("ray.xml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mjm, mjd, m, d = ...
dist_np = dist.numpy()[0][0] | ||
_assert_eq(geomid_np, -1, "geom_id") | ||
_assert_eq(dist_np, -1, "dist") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a test for transparent geoms. mjx reference: https://github.com/google-deepmind/mujoco/blob/8e7457d7c6c1cbda42ec39d2297d4f90b3396040/mjx/mujoco/mjx/_src/ray_test.py#L238
mujoco_warp/_src/types.py
Outdated
@@ -576,6 +583,7 @@ class Model: | |||
geom_condim: contact dimensionality (1, 3, 4, 6) (ngeom,) | |||
geom_bodyid: id of geom's body (ngeom,) | |||
geom_dataid: id of geom's mesh/hfield; -1: none (ngeom,) | |||
geom_group: geom group inclusion/exclusion mask (ngeom, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(ngeom,)
mujoco_warp/_src/types.py
Outdated
@@ -788,6 +801,8 @@ class Model: | |||
mesh_vertadr: wp.array(dtype=wp.int32, ndim=1) | |||
mesh_vertnum: wp.array(dtype=wp.int32, ndim=1) | |||
mesh_vert: wp.array(dtype=wp.vec3, ndim=1) | |||
mesh_faceadr: wp.array(dtype=wp.int32, ndim=1) | |||
mesh_face: wp.array(dtype=wp.int32, ndim=2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wp.array(dtype=wp.vec3i, ndim=1)
triangle.v2 = m.mesh_vert[vert_start + v_idx.z] | ||
|
||
# Calculate intersection | ||
dist = _ray_triangle(triangle, pnt, vec, basis) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw Warp has BVH accelerated versions of these routines: https://nvidia.github.io/warp/modules/functions.html#warp.mesh_query_ray, also distance and sign queries: https://nvidia.github.io/warp/modules/functions.html#warp.mesh_query_point.
I don't understand why the ray unit tests fail on github. They succeed on my Linux and on my Windows machine. |
@nvtw Is it a CPU vs GPU issue? Do you have a way to force CPU on one of your dev machines and rerun the tests? |
@erikfrey is it ok to add these .stl files? it looks like they are from https://github.com/google-deepmind/mujoco/tree/main/mjx/mujoco/mjx/test_data/meshes. the alternative would be to define meshes directly in xml? |
# Conflicts: # mujoco_warp/_src/io.py
request that would be useful for the touch sensor implementation #213:
here is the mujoco reference for here is the mujoco reference for thanks! |
@thowell yes it's OK to bring those meshes in. |
# Conflicts: # mujoco_warp/_src/io.py # mujoco_warp/_src/types.py
Should be all done now |
mujoco_warp/_src/io.py
Outdated
@@ -127,17 +127,29 @@ def put_model(mjm: mujoco.MjModel) -> types.Model: | |||
tile_beg = tile_corners[i] | |||
tile_end = mjm.nv if i == len(tile_corners) - 1 else tile_corners[i + 1] | |||
tiles.setdefault(tile_end - tile_beg, []).append(tile_beg) | |||
|
|||
# Handle empty tiles case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this block of code still utilized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this file needed?
@nvtw please take a look at the comment about the block of code in io.py and the comment about the mesh file. thanks! |
See #94