I am trying to load a .glb file with react-three-fiber and I get the following error.
Error Unexpected token c in JSON at position 3
I'm not sure what I am doing wrong - it appears the most common solution to this problem is having the .glb file in your public folder (which I do). So I'm at a loss here.
Here is the codesandbox
https://codesandbox.io/s/gltfloader-forked-5nkzl?file=/src/App.js
Here is the code anyways:
import "./styles.css";
import { Suspense } from "react";
import { Canvas, useLoader } from "@react-three/fiber";
import { Environment, OrbitControls } from "@react-three/drei";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
const Model = () => {
const gltf = useLoader(GLTFLoader, './scene.glb');
return (
<>
<primitive object={gltf.scene} scale={0.4} />
</>
);
};
export default function App() {
return (
<div className="App">
<Canvas>
<Suspense fallback={null}>
<Model />
<OrbitControls />
<Environment preset="sunset" background />
</Suspense>
</Canvas>
</div>
);
}
Any help would be immensely appreciated.