Utility for exporting a three.js object hierarchy as a URDF.
Exporting a model constructed from URDF classes like URDFLink and URDFJoint.
import { URDFExporter } from 'urdf-exporter';
import { STLExporter } from 'three/examples/jsm/exporters/STLExporter.js';
let urdfModel;
// ... create a model using the URDF classes for export
const models = {};
const exporter = new URDFExporter();
exporter.processGeometryCallback = ( model, link ) => {
const name = `${ link.name }_mesh.stl`;
models[ name ] = new STLExporter().parse( model );
return name;
};
urdfModel.updateMatrixWorld();
const urdf = exporter.parse( urdfModel );
// ... urdf content ready!Converting an existing model to one made with the appropriate classes.
import { URDFConverter, URDFRobot, URDFLink, URDFJoint, URDFVisual } from 'urdf-exporter';
let model;
// ... create or load a model
const convert = new URDFConverter();
converter.generateCallback = child => {
let result;
if ( child.linkData ) {
if ( child === model ) {
result = new URDFRobot();
result.robotName = 'my-robot-urdf';
} else {
result = new URDFLink();
}
result.name = child.linkData.name;
} else if ( child.jointData ) {
result = new URDFJoint();
result.name = child.jointData.name;
result.jointType = 'revolute';
result.limit.lower = - Math.PI / 2;
result.limit.upper = Math.PI / 2;
} else if ( child.isMesh ) {
result = new URDFVisual()
result.add( child.clone() );
} else {
result = new Group();
}
result.position.copy( child.position );
result.quaternion.copy( child.quaternion );
result.scale.copy( child.scale );
};
const urdfModel = converter.generate( model );
// ... urdf class hierarchy!Utility class to enable convenient conversion from three.js objects to URDF classes for export.
generateCallback : ( object : Object3D ) => Object3DCallback used for generating URDF class equivalents. The function is expected to return a cloned version of the provided mesh or a URDF class describing the analogous object. The returned object must be the child object that will have children added to it. The generator will then find the root parent to add to the previously processed object.
For example a custom three.js joint type could converted into a joint and link connection which can be run through the URDFExporter.
postprocessCallback : ( object : URDFRobot ) => voidA function that takes the generated URDF result to enable fixups and other types of postprocessing that might be needed.
generate( object : Object3D ) : URDFRobotTraverses the given hierarchy and generates a converted URDF hierarchy.
indent = '\t' : stringThe set of indentation characters to use.
processGeometryCallback : ( node : Object3D, link : URDFLink ) => stringThe callback for to use when processing geometry. Geometry must be processed and cached in order to be exported. A file path is returned from the function.
parse( root : URDFRobot ) : stringParses the object into a urdf file. Returns the URDF contents as a string. The hierarchy matrix world must be updated before calling this function.
Class containing values to export for joint limits.
upper = 0 : Numberlower = 0 : Numbervelocity = 0 : Numbereffort = 0 : NumberClass containing values for the link inertial frame.
position : Vector3rotation : Eulermass = 0 : Numberinertial : Matrix3The upper triangular matrix is used to define the xx, yy, zz, xy, yz, and xz fields.
extends THREE.Object3D
When this field is encountered a new link is created in the URDF file.
inertial : URDFInertialFrameextends THREE.Object3D
When this field is encountered a new joint is created in the URDF file.
jointType = 'fixed' : stringaxis : Vector3limit : URDFLimitextends URDFLink
A class describing the root of the URDF Robot.
robotName = '' : stringextends THREE.Object3D
extends THREE.Object3D