Working with URDF Format

Contents
[ ]

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.setLoadCollisionGeometry() to true to also import the <collision> geometry, which robots use for physics simulation.

// Create a new scene
Scene scene = new Scene();
// Build a simple robot link
Node link = scene.getRootNode().createChildNode("link1");
link.setEntity(new Box());
// Save the scene as URDF file
scene.save("output.urdf", FileFormat.URDF);

// Load it back with URDF options
UrdfLoadOptions loadOptions = new UrdfLoadOptions();
// Load collision geometry from the URDF file
loadOptions.setLoadCollisionGeometry(true);
Scene 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.setMeshFormat() method selects which mesh format to use, and setIndented() enables pretty-printed XML output.

// Save with options: pretty-printed XML, meshes exported as OBJ
UrdfSaveOptions saveOptions = new UrdfSaveOptions();
saveOptions.setIndented(true);
saveOptions.setMeshFormat(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>