Implementation:Google deepmind Mujoco MjSpec Header
| Knowledge Sources | |
|---|---|
| Domains | C API, Model Specification, Data Structures, Procedural Generation |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
C header file that defines the MuJoCo model specification API (mjSpec) with types for programmatic model construction, mesh generation, and inertia inference.
Description
mjspec.h provides the C/C++ API for constructing MuJoCo models programmatically rather than from XML files. It defines string and array handle types (mjString, mjStringVec, mjIntVec, mjFloatVec, mjDoubleVec, mjByteVec) that are opaque in C but map to std::string and std::vector types in C++. Key enumerations include mjtGeomInertia (VOLUME, SHELL), mjtMeshInertia (CONVEX, EXACT, LEGACY, SHELL), and mjtMeshBuiltin (procedural mesh types including SPHERE, HEMISPHERE, CONE, SUPERSPHERE, SUPERTORUS). The header bridges the C and C++ APIs using conditional compilation.
Usage
This header is used when programmatically constructing or modifying MuJoCo models at runtime, for procedural scene generation, and for importing models from formats other than MJCF. It enables creating bodies, joints, geoms, and actuators through code rather than XML specification.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: include/mujoco/mjspec.h
- Lines: 1-800
Key Functions
// String and array handle types (C++ / C dual definitions)
#ifdef __cplusplus
using mjString = std::string;
using mjStringVec = std::vector<std::string>;
using mjIntVec = std::vector<int>;
using mjFloatVec = std::vector<float>;
using mjDoubleVec = std::vector<double>;
using mjByteVec = std::vector<std::byte>;
#else
typedef void mjString;
typedef void mjIntVec;
// ... opaque types in C
#endif
// Inertia inference types
typedef enum mjtGeomInertia_ {
mjINERTIA_VOLUME = 0, // mass distributed in the volume
mjINERTIA_SHELL, // mass distributed on the surface
} mjtGeomInertia;
// Procedural mesh types
typedef enum mjtMeshBuiltin_ {
mjMESH_BUILTIN_NONE = 0,
mjMESH_BUILTIN_SPHERE,
mjMESH_BUILTIN_HEMISPHERE,
mjMESH_BUILTIN_CONE,
mjMESH_BUILTIN_SUPERSPHERE,
mjMESH_BUILTIN_SUPERTORUS,
...
} mjtMeshBuiltin;
Import
#include <mujoco/mjspec.h>
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (header definitions) | N/A | N/A | No runtime inputs; provides type definitions for model specification API |
Outputs
| Name | Type | Description |
|---|---|---|
| mjSpec | struct | Model specification structure for programmatic model construction |
| mjtGeomInertia | enum | Inertia inference mode (volume or shell distribution) |
| mjtMeshInertia | enum | Mesh inertia computation method (convex, exact, legacy, shell) |
| mjtMeshBuiltin | enum | Procedural mesh generation types (sphere, hemisphere, cone, supersphere, supertorus) |
| Handle types | typedef | String and array handle types for cross-language compatibility |
Related Pages
- Google_deepmind_Mujoco_MjModel_Header - Model data structure header included by mjspec.h
- Google_deepmind_Mujoco_MjTnum_Header - Numeric type definitions included by mjspec.h
- Google_deepmind_Mujoco_API_References_Header - Auto-generated API reference enumerations