Skip to main content

Convert URDF to MJCF with advanced mesh processing

Project description

urdf-to-mjcf

URDF to MJCF conversion tool with support for STL, OBJ, DAE, GLB formats, automatic recognition of mimic tags in URDF, configurable joint actuators, and one-click generation of sim-ready MJCF files.

中文文档

piper

🚀 Installation

Install from PyPI

pip install urdf-to-mjcf

Or with uv:

uv pip install urdf-to-mjcf

Install from Source

git clone https://github.com/discoverse-dev/urdf-to-mjcf.git
cd urdf-to-mjcf
uv pip install -e .

📖 Usage

Basic Conversion

cd /path/to/your/robot-description/
urdf-to-mjcf input.urdf --output mjcf/output.xml
# Note: Do not place the generated .xml file in the same directory as the urdf, you can add mjcf/output.xml as shown above

Command Line Arguments

urdf-to-mjcf <urdf_path> [options]

Required Arguments

  • urdf_path: Path to the input URDF file

Optional Arguments

  • -o, --output: Output MJCF file path (default: output_mjcf/robot.xml under the URDF directory)
  • -m, --metadata: Path to JSON file containing conversion metadata (joint parameters and sensor configurations)
  • -dm, --default-metadata: Default metadata JSON files, multiple files can be specified, later files override earlier settings
  • -am, --actuator-metadata: Actuator metadata JSON files, multiple files can be specified, later files override earlier settings
  • -a, --appendix: Appendix XML files, multiple files can be specified and applied in order
  • --collision-only: Use collision geometry only without visual appearance for visual representation
  • --collision-type: Collision type(mesh, convex decomposition, convex hull)
  • --log-level: Logging level (default: INFO level)
  • --max-vertices: Maximum number of vertices in the mesh (default: 200000)
  • --skip-mesh-postprocess: Skip heavy mesh-file post-processing and keep only lightweight XML-side postprocess steps

Metadata Files Description

  • metadata: Main conversion configuration file, contains height offset, angle units, whether to add floor, etc.
  • default-metadata: Default joint parameter configuration, defines default properties for joints
  • actuator-metadata: Actuator configuration, defines actuator types and parameters for each joint
  • appendix: Additional XML content that will be directly added to the generated MJCF file

Usage Examples

# agilex-piper robot
cd examples/agilex-piper
urdf-to-mjcf piper.urdf \
  -o mjcf/piper.xml \
  -m metadata/metadata.json \
  -am metadata/actuator.json \
  -dm metadata/default.json \
  -a metadata/appendix.xml
# View the generated model
python -m mujoco.viewer --mjcf=mjcf/piper.xml

# realman-rm65 robotic arm
cd examples/realman-rm65
urdf-to-mjcf rm65b_eg24c2_description.urdf \
  -o mjcf/rm65.xml \
  -m metadata/metadata.json \
  -am metadata/actuator.json \
  -dm metadata/default.json \
  -a metadata/appendix.xml
# View the generated model
python -m mujoco.viewer --mjcf=mjcf/rm65.xml

Environment Variables - URDF2MJCF_MODEL_PATH

You can set the URDF2MJCF_MODEL_PATH environment variable to specify additional search paths for ROS packages and mesh files. This is particularly useful when your robot description packages are not in standard ROS workspace locations.

Manual Setup

Format:

  • Linux/Mac: Colon-separated paths (:)
  • Windows: Semicolon-separated paths (;)
# Linux/Mac
export URDF2MJCF_MODEL_PATH="/path/to/robot1_description:/path/to/robot2_description:/path/to/models"

# Windows
set URDF2MJCF_MODEL_PATH="C:\path\to\robot1_description;C:\path\to\robot2_description"

Model Path Manager Tool

We provide a convenient command-line tool to manage the URDF2MJCF_MODEL_PATH environment variable:

# Scan a workspace for ROS description packages and generate export command
urdf-to-mjcf-modelpath scan /path/to/your/workspace

# Scan multiple directories
urdf-to-mjcf-modelpath scan /path/to/workspace1 /path/to/workspace2

# List current paths in the environment variable
urdf-to-mjcf-modelpath list

# Generate command to unset the environment variable
urdf-to-mjcf-modelpath unset

Features:

  • Recursively searches for packages ending with _description
  • Verifies packages contain package.xml and typical robot folders (urdf, meshes, etc.)
  • Generates the appropriate export command for your shell
  • Shows which paths are new vs. existing
  • Provides instructions to make changes permanent

Example Output:

======================================================================
✅ Total 2 path(s) in URDF2MJCF_MODEL_PATH:
======================================================================
🆕 1. /workspace/src/robot1_description
🆕 2. /workspace/src/robot2_description

======================================================================
📝 To apply these changes, run the following command:
======================================================================

export URDF2MJCF_MODEL_PATH="/workspace/src/robot1_description:/workspace/src/robot2_description"

These paths will be searched when resolving package:// URIs and locating mesh files.

📚 Additional Docs

🤝 Acknowledgments

This project builds upon these excellent open-source projects:

Thanks to the original authors for their outstanding contributions!

📄 License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

urdf_to_mjcf-0.0.0.tar.gz (27.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

urdf_to_mjcf-0.0.0-py3-none-any.whl (98.8 kB view details)

Uploaded Python 3

File details

Details for the file urdf_to_mjcf-0.0.0.tar.gz.

File metadata

  • Download URL: urdf_to_mjcf-0.0.0.tar.gz
  • Upload date:
  • Size: 27.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for urdf_to_mjcf-0.0.0.tar.gz
Algorithm Hash digest
SHA256 9b1a2250847b0a62bce8c79cf5440f846d9ae70990f7ac27cafc40bb72d2b5a9
MD5 c3572881eabca549e0aa6dec419329ef
BLAKE2b-256 9df4110f524fe2a14f20e5dd74d55b53999912815eac38975a869460743fd3be

See more details on using hashes here.

File details

Details for the file urdf_to_mjcf-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: urdf_to_mjcf-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 98.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for urdf_to_mjcf-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9130bb00783b51771616651b5558de2488d50ca085feb701ccd17729dfbab1c8
MD5 3e1d8af3f14b3af736af5830cb4c4592
BLAKE2b-256 8395a6821c314c820acd4cb09381e750d971c4b219918b2c034b6f43d5afd145

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page