Skip to main content
Methods for loading and swapping models at runtime.

loadScene(newConfig)

Load a new model, replacing the current scene entirely.
SceneConfig
required
New scene configuration. See Loading Models for all fields.
Returns: Promise<void> — resolves when the new model is loaded and ready. This method:
  1. Fetches the new model files
  2. Applies XML patches and injects scene objects
  3. Compiles the model with mj_loadXML
  4. Creates new model/data objects
  5. Rebuilds the scene graph (SceneRenderer will re-render)
  6. Fires the onReady callback with the updated API

loadFromFiles(files, options?)

Load MJCF or URDF from browser-selected files. Folder uploads preserve paths from webkitRelativePath; flat uploads fall back to matching mesh/texture assets by basename.
FileList | File[]
required
Browser-selected MJCF/URDF files and referenced assets.
LoadFromFilesOptions
Optional sceneFile, environmentFiles, homeJoints, xmlPatches, sceneObjects, and onReset settings.

Composable Environments

Use environmentFiles when a robot should run inside a reusable MJCF environment. The loader merges the environment XML’s assets and physics sections into the entry model before MuJoCo compiles it.
This works well with Gaussian splats: keep the .spz as a visual-only layer, and add a paired scene.xml collision/physics layer only when the splat-backed workflow needs contact geometry.

addBody(body), removeBody(name), recompile(patches?)

Edit the current scene configuration and recompile through MuJoCo. This is a model reload, not an in-place mutation of compiled mjModel memory.

Example: Model Switcher

Utility Functions

These standalone functions are exported for advanced use cases (e.g., building custom loaders).

getName(model, address)

Read a null-terminated C string from the WASM model’s name buffer.

find*ByName(model, name)

Look up element indices by name. All return -1 if not found.

loadScene(mujoco, config, onProgress?)

The standalone scene loader function (used internally by the provider).