extendsXacroParser
Extends XacroParser and implements getFileContents to load from a server using fetch.
const loader = new XacroLoader();
loader.load(
'../path/to/file.xacro',
result => {
// xacro XML
},
err => {
// parse error
} );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 = {}
Options passed to fetch when loading files.
Methods
load(
url: string,
onComplete: ( result: XMLDocument ) => void,
onError?: ( error: Error ) => void
): voidLoads and parses the xacro file at the given url. If workingPath has not been set it is
extracted from the url.
parse(
data: string,
onComplete: ( result: XMLDocument ) => void,
onError?: ( error: Error ) => void
): voidParses the passed xacro contents using the options specified on the object and calls
onComplete with the xml document of the processed xacro file.
getFileContents( path: string ): Promise<string>Loads the file at the given path using fetch and fetchOptions and returns the contents
as a string.