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 Driver

From Leeroopedia
Knowledge Sources
Domains Physics Simulation, Collision Detection, Broadphase
Last Updated 2026-02-15 04:00 GMT

Overview

Orchestrates the entire collision detection pipeline in MuJoCo, from broadphase sweep-and-prune through narrow-phase geometry pair testing to contact generation.

Description

This is the central collision detection driver that coordinates broadphase and narrow-phase collision. It defines the mjCOLLISIONFUNC dispatch table that maps every pair of geometry types to the appropriate collision function. The broadphase uses a sweep-and-prune (SAP) algorithm (mj_broadphase) with axis-aligned bounding boxes to rapidly cull non-interacting pairs, followed by bitmask and sphere filtering. The driver then dispatches to specialized narrow-phase functions for each geometry pair type. It also handles flex (soft-body) collisions, heightfield collisions, element-level and vertex-level collision testing, and contact parameter assignment.

Usage

The top-level function mj_collision is called during the forward dynamics pipeline after kinematics have been computed. It populates the mjData contact array which is subsequently used by constraint generation.

Code Reference

Source Location

Key Functions

// Main collision entry point called during forward dynamics
void mj_collision(const mjModel* m, mjData* d);

// Broadphase: sweep-and-prune to find candidate body-field pairs
int mj_broadphase(const mjModel* m, mjData* d, int* bfpair, int maxpair);

// Collide a specific pair of geoms
void mj_collideGeoms(const mjModel* m, mjData* d, int g1, int g2);

// Collide a geom pair with custom parameters
void mj_collideGeomPair(const mjModel* m, mjData* d, int g1, int g2,
                        int merged, mjtNum margin, mjtNum gap,
                        int condim, const mjtNum* solref, const mjtNum* solimp,
                        const mjtNum* friction);

// OBB overlap test for oriented bounding boxes
int mj_collideOBB(const mjtNum aabb1[6], const mjtNum aabb2[6],
                  const mjtNum xpos1[3], const mjtNum xmat1[9],
                  const mjtNum xpos2[3], const mjtNum xmat2[9],
                  mjtNum margin);

// BVH tree collision traversal
void mj_collideTree(const mjModel* m, mjData* d, int bf1, int bf2,
                    int self, mjtNum margin);

// Flex collision functions
void mj_collidePlaneFlex(const mjModel* m, mjData* d, int g, int f);
void mj_collideFlexInternal(const mjModel* m, mjData* d, int f);
void mj_collideFlexSAP(const mjModel* m, mjData* d, int f);
void mj_collideGeomElem(const mjModel* m, mjData* d, int g, int f, int e);
void mj_collideElems(const mjModel* m, mjData* d, int f1, int e1, int f2, int e2);
void mj_collideElemVert(const mjModel* m, mjData* d, int f, int e, int v);

Import

#include "engine/engine_collision_driver.h"

I/O Contract

Inputs

Name Type Required Description
m const mjModel* Yes Physics model with all geometry, body, and collision parameters
d mjData* Yes Simulation state with computed kinematics and AABB data

Outputs

Name Type Description
d->contact mjContact[] Array of detected contacts stored in the arena
d->ncon int Number of contacts detected

Related Pages

Page Connections

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