urdf-loader
Advanced tools
Comparing version 0.7.3 to 0.8.0
@@ -7,2 +7,7 @@ # Changelog | ||
## [0.8.0] - 2020-01-03 | ||
### Changed | ||
- Moved the URDFLoader options to member variables instead of an object paramter to `parse` and `load` functions. | ||
- Added `onError` and `onProgress` callbacks to `load` function. | ||
## [0.7.3] - 2019-11-08 | ||
@@ -9,0 +14,0 @@ ### Fixed |
{ | ||
"name": "urdf-loader", | ||
"version": "0.7.3", | ||
"version": "0.8.0", | ||
"description": "URDF Loader for THREE.js and webcomponent viewer", | ||
@@ -10,4 +10,4 @@ "main": "umd/URDFLoader.js", | ||
"build": "rollup -c && cd example && webpack", | ||
"test": "rollup -c && jest", | ||
"lint": "eslint ./src/*.js ./test/*.js", | ||
"test": "jest", | ||
"lint": "eslint ./src/*.js ./test/*.js && tsc -p tsconfig.json --noEmit", | ||
"coverage": "nyc report --reporter=html & opn coverage/index.html" | ||
@@ -59,2 +59,3 @@ }, | ||
"threejs-model-loader": "0.0.1", | ||
"typescript": "^3.7.4", | ||
"wc-loader": "^1.1.12", | ||
@@ -61,0 +62,0 @@ "webpack": "^3.5.3" |
@@ -20,11 +20,9 @@ # javascript urdf-loader | ||
const loader = new URDFLoader(manager); | ||
loader.packages = { | ||
packageName : '.../package/dir/' // The equivalent of a (list of) ROS package(s):// directory | ||
}; | ||
loader.loadMeshCb = (path, manager, done) => { }; | ||
loader.load( | ||
'T12/urdf/T12.URDF', // The path to the URDF within the package OR absolute | ||
robot => { }, // The robot is loaded! | ||
{ | ||
packages: { | ||
packageName : '.../package/dir/' // The equivalent of a (list of) ROS package(s):// directory | ||
}, | ||
loadMeshCb: (path, manager, done) => { }, // Callback for each mesh for custom mesh processing and loading code | ||
} | ||
robot => { } // The robot is loaded! | ||
); | ||
@@ -40,2 +38,4 @@ ``` | ||
List of options available on the URDFLoader class. | ||
### .packages | ||
@@ -68,3 +68,3 @@ | ||
onComplete : ( obj : Object3D ) => void | ||
) => void | ||
) => void | ||
``` | ||
@@ -129,4 +129,5 @@ | ||
urdfpath : string, | ||
onComplete : (robot: URDFRobot) => void, | ||
options = null : URDFOptions | ||
onComplete : (robot : URDFRobot) => void, | ||
onProgress? : () => void, | ||
onError? : (error : Error) => void | ||
) : void | ||
@@ -142,3 +143,3 @@ ``` | ||
```js | ||
parse( urdfContent : string, options = null : URDFOptions) : URDFRobot | ||
parse( urdfContent : string ) : URDFRobot | ||
``` | ||
@@ -260,3 +261,3 @@ | ||
<!-- Register the Element --> | ||
<script href=".../urdf-viewer-element.js" /> | ||
<script href=".../urdf-viewer-element.js"></script> | ||
<script>customElements.define('urdf-viewer', URDFViewer)</script> | ||
@@ -263,0 +264,0 @@ |
@@ -501,15 +501,8 @@ import * as THREE from 'three'; | ||
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' }, | ||
}); | ||
} | ||
@@ -516,0 +509,0 @@ |
@@ -0,0 +0,0 @@ import { Object3D, Vector3 } from 'three'; |
@@ -12,11 +12,2 @@ import { LoadingManager, Object3D } from 'three'; | ||
interface URDFLoaderOptions { | ||
packages?: string | { [key: string]: string }, | ||
loadMeshCb?: MeshLoadFunc, | ||
workingPath?: string, | ||
fetchOptions?: object | ||
} | ||
export default class URDFLoader { | ||
@@ -27,6 +18,19 @@ | ||
// options | ||
fetchOptions: Object; | ||
workingPath: string; | ||
parseVisual: boolean; | ||
parseCollision: boolean; | ||
packages: string | { [key: string]: string }; | ||
loadMeshCb: MeshLoadFunc; | ||
constructor(manager?: LoadingManager); | ||
load(url: string, onLoad: (robot: URDFRobot) => void, options?: URDFLoaderOptions): void; | ||
parse(content: string, options?: URDFLoaderOptions): URDFRobot; | ||
load( | ||
url: string, | ||
onLoad: (robot: URDFRobot) => void, | ||
onProgress?: () => void, | ||
onError?: () => void | ||
): void; | ||
parse(content: string): URDFRobot; | ||
} |
@@ -62,2 +62,8 @@ import * as THREE from 'three'; | ||
this.manager = manager || THREE.DefaultLoadingManager; | ||
this.loadMeshCb = this.defaultMeshLoader.bind(this); | ||
this.parseVisual = true; | ||
this.parseCollision = false; | ||
this.packages = ''; | ||
this.workingPath = ''; | ||
this.fetchOptions = null; | ||
@@ -69,3 +75,3 @@ } | ||
// onComplete: Callback that is passed the model once loaded | ||
load(urdf, onComplete, options) { | ||
load(urdf, onComplete, onProgress, onError) { | ||
@@ -78,12 +84,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); | ||
@@ -95,4 +108,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); | ||
@@ -105,9 +121,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; | ||
@@ -114,0 +130,0 @@ const linkMap = {}; |
@@ -0,0 +0,0 @@ (function (global, factory) { |
@@ -0,0 +0,0 @@ (function (global, factory) { |
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
250471
2854
414
17