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 Dm control MuJoCo Scene Export

From Leeroopedia
Knowledge Sources
Domains Blender, MuJoCo, Export
Last Updated 2026-02-15 04:00 GMT

Overview

The mujoco_scene module converts Blender scene objects into the MuJoCo MJCF XML scene tree (worldbody), generating <body>, <geom>, <light>, <joint>, and <freejoint> elements with correct transforms and properties.

Description

This module provides builder functions for each MJCF element type. body_builder() creates <body> elements with position and quaternion from local transforms. light_builder() maps Blender light type, color, attenuation, and shadow settings to <light> attributes including directional classification for SUN and SPOT lights. mesh_geom_builder() creates <geom type="mesh"> elements with material references, handling multi-material meshes by generating multiple geoms. joint_builder() creates <joint> elements from DOF definitions with axis, limits, and type.

The main export_to_xml() function iterates over the ordered list of scene objects and builds a parent-child XML tree using a parent_elements dictionary that maps ObjectRef instances to their corresponding XML elements. Armatures optionally receive a <freejoint>, bones get hinge joints from their rotation DOFs, and multi-geom meshes are wrapped in an aggregating <body> element. Helper functions (vec_to_mjcf, quat_to_mjcf, color_to_mjcf, bool_to_mjcf) convert Blender data types to MJCF string representations.

Usage

Called by the Blender Exporter addon's _export_mjcf method to generate the worldbody portion of the MJCF XML. Not typically used directly, but rather as part of the Blender-to-MuJoCo export pipeline.

Code Reference

Source Location

Signature

def color_to_mjcf(color: mathutils.Color) -> str:
def vec_to_mjcf(vec: mathutils.Vector) -> str:
def quat_to_mjcf(quat: mathutils.Quaternion) -> str:
def bool_to_mjcf(bool_val: bool):

def body_builder(
    doc: minidom.Document, blender_obj: blender_scene.ObjectRef
) -> minidom.Element:

def light_builder(
    doc: minidom.Document, light_obj: blender_scene.ObjectRef
) -> minidom.Element:

def mesh_geom_builder(
    doc: minidom.Document, mesh_obj: blender_scene.ObjectRef
) -> Sequence[minidom.Element]:

def joint_builder(
    doc: minidom.Document,
    dof: blender_scene.Dof,
    dof_type: str,
) -> minidom.Element:

def export_to_xml(
    doc: minidom.Document,
    objects: Sequence[blender_scene.ObjectRef],
    armature_freejoint: bool,
) -> minidom.Element:

Import

from dm_control.blender.mujoco_exporter import mujoco_scene

I/O Contract

Inputs

Name Type Required Description
doc minidom.Document Yes XML document used for creating elements
objects Sequence[ObjectRef] Yes Ordered list of Blender scene objects (parents precede children)
armature_freejoint bool Yes Whether to add a <freejoint> to armature bodies

Outputs

Name Type Description
return minidom.Element A <worldbody> XML element containing the full scene tree hierarchy

Usage Examples

from xml.dom import minidom
from dm_control.blender.mujoco_exporter import mujoco_scene

xml_doc = minidom.Document()

# Build the worldbody scene tree
worldbody_el = mujoco_scene.export_to_xml(
    doc=xml_doc,
    objects=blender_objects,
    armature_freejoint=True,
)

# Append to the MuJoCo root element
mujoco_root.appendChild(worldbody_el)

Related Pages

Page Connections

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