I think I'm following the react-three docs and many other examples, but cannot get drei useGLTF to work as others have.
I have a simple, from-scratch, Next|React|react-three/fiber project. I'm simply trying to load the example astronaut and display it.
I believe the following code actually worked perfectly for a while. After some minor changes and undo's I think I arrived back at the same code, which now doesn't work. (I've tried with and without Suspense.)
import { Canvas, Suspense } 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>
)
}
Here is my package.json:
{
"name": "cfgnext",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@react-three/drei": "^8.18.10",
"@react-three/fiber": "^7.0.26",
"next": "12.1.0",
"react": "17.0.2",
"react-dom": "^17.0.2",
"styled-components": "^5.3.3"
},
"devDependencies": {
"eslint": "8.11.0",
"eslint-config-next": "12.1.0"
}
}
From everything I've read this should be quite simple. Can someone please tell me where I'm going wrong.
tia, Bill