forked from isaac-sim/IsaacLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for MJCF converter (isaac-sim#957)
# Description Added command-line MJCF conversion script and corresponding support and test files. - `convert_mjcf.py` in `standalone/tools/` - `mjcf_converter.py` and `mjcf_converter_cfg.py` in `extensions/omni.isaac.lab/omni/isaac/lab/sim/converters/` - tests and corresponding tutorial update ## Checklist - [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format` - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have updated the changelog and the corresponding version in the extension's `config/extension.toml` file - [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there --------- Signed-off-by: Kelly Guo <kellyg@nvidia.com> Signed-off-by: Kelly Guo <kellyguo123@hotmail.com> Co-authored-by: Kelly Guo <kellyg@nvidia.com> Co-authored-by: Kelly Guo <kellyguo123@hotmail.com>
- Loading branch information
1 parent
eb5500c
commit a78c419
Showing
13 changed files
with
511 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
source/extensions/omni.isaac.lab/omni/isaac/lab/sim/converters/mjcf_converter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Copyright (c) 2022-2024, The Isaac Lab Project Developers. | ||
# All rights reserved. | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
from __future__ import annotations | ||
|
||
import os | ||
|
||
import omni.kit.commands | ||
import omni.usd | ||
from omni.isaac.core.utils.extensions import enable_extension | ||
from pxr import Usd | ||
|
||
from .asset_converter_base import AssetConverterBase | ||
from .mjcf_converter_cfg import MjcfConverterCfg | ||
|
||
|
||
class MjcfConverter(AssetConverterBase): | ||
"""Converter for a MJCF description file to a USD file. | ||
This class wraps around the `omni.isaac.mjcf_importer`_ extension to provide a lazy implementation | ||
for MJCF to USD conversion. It stores the output USD file in an instanceable format since that is | ||
what is typically used in all learning related applications. | ||
.. caution:: | ||
The current lazy conversion implementation does not automatically trigger USD generation if | ||
only the mesh files used by the MJCF are modified. To force generation, either set | ||
:obj:`AssetConverterBaseCfg.force_usd_conversion` to True or delete the output directory. | ||
.. note:: | ||
From Isaac Sim 2023.1 onwards, the extension name changed from ``omni.isaac.mjcf`` to | ||
``omni.importer.mjcf``. This converter class automatically detects the version of Isaac Sim | ||
and uses the appropriate extension. | ||
.. _omni.isaac.mjcf_importer: https://docs.omniverse.nvidia.com/isaacsim/latest/ext_omni_isaac_mjcf.html | ||
""" | ||
|
||
cfg: MjcfConverterCfg | ||
"""The configuration instance for MJCF to USD conversion.""" | ||
|
||
def __init__(self, cfg: MjcfConverterCfg): | ||
"""Initializes the class. | ||
Args: | ||
cfg: The configuration instance for URDF to USD conversion. | ||
""" | ||
super().__init__(cfg=cfg) | ||
|
||
""" | ||
Implementation specific methods. | ||
""" | ||
|
||
def _convert_asset(self, cfg: MjcfConverterCfg): | ||
"""Calls underlying Omniverse command to convert MJCF to USD. | ||
Args: | ||
cfg: The configuration instance for MJCF to USD conversion. | ||
""" | ||
import_config = self._get_mjcf_import_config(cfg) | ||
omni.kit.commands.execute( | ||
"MJCFCreateAsset", | ||
mjcf_path=cfg.asset_path, | ||
import_config=import_config, | ||
dest_path=self.usd_path, | ||
) | ||
|
||
# fix the issue that material paths are not relative | ||
if self.cfg.make_instanceable: | ||
instanced_usd_path = os.path.join(self.usd_dir, self.usd_instanceable_meshes_path) | ||
stage = Usd.Stage.Open(instanced_usd_path) | ||
# resolve all paths relative to layer path | ||
source_layer = stage.GetRootLayer() | ||
omni.usd.resolve_paths(source_layer.identifier, source_layer.identifier) | ||
stage.Save() | ||
|
||
# fix the issue that material paths are not relative | ||
# note: This issue seems to have popped up in Isaac Sim 2023.1.1 | ||
stage = Usd.Stage.Open(self.usd_path) | ||
# resolve all paths relative to layer path | ||
source_layer = stage.GetRootLayer() | ||
omni.usd.resolve_paths(source_layer.identifier, source_layer.identifier) | ||
stage.Save() | ||
|
||
def _get_mjcf_import_config(self, cfg: MjcfConverterCfg) -> omni.importer.mjcf.ImportConfig: | ||
"""Returns the import configuration for MJCF to USD conversion. | ||
Args: | ||
cfg: The configuration instance for MJCF to USD conversion. | ||
Returns: | ||
The constructed ``ImportConfig`` object containing the desired settings. | ||
""" | ||
|
||
# Enable MJCF Extensions | ||
enable_extension("omni.importer.mjcf") | ||
|
||
from omni.importer.mjcf import _mjcf as omni_mjcf | ||
|
||
import_config = omni_mjcf.ImportConfig() | ||
|
||
# set the unit scaling factor, 1.0 means meters, 100.0 means cm | ||
import_config.set_distance_scale(1.0) | ||
# set imported robot as default prim | ||
import_config.set_make_default_prim(True) | ||
# add a physics scene to the stage on import if none exists | ||
import_config.set_create_physics_scene(False) | ||
# set flag to parse <site> tag | ||
import_config.set_import_sites(True) | ||
|
||
# -- instancing settings | ||
# meshes will be placed in a separate usd file | ||
import_config.set_make_instanceable(cfg.make_instanceable) | ||
import_config.set_instanceable_usd_path(self.usd_instanceable_meshes_path) | ||
|
||
# -- asset settings | ||
# default density used for links, use 0 to auto-compute | ||
import_config.set_density(cfg.link_density) | ||
# import inertia tensor from urdf, if it is not specified in urdf it will import as identity | ||
import_config.set_import_inertia_tensor(cfg.import_inertia_tensor) | ||
|
||
# -- physics settings | ||
# create fix joint for base link | ||
import_config.set_fix_base(cfg.fix_base) | ||
# self collisions between links in the articulation | ||
import_config.set_self_collision(cfg.self_collision) | ||
|
||
return import_config |
35 changes: 35 additions & 0 deletions
35
source/extensions/omni.isaac.lab/omni/isaac/lab/sim/converters/mjcf_converter_cfg.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright (c) 2022-2024, The Isaac Lab Project Developers. | ||
# All rights reserved. | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
from dataclasses import MISSING | ||
|
||
from omni.isaac.lab.sim.converters.asset_converter_base_cfg import AssetConverterBaseCfg | ||
from omni.isaac.lab.utils import configclass | ||
|
||
|
||
@configclass | ||
class MjcfConverterCfg(AssetConverterBaseCfg): | ||
"""The configuration class for MjcfConverter.""" | ||
|
||
link_density = 0.0 | ||
"""Default density used for links. Defaults to 0. | ||
This setting is only effective if ``"inertial"`` properties are missing in the MJCF. | ||
""" | ||
|
||
import_inertia_tensor: bool = True | ||
"""Import the inertia tensor from mjcf. Defaults to True. | ||
If the ``"inertial"`` tag is missing, then it is imported as an identity. | ||
""" | ||
|
||
fix_base: bool = MISSING | ||
"""Create a fix joint to the root/base link. Defaults to True.""" | ||
|
||
import_sites: bool = True | ||
"""Import the sites from the MJCF. Defaults to True.""" | ||
|
||
self_collision: bool = False | ||
"""Activate self-collisions between links of the articulation. Defaults to False.""" |
Oops, something went wrong.