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 Engine Collision SDF

From Leeroopedia
Revision as of 12:45, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Google_deepmind_Mujoco_Engine_Collision_SDF.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Physics Simulation, Collision Detection, Signed Distance Fields
Last Updated 2026-02-15 04:00 GMT

Overview

Implements signed distance field (SDF) based collision detection for mesh, heightfield, and plugin-defined geometries in MuJoCo.

Description

This module provides collision detection using signed distance fields (SDFs), supporting both precomputed mesh SDFs stored as octree-interpolated scalar fields, and plugin-defined SDFs for custom geometry types. The core functions mjc_distance and mjc_gradient evaluate the SDF value and its spatial gradient at any point in space, using trilinear interpolation within octree leaf nodes for mesh SDFs, or delegating to plugin callbacks for user-defined geometries. The collision algorithm iteratively walks contact candidates along the SDF gradient via stepGradient to find surface contact points. Helper functions like boxProjection handle point projection onto bounding boxes and findOct navigates the octree structure.

Usage

Called by the collision driver when one or both geometries are of SDF type (including mesh SDFs and heightfield SDFs). The entry points mjc_SDF, mjc_MeshSDF, and mjc_HFieldSDF are registered in the collision function dispatch table.

Code Reference

Source Location

Key Functions

// Project point onto bounding box, return distance
mjtNum boxProjection(mjtNum point[3], const mjtNum box[6]);

// Evaluate octree-based SDF distance at a point
mjtNum oct_distance(const mjModel* m, const mjtNum p[3], int meshid);

// Evaluate octree-based SDF gradient at a point
void oct_gradient(const mjModel* m, mjtNum grad[3], const mjtNum point[3], int meshid);

// General SDF distance evaluation (handles both mesh and plugin SDFs)
mjtNum mjc_distance(const mjModel* m, const mjData* d, const mjSDF* s, const mjtNum x[3]);

// General SDF gradient evaluation
void mjc_gradient(const mjModel* m, const mjData* d, const mjSDF* s,
                  mjtNum gradient[3], const mjtNum x[3]);

// SDF collision entry points
int mjc_SDF(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, mjtNum margin);
int mjc_MeshSDF(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, mjtNum margin);
int mjc_HFieldSDF(const mjModel* m, const mjData* d, mjContact* con, int g1, int g2, mjtNum margin);

Import

#include "engine/engine_collision_sdf.h"

I/O Contract

Inputs

Name Type Required Description
m const mjModel* Yes Physics model with mesh and SDF octree data
d const mjData* Yes Simulation state with geometry poses
g1 int Yes Index of first geometry
g2 int Yes Index of second geometry (SDF type)
margin mjtNum Yes Contact margin distance

Outputs

Name Type Description
con mjContact* Contact array populated with SDF-computed contact points
return value int Number of contacts generated

Related Pages

Page Connections

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