Working with URDF Format
What is URDF?
URDF (Unified Robot Description Format) is an XML format used by ROS and robotics simulators such as Gazebo to describe robots — their links, joints and the geometry attached to them. Importing a URDF file gives you the robot as a regular Aspose.3D scene, so you can convert it to glTF, FBX or any other supported format.
Open URDF File Format
Aspose.3D imports the <visual> geometry of every link. Set UrdfLoadOptions.LoadCollisionGeometry to true to also import the <collision> geometry, which robots use for physics simulation.
using Aspose.ThreeD.Formats;
// Create a new scene
var scene = new Scene();
// Build a simple robot link
var link = scene.RootNode.CreateChildNode("link1");
link.Entity = new Box();
// Save the scene as URDF file
scene.Save("output.urdf", FileFormat.URDF);
// Load it back with URDF options
var loadOptions = new UrdfLoadOptions();
// Load collision geometry from the URDF file
loadOptions.LoadCollisionGeometry = true;
var loaded = new Scene();
loaded.Open("output.urdf", loadOptions);
Save URDF File Format
Scenes are exported to URDF with the URDF file format. Links whose geometry is a mesh are written as external mesh files next to the URDF file — the UrdfSaveOptions.MeshFormat property selects which mesh format to use, and Indented enables pretty-printed XML output.
using Aspose.ThreeD.Formats;
// Load the scene to save
var scene = Scene.FromFile("output.urdf");
// Save with options: pretty-printed XML, meshes exported as OBJ
var saveOptions = new UrdfSaveOptions();
saveOptions.Indented = true;
saveOptions.MeshFormat = FileFormat.WavefrontOBJ;
scene.Save("output_indented.urdf", saveOptions);
For a scene containing a link named link1 with mesh geometry, this produces a URDF file that references the exported mesh:
<?xml version="1.0" encoding="utf-8"?>
<robot name="RootNode">
<link name="link1">
<visual>
<geometry>
<mesh filename="link1_visual0.obj" />
</geometry>
</visual>
</link>
</robot>