Implementation:Google deepmind Dm control Blender Exporter
| Knowledge Sources | |
|---|---|
| Domains | Blender, MuJoCo, Export |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
The Blender MuJoCo Exporter is a Blender 3.4+ addon that exports Blender scenes to MuJoCo's MJCF XML format with associated mesh assets.
Description
The ExportMjcf class extends bpy.types.Operator and ExportHelper to integrate into Blender's File > Export menu. On execution, it uses the context_settings_cacher context manager to temporarily set OBJECT mode and reset all armatures to REST pose, ensuring consistent geometry export. It then calls apply_scale() to apply scale transforms on all objects for affine correctness.
The export workflow builds a list of visible Blender objects via blender_scene.map_blender_tree, generates the MJCF worldbody tree via mujoco_scene.export_to_xml, and generates the asset tree (meshes and materials) via mujoco_assets.export_to_xml. Compiler options for small feature meshes are added (boundmass and boundinertia), and the complete XML document is written using minidom.toprettyxml.
Export settings include toggles for armature freejoint (whether to add a freejoint to the armature body) and mesh modifier application (whether to apply Blender mesh modifiers during export). The register() and unregister() functions handle the Blender addon lifecycle.
Usage
Install this addon in Blender 3.3.1 or later. Access it from File > Export > MuJoCo (.xml). Configure export settings (armature freejoint, apply modifiers) in the export dialog before saving. The exported XML and mesh files can be loaded directly in MuJoCo.
Code Reference
Source Location
- Repository: Google_deepmind_Dm_control
- File: dm_control/blender/mujoco_exporter/__init__.py
- Lines: 1-170
Signature
@contextlib.contextmanager
def context_settings_cacher(context: bpy.types.Context):
"""Preserves the pose of exported objects and the scene mode."""
def apply_scale():
"""Applies scale transforms to all selected objects."""
class ExportMjcf(bpy.types.Operator, ExportHelper):
bl_idname = 'export_scene.mjcf'
bl_label = 'Export MJCF'
filename_ext = '.xml'
armature_freejoint: bpy.props.BoolProperty(...)
apply_mesh_modifiers: bpy.props.BoolProperty(...)
def _export_mjcf(self, context: bpy.types.Context) -> None:
def execute(self, context: bpy.types.Context):
def register():
def unregister():
Import
# Used as a Blender addon; registered via register() at plugin load time
from dm_control.blender.mujoco_exporter import ExportMjcf
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| context | bpy.types.Context | Yes | Blender scene context containing objects to export |
| armature_freejoint | bool | No | Whether to add a freejoint to armature bodies (default: False) |
| apply_mesh_modifiers | bool | No | Whether to apply Blender mesh modifiers before export (default: False) |
| filepath | str | Yes | Output path for the MJCF XML file (provided by ExportHelper) |
Outputs
| Name | Type | Description |
|---|---|---|
| MJCF XML file | file | MuJoCo-compatible XML scene description |
| .msh mesh files | files | Binary mesh files for each material-mesh pair, saved alongside the XML |
Usage Examples
# In Blender's Python console or script:
import bpy
# Register the addon
from dm_control.blender.mujoco_exporter import register
register()
# Export the current scene
bpy.ops.export_scene.mjcf(
filepath='/path/to/output/scene.xml',
armature_freejoint=True,
apply_mesh_modifiers=True
)