Skip to content

Add height field ray intersection support to MJX ray functions #2637

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

achaljhawar
Copy link

Description

This PR adds support for height field ray intersection testing to the MJX ray intersection functions. This feature enables depth rendering in environments with terrain (height fields), which is particularly useful for robot locomotion tasks.

Motivation

The mjx.ray function is essential for getting depth images in MJX and is used by the rangefinder sensor, but it currently doesn't support hfield geoms. This PR ports the mj_rayHfield function from MuJoCo to MJX to enable ray intersection tests with height fields.

Implementation Details

  • Added ray_hfield function to calculate ray intersection with height fields
  • Created _ray_hfield_wrapper to adapt the function to the expected interface
  • Updated _RAY_FUNC dictionary to include height field geoms
  • Modified the ray function to handle height field geoms similar to mesh geoms
  • Updated ray_geom to handle height field cases appropriately

The implementation follows the ray marching approach from the C implementation but adapts it to JAX's functional programming model with vectorized operations where possible.

Testing

Tested with height field environments to ensure correct depth values when using rangefinder sensors over terrain.

Fixes #2155

Copy link

google-cla bot commented May 17, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@achaljhawar
Copy link
Author

I have signed the cla

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MJX ray has no implementation for hfield geoms
2 participants