I am trying to load this .gltf file into Three.js with DRACOLoader.
dna.gltf (893.6 KB)
But for some reason I get this error: SyntaxError: Unexpected token '<'
You can see my code here:
import * as THREE from "three";
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js'
export default class Sketch {
constructor(options) {
this.scene = new THREE.Scene();
this.container = options.dom;
this.width = this.container.offsetWidth;
this.height = this.container.offsetHeight;
this.renderer = new THREE.WebGLRenderer();
this.renderer.setPixelRatio(window.devicePixelRatio);
this.renderer.setSize(this.width, this.height);
this.renderer.setClearColor(0x141414, 1);
this.renderer.outputColorSpace = THREE.SRGBColorSpace;
this.container.appendChild(this.renderer.domElement);
this.camera = new THREE.PerspectiveCamera(
70,
window.innerWidth / window.innerHeight,
0.001,
1000
);
this.camera.position.set(-2, 2, 4)
this.time = 0;
const dnaPath = new URL('/public/model/dna.gltf', import.meta.url);
this.dracoLoader = new DRACOLoader()
this.dracoLoader.setDecoderPath( '/examples/jsm/libs/draco/' );
this.loader = new GLTFLoader()
this.loader.setDRACOLoader( this.dracoLoader );
this.loader.load( //Error happens here
dnaPath.href,
function () {
console.log("IN")
}
)
}
setupResize() {
window.addEventListener("resize", this.resize.bind(this));
}
resize() {
this.width = this.container.offsetWidth;
this.height = this.container.offsetHeight;
this.renderer.setSize(this.width, this.height);
this.camera.aspect = this.width / this.height;
this.camera.updateProjectionMatrix();
}
render() {
this.time += 0.05;
requestAnimationFrame(this.render.bind(this));
this.renderer.render(this.scene, this.camera);
}
}
new Sketch({
dom: document.getElementById("container")
});
This is my Network page when I run the code, but I can’t see anything wrong with it.
I tried following this: To load 3D model which is compressed by draco and it has .gltf extension - #4 by mfschmidt.
But it does not work. What am I doing wrong?
I hope someone can help.
Note: I am using Parcel, if that changes anything.
Let me know if I need to share my package.json file.