Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Google deepmind Mujoco MJWarp Collision SDF

From Leeroopedia
Knowledge Sources
Domains Physics_Simulation, GPU_Computing, NVIDIA_Warp
Last Updated 2026-02-15 04:00 GMT

Overview

MJWarp Collision SDF implements Signed Distance Field based collision detection with gradient descent optimization on the GPU.

Description

This module provides SDF-based collision detection for geometry pairs that use signed distance fields, including sphere, box, ellipsoid, and user-defined SDF plugins. It defines Warp structs for OptimizationParams, AABB, VolumeData, and MeshData, and implements gradient descent optimization to find contact points on SDF surfaces. The module supports octree-based volume SDF sampling and mesh-based SDF via ray casting, and uses Halton sequences for initial sampling points.

Usage

Invoked by the collision driver when geometry pairs involve SDF-type geometries or when native CCD is disabled for certain convex pairs. The sdf_narrowphase function is the main entry point.

Code Reference

Source Location

Key Functions

# Warp structs
@wp.struct
class OptimizationParams:
    rel_mat: wp.mat33; rel_pos: wp.vec3; attr1: wp.vec3; attr2: wp.vec3

@wp.struct
class AABB:
    min: wp.vec3; max: wp.vec3

@wp.struct
class VolumeData:
    center: wp.vec3; half_size: wp.vec3; oct_aabb: ...; oct_child: ...; oct_coeff: ...

@wp.struct
class MeshData:
    nmeshface: int; mesh_vertadr: ...; mesh_vert: ...; ...

# Primary entry point
def sdf_narrowphase(m: Model, d: Data, ctx: CollisionContext)

# SDF evaluation
def sdf(type, p, attr, sdf_type, volume_data, mesh_data) -> float
def sdf_grad(type, p, attr, sdf_type, volume_data, mesh_data) -> wp.vec3

# Built-in SDF functions
def sphere(p, size) -> float
def box(p, size) -> float
def ellipsoid(p, size) -> float

# Optimization
def gradient_descent(...)
def gradient_step(...)
def clearance(...)

Import

from mujoco.mjx.third_party.mujoco_warp._src.collision_sdf import sdf_narrowphase
from mujoco.mjx.third_party.mujoco_warp._src.collision_sdf import sdf
from mujoco.mjx.third_party.mujoco_warp._src.collision_sdf import sdf_grad

I/O Contract

Inputs

Name Type Required Description
m Model Yes Warp model with SDF geometry data and plugin configurations
d Data Yes Warp simulation data with current geom transforms
ctx CollisionContext Yes Collision context with candidate pairs from broadphase

Outputs

Name Type Description
d.contact Contact SDF-based contacts with positions, normals, and penetration depths
d.nacon wp.array Updated active contact count

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment