Implementation:Google deepmind Mujoco MJWarp BVH
| Knowledge Sources | |
|---|---|
| Domains | Physics_Simulation, GPU_Computing, NVIDIA_Warp |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
MJWarp BVH implements Bounding Volume Hierarchy construction and refitting for GPU-accelerated collision broadphase and rendering in MuJoCo Warp.
Description
This module provides GPU-based BVH (Bounding Volume Hierarchy) construction and dynamic refitting for scene geometry, meshes, height fields, and flex elements. It computes axis-aligned bounding boxes (AABBs) for various geometry types (box, sphere, capsule, plane, ellipsoid, cylinder) and builds hierarchical spatial acceleration structures used by the collision detection and ray-casting subsystems. The module also handles flex element BVH construction including vertex normal computation and shell/side assembly.
Usage
Called during the rendering and collision pipeline to build and refit BVH structures when geometry transforms change. The primary entry point refit_bvh is invoked each step to update the dynamic BVH in the render context.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: mjx/mujoco/mjx/third_party/mujoco_warp/_src/bvh.py
- Lines: 1-1013
Key Functions
# Primary entry point - refits dynamic BVH structures
def refit_bvh(m: Model, d: Data, rc: RenderContext)
# Scene BVH construction and refitting
def build_scene_bvh(m: Model, d: Data, rc: RenderContext)
def refit_scene_bvh(m: Model, d: Data, rc: RenderContext)
# Mesh and height field BVH
def build_mesh_bvh(...)
def build_hfield_bvh(...)
# Flex element BVH
def build_flex_bvh(...)
def refit_flex_bvh(m: Model, d: Data, rc: RenderContext)
# Warp functions for computing AABB bounds per geometry type
def _compute_box_bounds(pos, rot, size) -> Tuple[wp.vec3, wp.vec3]
def _compute_sphere_bounds(pos, rot, size) -> Tuple[wp.vec3, wp.vec3]
def _compute_capsule_bounds(pos, rot, size) -> Tuple[wp.vec3, wp.vec3]
def _compute_plane_bounds(pos, rot, size) -> Tuple[wp.vec3, wp.vec3]
def _compute_ellipsoid_bounds(pos, rot, size) -> Tuple[wp.vec3, wp.vec3]
def _compute_cylinder_bounds(pos, rot, size) -> Tuple[wp.vec3, wp.vec3]
Import
from mujoco.mjx.third_party.mujoco_warp._src.bvh import refit_bvh
from mujoco.mjx.third_party.mujoco_warp._src.bvh import build_scene_bvh
from mujoco.mjx.third_party.mujoco_warp._src.bvh import build_mesh_bvh
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| m | Model | Yes | Warp model containing geometry definitions, sizes, and mesh data |
| d | Data | Yes | Warp simulation data with current geom positions and orientations |
| rc | RenderContext | Yes | Render context holding BVH arrays to be built or refitted |
Outputs
| Name | Type | Description |
|---|---|---|
| rc.scene_bvh | wp.Bvh | Updated scene-level BVH acceleration structure |
| rc.mesh_bvh | wp.Bvh | Per-mesh BVH for triangle-level queries |
| rc.flex_bvh | wp.Bvh | Flex element BVH for deformable body queries |