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
  • -ct, --collision-type: Collision mesh processing mode. Choices:
    • mesh: keep the original collision mesh.
    • decomposition: split collision meshes into convex parts.
    • convex_hull: replace collision meshes with convex hulls. This option is ignored when --skip-mesh-postprocess is set.
  • --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.1.1.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.1.1-py3-none-any.whl (101.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: urdf_to_mjcf-0.1.1.tar.gz
  • Upload date:
  • Size: 27.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for urdf_to_mjcf-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d92cca5fad7cfdf32f7ddd6026703c5386c6b35fdb43302031f5790a8a2c6354
MD5 f3f4c1c75388b3bba325ba189fde0b7c
BLAKE2b-256 7ed61c2f7d77e4ce7b27c14f37a9494021c4685d8b2806732c0e54cd2fd4ef32

See more details on using hashes here.

File details

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

File metadata

  • Download URL: urdf_to_mjcf-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 101.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for urdf_to_mjcf-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 136d7bf30421efae184bc9deb37012f86d6adaf11fb4a2a9e721c4e829e324d3
MD5 385f042c974d059e3294a36c7c881443
BLAKE2b-256 bb811a5b9dd58980373ddf719a90cb707ed45b08709c048c37663544095b3ded

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