I have a problem with Downloading GLB file with GLTFLoader in React.
It shows this error SyntaxError: Unexpected token < in JSON at position 0
at Object.parse ()
at GLTFLoader.parse (GLTFLoader.js:100)
at Object.onLoad (GLTFLoader.js:52)
at XMLHttpRequest. (three.module.js:23674)
This is my part of code
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
this.loader = new GLTFLoader();
this.loader.load("./bread.glb", gltf => {
// ADD MODEL TO THE SCENE
this.scene.add(gltf.scene);
this.renderer.render(this.scene, this.camera);
}, undefined,
error => {
console.log(error);
});
This is the repository, if you comment this line import fileGlb from ‘./bread.glb’ (GLB FILE) in App.js file
and change fileGlb in this.loader.load(fileGlb, gltf => {… }) to ’ ./bread.glb ’ you will get that ERROR .
I found this IMPORT FROM approach in web but it is not solution for that issue.
THANK YOU.
[Mugen87]
Can you please share bread.glb in this thread?
Wow, I didn’t expect WebGL Developers’ salary, in Germany, to be so low, that they have to ask for bread on online forums (with sick rhymes while theyre at it )
This is working example…
And when I want to add path of my glb file it shows error “Unexpected token < in JSON at position 0”. Maybe its bad 3DModel file?
Your loading code looks correct.
Have you checked if the file works in online gltf model viewers, for example https://gltf-viewer.donmccurdy.com/ ? That’s a good way to test whether the problem lies within your code or your model
Hei, this is cool. I put my gltf file there, and it shows the scene. But same issue, it shows “Unexpected token < in JSON at position 0” when put it to the project.
This error usually indicates that your web server does not serve a glTF asset but a HTML file. Make sure you inspect the HTTP response of your request and ensure valid glTF content.
I think the problem was because my file needed to be in the public folder
Can you help me with setting up position of my model? In attached photo you can see that legs are in center position , and I want the whole model to be vertically centered… ! thank you
It’s normally best if you author the model’s center in a DCC tool like Blender. If you have to do this in code, you can compute the AABB of the model and then use it to center it. Meaning: