# XacroLoader

class in `xacro-parser`, extends `XacroParser`

```js
import { XacroLoader } from 'xacro-parser';
```

Extends XacroParser and implements `getFileContents` to load from a server using fetch.

```js
const loader = new XacroLoader();
loader.load(
    '../path/to/file.xacro',
    result => {

        // xacro XML

    },
    err => {

        // parse error

    } );
```

> **Note:** The working path is extracted automatically from the loaded url. Only works in the browser.

Example: Building a robot from its xacro description

```js
import { HemisphereLight } from 'three';
import { XacroLoader } from 'xacro-parser';
import URDFLoader from 'urdf-loader';

// scene, camera and renderer are initialized here

const URL = 'https://raw.githubusercontent.com/gkjohnson/xacro-parser/master/test/data/val_description/model/robots/valkyrie_A.xacro';
const PACKAGE_URL = 'https://raw.githubusercontent.com/gkjohnson/xacro-parser/master/test/data/val_description';
const MESHES_URL = 'https://raw.githubusercontent.com/gkjohnson/nasa-urdf-robots/master/val_description';

scene.add( new HemisphereLight( 0xffffff, 0x444444, 3 ) );
camera.position.set( 1.5, 0.9, 2.4 );

const xacroLoader = new XacroLoader();
xacroLoader.rospackCommands = { find: () => PACKAGE_URL };
xacroLoader.load( URL, xml => {

	const urdfLoader = new URDFLoader();
	urdfLoader.packages = { val_description: MESHES_URL };

	const robot = urdfLoader.parse( xml );
	robot.rotation.x = - Math.PI / 2;
	robot.position.y = 0.1;
	scene.add( robot );

} );
```

## Properties

### .fetchOptions: RequestInit

default `{}`

Options passed to `fetch` when loading files.

## Methods

### .load

```js
.load( url: string, onComplete: XacroLoaderCompleteCallback, onError?: XacroLoaderErrorCallback ): void
```

Loads and parses the xacro file at the given url. If `workingPath` has not been set it is
extracted from the url.

- `url`, `string`
- `onComplete`, `XacroLoaderCompleteCallback`
- `onError`, `XacroLoaderErrorCallback`, optional

### .parse

```js
.parse( data: string, onComplete: XacroLoaderCompleteCallback, onError?: XacroLoaderErrorCallback ): void
```

Parses the passed xacro contents using the options specified on the object and calls
`onComplete` with the xml document of the processed xacro file.

- `data`, `string`
- `onComplete`, `XacroLoaderCompleteCallback`
- `onError`, `XacroLoaderErrorCallback`, optional

### .getFileContents

```js
.getFileContents( path: string ): Promise<string>
```

Loads the file at the given path using `fetch` and `fetchOptions` and returns the contents
as a string.

- `path`, `string`
