base
BaseCompositionElement
¶
Bases: ABC
Base class for composable elements in the MuJoCo model, providing common functionality such as compiling to MuJoCo model/data and exporting.
Source code in src/flygym/compose/base.py
mjcf_root
abstractmethod
property
¶
The root MjSpec of this composition element.
compile()
¶
Compile the MjSpec into MuJoCo MjModel and MjData objects. This is where
the model edited via mujoco.MjSpec is "handed off" to mujoco for
simulation. Things like the ordering of generalized coordinates (qpos) are
determined here.
We compile a copy of the spec rather than the spec itself: with
compiler/fusestatic enabled, compiling mutates the spec in place by fusing
static bodies into their parent. During composition (e.g. before a fly is
given a free joint by the world) the root body is still static, so compiling
the live spec would destroy it and invalidate the element references FlyGym
holds. Compiling a copy keeps the editable spec intact while producing an
equivalent compiled model.
Source code in src/flygym/compose/base.py
save_xml_with_assets(output_dir, xml_filename=None)
¶
Export the model to a directory, including an XML file (filename defaults to the model name if not specified) and all associated assets (e.g. meshes).
File-based assets are copied next to the XML and their references are
relativized so the exported model is self-contained (e.g. loadable via
mj_loadXML in the browser).