I’m not sure what I am doing wrong. I am trying to load a glft in react-three-fibre with TypeScript. But I am unable to load the model and only get a vague error message.
I’ve also looked into the documentation from react-three-fibre how to load a model but it uses JavaScript. I guess my problem is with due to TypeScript
Also, I saw from some similar problems posted that dated library versions could be culprit.
Not sure if this is helpful, but the working example simply uses:
import { Suspense } from 'react'
import { Canvas } from '@react-three/fiber'
import { useGLTF } from '@react-three/drei'
function Model() {
const gltf = useGLTF('https://thinkuldeep.com/modelviewer/Astronaut.glb')
return (<primitive object={gltf.scene} />)
}
export default function Home() {
return (
<div>
<Suspense>
<Canvas>
<ambientLight />
<Model />
</Canvas>
</Suspense>
</div>
)
}
I’ve traced it back to Ionic. I’ve tested a setup with a clean react project using this Getting Started | Create React App and the same code from above worked without a problem.
So, I conclude for myself, it is not an issue of react-three-fibre and TypeScript but an Ionic with React issue. I might have to rethink my strategy and switch to a pure React project instead of using Ionic with React.
maybe for have figured out already but for sure this is not a path. “src” does not exist, it is virtual. the bundler will take all these folders and files and create a bundle, a single file, from it. browser url fetching something from “src/…” hence doesn’t compute. this is not react or three, it goes for bundling in general.
your file has to be located in /public/LittlestTokyo.glb and the path will have to be “/LittlestTokyo.glb”