| | |
| | |
| | |
| | |
| |
|
| | """ |
| | Utility to convert a MJCF into USD format. |
| | |
| | MuJoCo XML Format (MJCF) is an XML file format used in MuJoCo to describe all elements of a robot. |
| | For more information, see: http://www.mujoco.org/book/XMLreference.html |
| | |
| | This script uses the MJCF importer extension from Isaac Sim (``isaacsim.asset.importer.mjcf``) to convert |
| | a MJCF asset into USD format. It is designed as a convenience script for command-line use. For more information |
| | on the MJCF importer, see the documentation for the extension: |
| | https://docs.isaacsim.omniverse.nvidia.com/latest/robot_setup/ext_isaacsim_asset_importer_mjcf.html |
| | |
| | |
| | positional arguments: |
| | input The path to the input URDF file. |
| | output The path to store the USD file. |
| | |
| | optional arguments: |
| | -h, --help Show this help message and exit |
| | --fix-base Fix the base to where it is imported. (default: False) |
| | --import-sites Import sites by parse <site> tag. (default: True) |
| | --make-instanceable Make the asset instanceable for efficient cloning. (default: False) |
| | |
| | """ |
| |
|
| | """Launch Isaac Sim Simulator first.""" |
| |
|
| | import argparse |
| |
|
| | from isaaclab.app import AppLauncher |
| |
|
| | |
| | parser = argparse.ArgumentParser(description="Utility to convert a MJCF into USD format.") |
| | parser.add_argument("input", type=str, help="The path to the input MJCF file.") |
| | parser.add_argument("output", type=str, help="The path to store the USD file.") |
| | parser.add_argument("--fix-base", action="store_true", default=False, help="Fix the base to where it is imported.") |
| | parser.add_argument( |
| | "--import-sites", action="store_true", default=False, help="Import sites by parsing the <site> tag." |
| | ) |
| | parser.add_argument( |
| | "--make-instanceable", |
| | action="store_true", |
| | default=False, |
| | help="Make the asset instanceable for efficient cloning.", |
| | ) |
| |
|
| | |
| | AppLauncher.add_app_launcher_args(parser) |
| | |
| | args_cli = parser.parse_args() |
| |
|
| | |
| | app_launcher = AppLauncher(args_cli) |
| | simulation_app = app_launcher.app |
| |
|
| | """Rest everything follows.""" |
| |
|
| | import contextlib |
| | import os |
| |
|
| | import carb |
| | import omni.kit.app |
| |
|
| | import isaaclab.sim as sim_utils |
| | from isaaclab.sim.converters import MjcfConverter, MjcfConverterCfg |
| | from isaaclab.utils.assets import check_file_path |
| | from isaaclab.utils.dict import print_dict |
| |
|
| |
|
| | def main(): |
| | |
| | mjcf_path = args_cli.input |
| | if not os.path.isabs(mjcf_path): |
| | mjcf_path = os.path.abspath(mjcf_path) |
| | if not check_file_path(mjcf_path): |
| | raise ValueError(f"Invalid file path: {mjcf_path}") |
| | |
| | dest_path = args_cli.output |
| | if not os.path.isabs(dest_path): |
| | dest_path = os.path.abspath(dest_path) |
| |
|
| | |
| | mjcf_converter_cfg = MjcfConverterCfg( |
| | asset_path=mjcf_path, |
| | usd_dir=os.path.dirname(dest_path), |
| | usd_file_name=os.path.basename(dest_path), |
| | fix_base=args_cli.fix_base, |
| | import_sites=args_cli.import_sites, |
| | force_usd_conversion=True, |
| | make_instanceable=args_cli.make_instanceable, |
| | ) |
| |
|
| | |
| | print("-" * 80) |
| | print("-" * 80) |
| | print(f"Input MJCF file: {mjcf_path}") |
| | print("MJCF importer config:") |
| | print_dict(mjcf_converter_cfg.to_dict(), nesting=0) |
| | print("-" * 80) |
| | print("-" * 80) |
| |
|
| | |
| | mjcf_converter = MjcfConverter(mjcf_converter_cfg) |
| | |
| | print("MJCF importer output:") |
| | print(f"Generated USD file: {mjcf_converter.usd_path}") |
| | print("-" * 80) |
| | print("-" * 80) |
| |
|
| | |
| | |
| | carb_settings_iface = carb.settings.get_settings() |
| | |
| | local_gui = carb_settings_iface.get("/app/window/enabled") |
| | |
| | livestream_gui = carb_settings_iface.get("/app/livestream/enabled") |
| |
|
| | |
| | if local_gui or livestream_gui: |
| | |
| | sim_utils.open_stage(mjcf_converter.usd_path) |
| | |
| | app = omni.kit.app.get_app_interface() |
| | |
| | with contextlib.suppress(KeyboardInterrupt): |
| | while app.is_running(): |
| | |
| | app.update() |
| |
|
| |
|
| | if __name__ == "__main__": |
| | |
| | main() |
| | |
| | simulation_app.close() |
| |
|