I have created a simple model. Also converted that into gltf/glb. That model is showing up on babylon and as well as on three js. But whenever I am trying to import into my html file, error is showing up like,
" GLTFLoader.js:149 SyntaxError: Unexpected token < in JSON at position 0" Note : I am using Parcel Bundler for bundling.
here’s my code
const loader = new GLTFLoader();
loader.load("model.glb", function (gltf) {
car = gltf.scene.children[0];
car.scale.set(0.5, 0.5, 0.5);
scene.add(gltf.scene);
animate();
});
loader instance is successfully loaded. But the load method is not working. Please help me out.
Not entirely sure. But having worked with a bunch of loaders, I think doing anything with adding to scene inside of them is hit or miss.
Try moving these two lines after the loader, outside of it:
scene.add(gltf.scene);
animate();
EDIT: Actually I think what you are doing should be working. It might be the scale that you are doing you might want to use .copy instead of .set - try commenting out the scale line.
It worked by using CDN or rather say from local directory. I think that was a server problem. I was successful after trying with CDN and some configuring into object properties. And it only runs on Apache.
I’ll try with bundler tomorrow. Thanks mate, for your help
I didn’t notice the notification though!
It was the problem of http server. After using the server from VS code…called five server pointed that solution. Thanks mate