URDF export for robot simulators (#719) (#942)

A design with components and joints exports as a URDF robot description (file.export to .urdf, the MCP export tool, solidcraft-cli run --out, File > Export URDF...). It writes one binary STL per component in metres, links with mass, centre of mass and inertia from material density, and maps rigid, revolute, slider, cylindrical, pin-slot, planar and ball joints to URDF joints or short chains. Loops, broken joints and loose parts are reported as warnings. Options: mesh_prefix, effort, velocity. Docs in docs/urdf.md.
This commit is contained in:
Mateusz Sych authored and GitHub committed 2026-10-13 21:52:30 -04:00
1 parent d2e409f40c
commit 17db109c5d
19 files changed
+1993 -17

No files matched your search

+9 -2
View File
@@ -1,6 +1,6 @@
//! File formats. Designs use JSON or versioned containers (`.solidcraft`); the authoritative
//! document rebuilds on load and optional display caches remain provisional. Bodies export
//! as STL (binary or ASCII), OBJ, STEP and 3MF; STEP
//! as STL (binary or ASCII), OBJ, STEP and 3MF, and assemblies as URDF ([`urdf()`]); STEP
//! files import as a base feature (see [`step_import_feature`]), 3MF and STL files as mesh bodies
//! (see [`mesh_import_feature`]).
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
@@ -20,6 +20,7 @@ pub mod safe_write;
mod sketch2d;
mod svg;
mod threemf;
pub mod urdf;
pub mod vfs;
pub use dxf::{read_dxf, write_dxf};
@@ -30,6 +31,7 @@ pub use svg::read_svg;
mod obj;
pub use obj::read_obj;
pub use threemf::{MAX_3MF_BYTES, MeshObject, model_xml, read_3mf, weld, write_3mf};
pub use urdf::{UrdfOptions, UrdfPackage, urdf};
use solidcraft_doc::{Document, ModelState};
use solidcraft_geom::{Mesh, Vec3};
@@ -54,7 +56,7 @@ pub const MAX_DESIGN_BYTES: usize = 256 << 20;
#[derive(Debug, thiserror::Error)]
pub enum IoError {
#[error("unsupported format `{0}` (use stl, obj, step, 3mf or solidcraft)")]
#[error("unsupported format `{0}` (use stl, obj, step, 3mf, urdf or solidcraft)")]
Format(String),
#[error("nothing to export: the design has no bodies")]
Empty,
@@ -202,6 +204,9 @@ pub enum Format {
/// `.3mf` path alone means [`Format::ThreeMf`].
ThreeMfTagged,
Design,
/// A robot description of the assembly with its mesh files ([`urdf()`]); written by the
/// engine, since it is several files.
Urdf,
}
impl Format {
@@ -216,6 +221,7 @@ impl Format {
"igs" | "iges" => Format::Iges,
"3mf" => Format::ThreeMf,
"3mf-tagged" => Format::ThreeMfTagged,
"urdf" => Format::Urdf,
"solidcraft" | "solvecraft" | "json" => Format::Design,
_ => return Err(IoError::Format(ext)),
})
@@ -336,6 +342,7 @@ pub fn export(state: &ModelState, bodies: &[String], format: Format, name: &str)
write_3mf(&objs)?
}
Format::Design => return Err(IoError::Format("solidcraft (save the document instead)".into())),
Format::Urdf => return Err(IoError::Format("urdf (an assembly package; use file.export)".into())),
})
}