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 WASM Bindings

From Leeroopedia
Knowledge Sources
Domains WebAssembly, Physics Simulation, JavaScript Bindings
Last Updated 2026-02-15 04:00 GMT

Overview

Auto-generated Emscripten/Embind bindings that expose the MuJoCo C API to JavaScript/WebAssembly environments.

Description

bindings.cc is a large (13448 lines) auto-generated file that provides complete Emscripten Embind bindings for the MuJoCo library. It exposes MuJoCo structs (mjModel, mjData, mjSpec, etc.), enums, and functions to JavaScript through typed wrappers. The file defines MJMODEL_ACCESSORS macros for generating accessor methods for all MuJoCo object types (actuator, body, camera, equality, geom, joint, light, material, mesh, numeric, pair, sensor, site, skin, tendon, texture), and uses custom Embind value types (NumberOrString, NumberArray, String, StringOrNull) for type-safe JavaScript interop.

Usage

Compiled with Emscripten as part of the MuJoCo WASM build to produce the mujoco_wasm.js module that enables MuJoCo physics simulation in web browsers.

Code Reference

Source Location

Key Functions

namespace mujoco::wasm {

EMSCRIPTEN_DECLARE_VAL_TYPE(NumberOrString);
EMSCRIPTEN_DECLARE_VAL_TYPE(NumberArray);
EMSCRIPTEN_DECLARE_VAL_TYPE(String);
EMSCRIPTEN_DECLARE_VAL_TYPE(StringOrNull);

#define MJMODEL_ACCESSORS \
  X_ACCESSOR(ACTUATOR, Actuator, mjOBJ_ACTUATOR, actuator, nu) \
  X_ACCESSOR(BODY, Body, mjOBJ_BODY, body, nbody) \
  // ... all MuJoCo object types
}

Import

#include <emscripten.h>
#include <emscripten/bind.h>
#include <emscripten/val.h>
#include <mujoco/mujoco.h>
#include "wasm/unpack.h"

I/O Contract

Inputs

Name Type Required Description
JavaScript values emscripten::val Yes JavaScript objects, arrays, and primitives passed to MuJoCo functions
Model XML string Yes MJCF XML string for model loading in the browser

Outputs

Name Type Description
Embind module JS module Complete MuJoCo API exposed to JavaScript
Typed memory views TypedArray Direct access to MuJoCo data arrays from JavaScript

Related Pages

Page Connections

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