urdf-loader
Advanced tools
Comparing version 0.8.0 to 0.8.1
@@ -7,2 +7,6 @@ # Changelog | ||
## [0.8.1] - 2020-03-12 | ||
### Added | ||
- Support for processing pre-parsed XML documents to the `parse` function. A `Document` or `Element` object as returned from `DOMParser` may be passed in place of the xml string. | ||
## [0.8.0] - 2020-01-03 | ||
@@ -9,0 +13,0 @@ ### Changed |
{ | ||
"name": "urdf-loader", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "URDF Loader for THREE.js and webcomponent viewer", | ||
@@ -5,0 +5,0 @@ "main": "umd/URDFLoader.js", |
# javascript urdf-loader | ||
[![npm version](https://img.shields.io/npm/v/urdf-loader.svg?style=flat-square)](https://www.npmjs.com/package/urdf-loader) | ||
[![travis build](https://img.shields.io/travis/gkjohnson/urdf-loaders.svg?style=flat-square)](https://travis-ci.com/gkjohnson/urdf-loaders) | ||
[![travis build](https://img.shields.io/travis/gkjohnson/urdf-loaders/master.svg?style=flat-square)](https://travis-ci.com/gkjohnson/urdf-loaders) | ||
[![lgtm code quality](https://img.shields.io/lgtm/grade/javascript/g/gkjohnson/urdf-loaders.svg?style=flat-square&label=code-quality)](https://lgtm.com/projects/g/gkjohnson/urdf-loaders/) | ||
@@ -14,2 +14,5 @@ | ||
# Use | ||
Loading a URDF file from a server. | ||
```js | ||
@@ -22,3 +25,3 @@ import { LoadingManager } from 'three'; | ||
loader.packages = { | ||
packageName : '.../package/dir/' // The equivalent of a (list of) ROS package(s):// directory | ||
packageName : './package/dir/' // The equivalent of a (list of) ROS package(s):// directory | ||
}; | ||
@@ -32,2 +35,23 @@ loader.loadMeshCb = (path, manager, done) => { }; | ||
Using [XacroParser](github.com/gkjohnson/xacro-parser) to process a Xacro URDF file and then parse it. | ||
```js | ||
import { LoaderUtils } from 'three'; | ||
import { XacroLoader } from 'xacro-parser'; | ||
import URDFLoader from 'urdf-loader'; | ||
const url = './path/to/file.xacro'; | ||
const xacroLoader = new XacroLoader(); | ||
xacroLoader.load( url, xml => { | ||
const urdfLoader = new URDFLoader(); | ||
urdfLoader.workingPath = LoaderUtils.extractUrlBase( url ); | ||
const robot = urdfLoader.parse( xml ); | ||
// robot is loaded! | ||
} ); | ||
``` | ||
## Limitations | ||
@@ -55,4 +79,4 @@ - Only `prismatic`, `continuous`, `revolute`, and `fixed` joints are supported. | ||
{ | ||
"package1": ".../path/to/package1", | ||
"package2": ".../path/to/package2", | ||
"package1": "./path/to/package1", | ||
"package2": "./path/to/package2", | ||
... | ||
@@ -84,3 +108,3 @@ } | ||
```js | ||
fetchOptions : Object | ||
fetchOptions = null : Object | ||
``` | ||
@@ -93,3 +117,3 @@ | ||
```js | ||
workingPath : string | ||
workingPath = '' : string | ||
``` | ||
@@ -104,3 +128,3 @@ | ||
```js | ||
parseVisual : boolean | ||
parseVisual = true : boolean | ||
``` | ||
@@ -113,3 +137,3 @@ | ||
```js | ||
parseCollision : boolean | ||
parseCollision = false : boolean | ||
``` | ||
@@ -147,3 +171,3 @@ | ||
```js | ||
parse( urdfContent : string ) : URDFRobot | ||
parse( urdfContent : string | Document | Element ) : URDFRobot | ||
``` | ||
@@ -153,2 +177,4 @@ | ||
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. | ||
@@ -155,0 +181,0 @@ |
@@ -0,0 +0,0 @@ import { Object3D, Vector3 } from 'three'; |
@@ -32,4 +32,4 @@ import { LoadingManager, Object3D } from 'three'; | ||
): void; | ||
parse(content: string): URDFRobot; | ||
parse(content: string | Element | Document): URDFRobot; | ||
} |
@@ -177,6 +177,19 @@ import * as THREE from 'three'; | ||
const parser = new DOMParser(); | ||
const urdf = parser.parseFromString(data, 'text/xml'); | ||
const children = [ ...urdf.children ]; | ||
let children; | ||
if (data instanceof Document) { | ||
children = [ ...data.children ]; | ||
} else if (data instanceof Element) { | ||
children = [ data ]; | ||
} else { | ||
const parser = new DOMParser(); | ||
const urdf = parser.parseFromString(data, 'text/xml'); | ||
children = [ ...urdf.children ]; | ||
} | ||
const robotNode = children.filter(c => c.nodeName === 'robot').pop(); | ||
@@ -183,0 +196,0 @@ return processRobot(robotNode); |
@@ -504,15 +504,8 @@ (function (global, factory) { | ||
new URDFLoader(manager).load( | ||
urdf, | ||
model => robot = model, | ||
const loader = new URDFLoader(manager); | ||
loader.packages = pkg; | ||
loader.loadMeshCb = this.loadMeshFunc; | ||
loader.fetchOptions = { mode: 'cors', credentials: 'same-origin' }; | ||
loader.load(urdf, model => robot = model); | ||
// options | ||
{ | ||
packages: pkg, | ||
loadMeshCb: this.loadMeshFunc, | ||
fetchOptions: { mode: 'cors', credentials: 'same-origin' }, | ||
}); | ||
} | ||
@@ -519,0 +512,0 @@ |
@@ -324,2 +324,8 @@ (function (global, factory) { | ||
this.manager = manager || THREE.DefaultLoadingManager; | ||
this.loadMeshCb = this.defaultMeshLoader.bind(this); | ||
this.parseVisual = true; | ||
this.parseCollision = false; | ||
this.packages = ''; | ||
this.workingPath = ''; | ||
this.fetchOptions = null; | ||
@@ -331,3 +337,3 @@ } | ||
// onComplete: Callback that is passed the model once loaded | ||
load(urdf, onComplete, options) { | ||
load(urdf, onComplete, onProgress, onError) { | ||
@@ -340,12 +346,19 @@ // Check if a full URI is specified before | ||
options = Object.assign({ | ||
workingPath, | ||
}, options); | ||
manager.itemStart(urdfPath); | ||
fetch(urdfPath, options.fetchOptions) | ||
.then(res => res.text()) | ||
fetch(urdfPath, this.fetchOptions) | ||
.then(res => { | ||
if (onProgress) { | ||
onProgress(null); | ||
} | ||
return res.text(); | ||
}) | ||
.then(data => { | ||
const model = this.parse(data, options); | ||
if (this.workingPath === '') { | ||
this.workingPath = workingPath; | ||
} | ||
const model = this.parse(data); | ||
onComplete(model); | ||
@@ -357,4 +370,7 @@ manager.itemEnd(urdfPath); | ||
// TODO: Add onProgress and onError functions here | ||
console.error('URDFLoader: Error parsing file.', e); | ||
if (onError) { | ||
onError(e); | ||
} else { | ||
console.error('URDFLoader: Error loading file.', e); | ||
} | ||
manager.itemError(urdfPath); | ||
@@ -367,9 +383,9 @@ manager.itemEnd(urdfPath); | ||
parse(content, options = {}) { | ||
parse(content) { | ||
const packages = options.packages || ''; | ||
const loadMeshCb = options.loadMeshCb || this.defaultMeshLoader.bind(this); | ||
const workingPath = options.workingPath || ''; | ||
const parseVisual = ('parseVisual' in options) ? options.parseVisual : true; | ||
const parseCollision = options.parseCollision || false; | ||
const packages = this.packages; | ||
const loadMeshCb = this.loadMeshCb; | ||
const parseVisual = this.parseVisual; | ||
const parseCollision = this.parseCollision; | ||
const workingPath = this.workingPath; | ||
const manager = this.manager; | ||
@@ -428,6 +444,19 @@ const linkMap = {}; | ||
const parser = new DOMParser(); | ||
const urdf = parser.parseFromString(data, 'text/xml'); | ||
const children = [ ...urdf.children ]; | ||
let children; | ||
if (data instanceof Document) { | ||
children = [ ...data.children ]; | ||
} else if (data instanceof Element) { | ||
children = [ data ]; | ||
} else { | ||
const parser = new DOMParser(); | ||
const urdf = parser.parseFromString(data, 'text/xml'); | ||
children = [ ...urdf.children ]; | ||
} | ||
const robotNode = children.filter(c => c.nodeName === 'robot').pop(); | ||
@@ -434,0 +463,0 @@ return processRobot(robotNode); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
253484
2879
440