Implementation:Google deepmind Mujoco User API
| Knowledge Sources | |
|---|---|
| Domains | Physics Simulation, Model Specification API |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Implements the public C API for creating, parsing, compiling, and manipulating MuJoCo model specifications (mjSpec).
Description
user_api.cc is the primary entry point for the MuJoCo specification API, providing functions to create models (mj_makeSpec), copy models (mj_copySpec), parse model files (mj_parse), and compile specifications into runtime models. It bridges the C-facing API with the internal C++ mjCModel class and manages a global asset cache (default 500MB) for resource reuse. The file handles multiple file formats by dispatching to the appropriate parser based on file extension or content type.
Usage
Used whenever a user creates or loads a MuJoCo model programmatically through the C API, including model creation, parsing from XML/URDF, compilation, and recompilation workflows.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/user/user_api.cc
- Lines: 1-1960
Key Functions
mjSpec* mj_makeSpec();
mjSpec* mj_copySpec(const mjSpec* s);
mjSpec* mj_parse(const char* filename, const char* content_type,
const mjVFS* vfs, char* error, int error_sz);
Import
#include "user/user_api.h"
#include <mujoco/mujoco.h>
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| filename | const char* | Yes (for mj_parse) | Path to model file (XML, URDF, or other supported format) |
| content_type | const char* | No | MIME type hint for parsing (e.g., "text/xml") |
| vfs | const mjVFS* | No | Virtual file system for resource lookups |
| error | char* | No | Buffer for error messages |
| error_sz | int | No | Size of error buffer |
Outputs
| Name | Type | Description |
|---|---|---|
| mjSpec* | mjSpec* | Pointer to created or parsed model specification, or NULL on failure |
| mjModel* | mjModel* | Compiled runtime model (from mj_compile) |