urdf-exporter v0.4.0
urdf-exporter-js
Utility for exporting a three.js object hierarchy as a URDF.
Use
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!API
URDFConverter
Utility class to enable convenient conversion from three.js objects to URDF classes for export.
.generateCallback
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
postprocessCallback : ( object : URDFRobot ) => voidA function that takes the generated URDF result to enable fixups and other types of postprocessing that might be needed.
.generate
generate( object : Object3D ) : URDFRobotTraverses the given hierarchy and generates a converted URDF hierarchy.
URDFExporter
.indent
indent = '\t' : stringThe set of indentation characters to use.
.processGeometryCallback
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
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.
URDFLimit
Class containing values to export for joint limits.
.upper
upper = 0 : Number.lower
lower = 0 : Number.velocity
velocity = 0 : Number.effort
effort = 0 : NumberURDFInertialFrame
Class containing values for the link inertial frame.
.position
position : Vector3.rotation
rotation : Euler.mass
mass = 0 : Numberinertia
inertial : Matrix3The upper triangular matrix is used to define the xx, yy, zz, xy, yz, and xz fields.
URDFLink
extends THREE.Object3D
When this field is encountered a new link is created in the URDF file.
.inertial
inertial : URDFInertialFrameURDFJoint
extends THREE.Object3D
When this field is encountered a new joint is created in the URDF file.
.jointType
jointType = 'fixed' : string.axis
axis : Vector3.limit
limit : URDFLimitURDFRobot
extends URDFLink
A class describing the root of the URDF Robot.
.robotName
robotName = '' : stringURDFVisual
extends THREE.Object3D
URDFCollider
extends THREE.Object3D