I want to create an extension that can load gltf once the method is call. I'm using the latest threejs module according to this blog. But got an error.
Here's my code.
const gltfLoader = new GLTFLoader();
let example = new THREE.Object3D();
gltfLoader.load(
"https://threejsfundamentals.org/threejs/resources/models/cartoon_lowpoly_small_city_free_pack/scene.gltf",
(gltf) => {
example = gltf.scene;
console.log(example);
if (!this.viewer.overlays.hasScene("gltf")) {
this.viewer.overlays.addScene("gltf");
}
this.viewer.overlays.addMesh(example, "gltf");
}
);
Regarding the glTF, you may check out this blog post and consider using the Autodesk.glTF
ext instead: https://forge.autodesk.com/blog/gltf-20-support-forge-viewer
viewer.loadExtension('Autodesk.glTF').then(() => {
viewer.loadModel('address/of/your/model.gltf');
});
See here for the code sample: https://github.com/petrbroz/forge-basic-app/tree/experiment/gltf2
Here's a couple of things to keep in mind when working with glTF files in Forge Viewer: