Skip to content

Commit

Permalink
Add defaultMaterialLoader function to URDFLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
sunjiang0018 committed Nov 5, 2024
1 parent 4cad1dc commit 2d5e0d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion javascript/src/URDFLoader.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LoadingManager, Object3D } from 'three';
import { LoadingManager, Object3D, Material } from 'three';
import { URDFRobot } from './URDFClasses';

interface MeshLoadDoneFunc {
Expand All @@ -9,10 +9,15 @@ interface MeshLoadFunc{
(url: string, manager: LoadingManager, onLoad: MeshLoadDoneFunc): void;
}

interface MaterialLoadFunc {
(): Material;
}

export default class URDFLoader {

manager: LoadingManager;
defaultMeshLoader: MeshLoadFunc;
defaultMaterialLoader: MaterialLoadFunc;

// options
fetchOptions: Object;
Expand All @@ -21,6 +26,7 @@ export default class URDFLoader {
parseCollision: boolean;
packages: string | { [key: string]: string } | ((targetPkg: string) => string);
loadMeshCb: MeshLoadFunc;
loadMaterialCb: MaterialLoadFunc;

constructor(manager?: LoadingManager);
loadAsync(urdf: string): Promise<URDFRobot>;
Expand Down
9 changes: 7 additions & 2 deletions javascript/src/URDFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class URDFLoader {

this.manager = manager || THREE.DefaultLoadingManager;
this.loadMeshCb = this.defaultMeshLoader.bind(this);
this.loadMaterialCb = this.defaultMaterialLoader.bind(this);
this.parseVisual = true;
this.parseCollision = false;
this.packages = '';
Expand Down Expand Up @@ -459,7 +460,7 @@ class URDFLoader {
function processMaterial(node) {

const matNodes = [ ...node.children ];
const material = new THREE.MeshPhongMaterial();
const material = this.loadMaterialCb();

material.name = node.getAttribute('name') || '';
matNodes.forEach(n => {
Expand Down Expand Up @@ -523,7 +524,7 @@ class URDFLoader {

} else {

material = new THREE.MeshPhongMaterial();
material = this.loadMaterialCb();

}

Expand Down Expand Up @@ -661,4 +662,8 @@ class URDFLoader {

}

defaultMaterialLoader() {
return new THREE.MeshPhongMaterial();
}

};

0 comments on commit 2d5e0d6

Please sign in to comment.