Implementation:Google deepmind Dm control MuJoCo Assets Export
| Knowledge Sources | |
|---|---|
| Domains | Blender, MuJoCo, Export |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
The mujoco_assets module handles the export of Blender mesh geometry and material definitions into MuJoCo-compatible asset representations, including binary .msh mesh files and XML asset elements.
Description
The MujocoMesh class extracts vertices, normals, UV coordinates, and face indices from a Blender mesh filtered by material index, enabling per-material mesh splitting. MuJoCo requires single-material-per-mesh, so a Blender mesh with multiple materials is split into separate MujocoMesh instances. For two-sided materials (where backface culling is disabled), geometry is duplicated with flipped normals and reversed winding order.
The save() method serializes mesh data into MuJoCo's binary .msh format using struct.pack with a header of 4 integers (vertex count, normal count, texcoord count, face count) followed by float arrays for vertex positions, normals, UV coordinates, and integer face indices.
mesh_asset_builder() creates XML <mesh> elements for each valid material-mesh pair. material_asset_builder() converts Blender material properties (diffuse color, specular intensity, roughness, metallic) to MuJoCo material XML attributes, inverting roughness to shininess and mapping metallic to reflectance. The top-level export_to_xml() iterates over all scene objects, deduplicates meshes and materials, optionally applies mesh modifiers, and assembles the complete <asset> XML element.
Usage
Called by the Blender Exporter addon's _export_mjcf method. Not typically used directly, but rather as part of the Blender-to-MuJoCo export pipeline.
Code Reference
Source Location
- Repository: Google_deepmind_Dm_control
- File: dm_control/blender/mujoco_exporter/mujoco_assets.py
- Lines: 1-175
Signature
class MujocoMesh:
def __init__(self, mesh: bpy.types.Mesh, material_idx: int, two_sided: bool):
def save(self, filepath: str) -> None:
def mesh_asset_builder(
doc: minidom.Document,
mesh: bpy.types.Mesh,
materials: Sequence[bpy.types.Material],
folder: str,
) -> Sequence[minidom.Element]:
def clip01(value):
def material_asset_builder(
doc: minidom.Document, mat: bpy.types.Material
) -> minidom.Element:
def export_to_xml(
doc: minidom.Document,
objects: Sequence[blender_scene.ObjectRef],
folder: str,
apply_mesh_modifiers: bool,
) -> minidom.Element:
Import
from dm_control.blender.mujoco_exporter import mujoco_assets
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| doc | minidom.Document | Yes | XML document used for creating elements |
| objects | Sequence[ObjectRef] | Yes | List of Blender scene objects to export |
| folder | str | Yes | Output directory for mesh .msh files
|
| apply_mesh_modifiers | bool | Yes | Whether to apply Blender mesh modifiers before export |
Outputs
| Name | Type | Description |
|---|---|---|
| return | minidom.Element | An <asset> XML element containing <mesh> and <material> children
|
| .msh files | binary files | Binary mesh files written to the output folder |
Usage Examples
from xml.dom import minidom
from dm_control.blender.mujoco_exporter import mujoco_assets
xml_doc = minidom.Document()
# Export all assets from visible Blender objects
asset_el = mujoco_assets.export_to_xml(
doc=xml_doc,
objects=blender_objects,
folder='/path/to/output/',
apply_mesh_modifiers=True,
)
# The asset_el contains <mesh> and <material> XML children
mujoco_root.appendChild(asset_el)