Skip to content

Commit

Permalink
fix cached working path (#301)
Browse files Browse the repository at this point in the history
* fix cached working path

* apply suggestions

* update tests

* remove unused import

---------

Co-authored-by: shaoyu <shaoyu>
  • Loading branch information
smeng9 authored Jan 1, 2025
1 parent 4cad1dc commit c47037d
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 57 deletions.
11 changes: 2 additions & 9 deletions javascript/src/URDFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,7 @@ class URDFLoader {
})
.then(data => {

if (this.workingPath === '') {

this.workingPath = workingPath;

}

const model = this.parse(data);
const model = this.parse(data, this.workingPath || workingPath);
onComplete(model);
manager.itemEnd(urdfPath);

Expand All @@ -141,13 +135,12 @@ class URDFLoader {

}

parse(content) {
parse(content, workingPath = this.workingPath) {

const packages = this.packages;
const loadMeshCb = this.loadMeshCb;
const parseVisual = this.parseVisual;
const parseCollision = this.parseCollision;
const workingPath = this.workingPath;
const manager = this.manager;
const linkMap = {};
const jointMap = {};
Expand Down
27 changes: 27 additions & 0 deletions javascript/test/URDFLoader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,33 @@ describe('Options', () => {

});

it('should use correct workingPath to load meshes', async() => {

const loader = new URDFLoader();

loader.workingPath = 'https://raw.githubusercontent.com/mock-working-path';
loader.loadMeshCb = (path, manager, done) => {

const mesh = new Mesh();
expect(path).toContain('https://raw.githubusercontent.com/mock-working-path');
done(mesh);

};
await loader.loadAsync('https://raw.githubusercontent.com/gkjohnson/urdf-loaders/master/urdf/TriATHLETE_Climbing/urdf/TriATHLETE.URDF');

loader.workingPath = '';
loader.loadMeshCb = (path, manager, done) => {

const mesh = new Mesh();
expect(path).toContain('https://raw.githubusercontent.com/gkjohnson/urdf-loaders/master/urdf/TriATHLETE_Climbing/urdf');
done(mesh);

};
await loader.loadAsync('https://raw.githubusercontent.com/gkjohnson/urdf-loaders/master/urdf/TriATHLETE_Climbing/urdf/TriATHLETE.URDF');

expect(loader.workingPath).toBe('');
});

});

describe('packages', () => {
Expand Down
113 changes: 89 additions & 24 deletions javascript/umd/URDFLoader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion javascript/umd/URDFLoader.js.map

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions javascript/umd/urdf-manipulator-element.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion javascript/umd/urdf-manipulator-element.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit c47037d

Please sign in to comment.