Loads and builds the specified URDF robot in THREE.js.
import { HemisphereLight, MathUtils } from 'three';
import URDFLoader from 'urdf-loader';
// scene, camera and renderer are initialized here
// meshes load relative to the URDF file
const URL = 'https://raw.githubusercontent.com/gkjohnson/urdf-loaders/master/urdf/T12/urdf/T12_flipped.URDF';
scene.add( new HemisphereLight( 0xffffff, 0x444444, 3 ) );
camera.position.set( 6, 5, 8 );
const robot = await new URDFLoader().loadAsync( URL );
// URDF is Z up
robot.rotation.x = Math.PI / 2;
robot.position.y = 1.1;
// stand the robot on its six legs
for ( let i = 1; i <= 6; i ++ ) {
robot.setJointValue( `HP${ i }`, MathUtils.degToRad( 30 ) );
robot.setJointValue( `KP${ i }`, MathUtils.degToRad( 120 ) );
robot.setJointValue( `AP${ i }`, MathUtils.degToRad( - 60 ) );
}
scene.add( robot );On this page
Methods
new URDFLoader(
// The THREE.js LoadingManager.
manager?: LoadingManager
)Constructor. Manager is used for transforming load URLs and tracking downloads.
loadAsync(
// The path to the URDF within the package OR absolute
urdfpath: string
): Promise<URDFRobot>Promise-wrapped version of load.
load(
// The path to the URDF within the package OR absolute
urdfpath: string,
// Callback that is passed the model once loaded
onComplete: ( robot: URDFRobot ) => void,
// Called during loading
onProgress?: () => void,
// Called if an error occurs
onError?: ( error: Error ) => void
): voidLoads and builds the specified URDF robot in THREE.js. Takes a path to load the urdf file from, a func to call when the robot has loaded, and a set of options.
parse(
// The URDF content to parse
urdfContent: string | Document | Element
): URDFRobotParses URDF content and returns the robot model. Takes an XML string to parse and a set of
options. If the XML document has already been parsed using DOMParser then either the
returned Document or root Element can be passed into this function in place of the
string, as well.
Note that geometry will not necessarily be loaded when the robot is returned.