# URDFLoader

class in `urdf-loader`

```js
import { URDFLoader } from 'urdf-loader';
```

Loads and builds the specified URDF robot in THREE.js.

Example: Loading a robot

```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 );
```

## Constructor

```js
new URDFLoader( manager?: LoadingManager )
```

Constructor. Manager is used for transforming load URLs and tracking downloads.

- `manager`, `LoadingManager`, optional: The THREE.js LoadingManager.

## Methods

### .loadAsync

```js
.loadAsync( urdfpath: string ): Promise<URDFRobot>
```

Promise-wrapped version of `load`.

- `urdfpath`, `string`: The path to the URDF within the package OR absolute

### .load

```js
.load( urdfpath: string, onComplete: OnURDFLoad, onProgress?: OnURDFProgress, onError?: OnURDFError ): void
```

Loads 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.

- `urdfpath`, `string`: The path to the URDF within the package OR absolute
- `onComplete`, `OnURDFLoad`: Callback that is passed the model once loaded
- `onProgress`, `OnURDFProgress`, optional: Called during loading
- `onError`, `OnURDFError`, optional: Called if an error occurs

### .parse

```js
.parse( urdfContent: string | Document | Element ): URDFRobot
```

Parses 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.

- `urdfContent`, `string | Document | Element`: The URDF content to parse
