mani_skill.utils.building._mjcf_loader#

Loader code to import MJCF xml files into SAPIEN

Code partially adapted from NVIDIA/warp

Articulations are known as kinematic trees (defined by <body> tags) in Mujoco. A single .xml file can have multiple articulations

Any <geom> tag in <worldbody> but not a <body> tag will be built as separate static actors if possible. Actors that are not static seem to be defined with a free joint under a single body tag.

Warnings of unloadable tags/data can be printed if verbosity is turned on (by default it is off)

Notes

Joint properties relating to the solver, stiffness, actuator, are all not directly imported here and instead must be implemented via a controller like other robots in SAPIEN

Contact tags are not supported

Tendons/equality constraints are supported but may not work the same

The default group of geoms is 0 in mujoco. From docs it appears only group 0 and 2 are rendered by default. This is also by default what the visualizer shows and presumably what image renders show. Any other group is treated as being invisible (e.g. in SAPIEN we do not add visual bodies). SAPIEN does not currently support toggling render groups like Mujoco. Sometimes a MJCF might not follow this and will try and render other groups. In that case the loader supports indicating which other groups to add visual bodies for.

Ref: https://mujoco.readthedocs.io/en/stable/XMLreference.html#body-geom-group, https://mujoco.readthedocs.io/en/latest/modeling.html#composite-objects (says group 3 is turned off)

If contype is 0, it means that geom can’t collide with anything. We do this by not adding a collision shape at all.

geoms under worldbody but not body tags are treated as static objects at the moment.

Useful references: - Collision detection: https://mujoco.readthedocs.io/en/stable/computation/index.html#collision-detection

Attributes#

Classes#

MJCFLoader

Class to load MJCF into SAPIEN.

MJCFTexture

Functions#

_merge_attrib(default_attrib, incoming_attribs)

_parse_float(attrib, key, default)

_parse_int(attrib, key, default)

_parse_orientation(attrib, use_degrees, euler_seq)

_parse_vec(attrib, key, default)

_str_to_float(string[, delimiter])

Module Contents#

class mani_skill.utils.building._mjcf_loader.MJCFLoader(ignore_classes=['motor'], visual_groups=[0, 2])[source]#

Class to load MJCF into SAPIEN.

_build_geom(geom, builder, defaults)[source]#
Parameters:
  • geom (xml.etree.ElementTree.Element) –

  • builder (Union[sapien.wrapper.articulation_builder.LinkBuilder, sapien.ActorBuilder]) –

sets inertial, visual/collision shapes

Parameters:
  • body (xml.etree.ElementTree.Element) –

  • link_builder (sapien.wrapper.articulation_builder.LinkBuilder) –

_parse_body(body, parent, incoming_defaults, builder)[source]#
Parameters:
  • body (xml.etree.ElementTree.Element) –

  • parent (sapien.wrapper.articulation_builder.LinkBuilder) –

  • incoming_defaults (dict) –

  • builder (sapien.wrapper.articulation_builder.ArticulationBuilder) –

_parse_constraint(constraint)[source]#
Parameters:

constraint (xml.etree.ElementTree.Element) –

_parse_default(node, parent)[source]#

Parse a MJCF default attribute. https://mujoco.readthedocs.io/en/stable/modeling.html#default-settings explains how it works

Parameters:
  • node (xml.etree.ElementTree.Element) –

  • parent (xml.etree.ElementTree.Element) –

_parse_material(material)[source]#

Parse MJCF materials in asset to sapien render materials

Parameters:

material (xml.etree.ElementTree.Element) –

_parse_mesh(mesh)[source]#

Parse MJCF mesh data in asset

Parameters:

mesh (xml.etree.ElementTree.Element) –

_parse_mjcf(mjcf_string)[source]#

Helper function for self.parse

Parameters:

mjcf_string (str) –

Return type:

Tuple[list[sapien.wrapper.articulation_builder.ArticulationBuilder], list[sapien.ActorBuilder], None]

_parse_texture(texture)[source]#

Parse MJCF textures to then be referenced by materials: https://mujoco.readthedocs.io/en/stable/XMLreference.html#asset-texture

NOTE: - Procedural texture generation is currently not supported. - Different texture types are not really supported

Parameters:

texture (xml.etree.ElementTree.Element) –

static _pose_from_origin(origin, scale)[source]#
load(mjcf_file, package_dir=None)[source]#

Parses a given mjcf .xml file and builds all articulations and actors

Parameters:

mjcf_file (str) –

parse(mjcf_file, package_dir=None)[source]#

Parses a given MJCF file into articulation builders and actor builders and sensor configs

Parameters:

mjcf_file (str) –

set_scene(scene)[source]#
_assets[source]#
_defaults: dict[str, xml.etree.ElementTree.Element][source]#
_group_count = 0[source]#
_link2builder: dict[str, sapien.wrapper.articulation_builder.LinkBuilder][source]#
_link2parent_joint: dict[str, Any][source]#
_materials[source]#
_meshes: dict[str, xml.etree.ElementTree.Element][source]#
property _root_default[source]#
_textures: dict[str, MJCFTexture][source]#
density = 1000[source]#

whether to fix the root link. Note regardless of given XML, the root link is a dummy link this loader creates which makes a number of operations down the line easier. In general this should be False if there is a freejoint for the root body of articulations in the XML and should be true if there are no free joints. At the moment when modelling a robot from Mujoco this must be handled on a case by case basis

ignore_classes = ['motor'][source]#
load_multiple_collisions_from_file = False[source]#
load_nonconvex_collisions = False[source]#
multiple_collisions_decomposition = 'none'[source]#
multiple_collisions_decomposition_params[source]#
revolute_unwrapped = False[source]#
scale = 1.0[source]#
scene: sapien.Scene = None[source]#
visual_groups = [0, 2][source]#
class mani_skill.utils.building._mjcf_loader.MJCFTexture[source]#
file: str[source]#
name: str[source]#
rgb1: list[source]#
rgb2: list[source]#
type: Literal['skybox', 'cube', '2d'][source]#
mani_skill.utils.building._mjcf_loader._merge_attrib(default_attrib, incoming_attribs)[source]#
Parameters:
  • default_attrib (dict) –

  • incoming_attribs (Union[list[dict], dict]) –

mani_skill.utils.building._mjcf_loader._parse_float(attrib, key, default)[source]#
mani_skill.utils.building._mjcf_loader._parse_int(attrib, key, default)[source]#
mani_skill.utils.building._mjcf_loader._parse_orientation(attrib, use_degrees, euler_seq)[source]#
mani_skill.utils.building._mjcf_loader._parse_vec(attrib, key, default)[source]#
mani_skill.utils.building._mjcf_loader._str_to_float(string, delimiter=' ')[source]#
Parameters:

string (str) –

mani_skill.utils.building._mjcf_loader.DEFAULT_MJCF_OPTIONS[source]#
mani_skill.utils.building._mjcf_loader.WARNED_ONCE[source]#