Implementation:Google deepmind Mujoco MJZ Decoder
| Knowledge Sources | |
|---|---|
| Domains | File I/O, Archive Processing |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Decodes MJZ archive files (zip-based MuJoCo model bundles) by providing a resource provider that lazily extracts individual files from the archive.
Description
mjz_decoder.cc implements the ZipArchiveProvider class, a custom mjpResourceProvider that reads MuJoCo model files from within zip archives. The provider takes a byte buffer containing the zip data, initializes a miniz archive reader, and builds an index of contained files. It implements root model detection logic: first looking for an XML file matching the archive name, then falling back to a name including the parent directory. The SetError helper function provides printf-style error formatting. File contents are extracted on demand through the MuJoCo resource provider interface.
Usage
Registered as a resource provider when loading .mjz files in MuJoCo Studio or other applications. The decoder enables loading of bundled MuJoCo models that package the XML specification together with mesh, texture, and other asset files in a single zip archive.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/experimental/mjz/mjz_decoder.cc
- Lines: 1-213
Key Functions
static void SetError(char* error, int error_sz, const char* format, ...);
class ZipArchiveProvider : public mjpResourceProvider {
ZipArchiveProvider(std::string name, const void* buffer, int nbuffer, char* error, int error_sz);
// Lazily reads files from zip archive via miniz
// Root model detection: archive_name/archive_name.xml or archive_name/parent/archive_name.xml
};
Import
#include <miniz_zip.h>
#include <mujoco/mjspec.h>
#include <mujoco/mujoco.h>
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| name | std::string | Yes | Name of the archive (used for root model lookup) |
| buffer | const void* | Yes | Raw zip archive bytes |
| nbuffer | int | Yes | Size of the archive buffer in bytes |
| error | char* | No | Buffer for error messages |
| error_sz | int | No | Size of the error buffer |
Outputs
| Name | Type | Description |
|---|---|---|
| ZipArchiveProvider | mjpResourceProvider | Resource provider for lazily reading files from the archive |
| root_model_ | std::string | Path to the root XML model within the archive |