Implementation:Google deepmind Mujoco MJWarp Ray
| Knowledge Sources | |
|---|---|
| Domains | Physics_Simulation, GPU_Computing, NVIDIA_Warp |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
MJWarp Ray implements GPU-accelerated ray casting against all MuJoCo geometry types including meshes with BVH acceleration.
Description
This module provides ray intersection testing for all supported geometry types: plane, sphere, capsule, ellipsoid, cylinder, box, height field, and mesh. It includes both individual ray-geometry functions and batch ray-casting kernels that test rays against all scene geometries. The module supports BVH-accelerated mesh and flex ray queries, geom group and body exclusion filtering, and both closest-hit and any-hit query modes. Ray results include hit distance and surface normal at the intersection point.
Usage
Used by the sensor system for rangefinder sensors, by the renderer for ray-traced rendering, and by the SDF collision module for mesh-based signed distance evaluation. The ray and rays functions are the primary batch entry points.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: mjx/mujoco/mjx/third_party/mujoco_warp/_src/ray.py
- Lines: 1-1292
Key Functions
# Batch ray-casting entry points
def ray(...) # Single ray against all geoms
def rays(...) # Multiple rays against all geoms
# Per-geometry ray intersection
def ray_plane(pos, mat, size, pnt, vec) -> Tuple[float, wp.vec3]
def ray_sphere(pos, dist_sqr, pnt, vec) -> Tuple[float, wp.vec3]
def ray_capsule(pos, mat, size, pnt, vec) -> Tuple[float, wp.vec3]
def ray_ellipsoid(pos, mat, size, pnt, vec) -> Tuple[float, wp.vec3]
def ray_cylinder(pos, mat, size, pnt, vec) -> Tuple[float, wp.vec3]
def ray_box(pos, mat, size, pnt, vec) -> Tuple[float, vec6, wp.vec3]
def ray_hfield(...)
def ray_mesh(...)
# BVH-accelerated ray queries
def ray_mesh_with_bvh(...)
def ray_mesh_with_bvh_anyhit(...)
def ray_flex_with_bvh(...)
# Generic ray dispatcher
def ray_geom(pos, mat, size, pnt, vec, geomtype) -> Tuple[float, wp.vec3]
# Utility
def _ray_map(pos, mat, pnt, vec) -> Tuple[wp.vec3, wp.vec3]
def _ray_eliminate(...) -> bool
Import
from mujoco.mjx.third_party.mujoco_warp._src.ray import ray
from mujoco.mjx.third_party.mujoco_warp._src.ray import rays
from mujoco.mjx.third_party.mujoco_warp._src.ray import ray_mesh_with_bvh
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| m | Model | Yes | Warp model with geometry definitions and mesh data |
| d | Data | Yes | Warp simulation data with geom transforms |
| pnt | wp.vec3 | Yes | Ray origin point |
| vec | wp.vec3 | Yes | Ray direction vector |
| geomgroup | vec6 | No | Geometry group filter flags |
| bodyexclude | int | No | Body ID to exclude from ray testing |
Outputs
| Name | Type | Description |
|---|---|---|
| dist | float | Distance to nearest intersection (-1 if no hit) |
| geomid | int | ID of the intersected geometry |
| normal | wp.vec3 | Surface normal at intersection point |