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 mjCModel Compile

From Leeroopedia
Knowledge Sources
Domains Model_IO, Physics_Simulation, Compilation
Last Updated 2026-02-15 06:00 GMT

Overview

Concrete internal tool for compiling MuJoCo specification trees into runtime models.

Description

The mjCModel::Compile method (exposed via mj_compile) transforms the parsed specification tree into a flat mjModel. This is the core compilation function that processes the entire model: resolves references, computes inertias, builds collision structures, packs arrays, and allocates the final model buffer.

Usage

Called internally by mj_loadXML. Not typically called directly, but can be invoked through the mj_compile C API for programmatic model construction via mjSpec.

Code Reference

Source Location

  • Repository: mujoco
  • File: src/user/user_model.cc
  • Lines: 4510-4583

Signature

// Internal C++ method
mjModel* mjCModel::Compile(const mjVFS* vfs, mjModel** m);

// Public C API wrapper
mjModel* mj_compile(mjSpec* s, const mjVFS* vfs);

Import

#include <mujoco/mujoco.h>
// mj_compile is the public C API entry point

I/O Contract

Inputs

Name Type Required Description
vfs const mjVFS* No Virtual file system for resource loading (NULL for disk)
m mjModel** No Pre-allocated model to reuse (NULL to allocate new)

Outputs

Name Type Description
return mjModel* Fully compiled runtime model (NULL on failure)

Usage Examples

#include <mujoco/mujoco.h>

// Programmatic model construction
mjSpec* spec = mj_makeSpec();
mjsBody* body = mjs_addBody(mjs_findBody(spec, "world"), NULL);
// ... add joints, geoms, etc. to spec ...

// Compile the spec into a model
mjModel* m = mj_compile(spec, NULL);
if (!m) {
    printf("Compilation error: %s\n", mjs_getError(spec));
}

mj_deleteSpec(spec);

Related Pages

Implements Principle

Page Connections

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