I am trying to load a URDF file in aframe scene to visualize it on VR. The code for aframe component is:
<script type="importmap">
{ "imports": {
"urdf-loader": "https://cdn.jsdelivr.net/npm/[email protected]/umd/URDFLoader.js",
"three": "https://unpkg.com/[email protected]/build/three.module.js",
"three/addons/": "https://unpkg.com/[email protected]/examples/jsm/"
} }
</script>
<script type="module">
import 'urdf-loader';
import { STLLoader } from 'three/addons/loaders/STLLoader';
import { WebGLRenderer, Mesh, MathUtils, Bone, Vector3 } from 'three';
AFRAME.registerComponent('load-panda-urdf', {
init: function () {
//const manager = new THREE.LoadingManager();
const apiBaseUrl = window.location.origin;
const URDF_PATH = apiBaseUrl + '/api/URDF';
const loader = new URDFLoader(); // Error in this line
loader.load(URDF_PATH, (result) => {
robot = result;
new STLLoader(manager).load(
path,
(result) => {
const material = new THREE.MeshPhongMaterial();
const mesh = new THREE.Mesh(result, material);
done(mesh);
},
null,
(err) => done(null, err)
);
// The robot is loaded!
this.el.sceneEl.object3D.add(robot);
});
},
})
</script>
I get this error related to STLLoader
URDFLoader.js:134 URDFLoader: Error loading file. TypeError: STLLoader_js.STLLoader is not a constructor
at URDFLoader.defaultMeshLoader (URDFLoader.js:645:28)
at URDFLoader.js:555:29
at Array.forEach (<anonymous>)
at processLinkElement (URDFLoader.js:533:22)
at URDFLoader.js:418:31
at Array.forEach (<anonymous>)
at processLink (URDFLoader.js:416:29)
at URDFLoader.js:257:33
at Array.forEach (<anonymous>)
at processRobot (URDFLoader.js:253:19)
The line responsible for error is this
const loader = new URDFLoader();
I went through the documentation of the urdf-loaders project on github but couldn’t find any fix for this. How do I fix this?