Open SakoMe opened 3 years ago
Did it generate a GLTFResult
type for you? This type is used to typecast useGLTF()
.
@Code47X where did you export GLTF from?
@utiq @Code47X Hi, May I know where does GLTF comes from?
Auto imports suggest it's from the examples folder.
It looks like thats where it was imported from.
@SakoMe
It seems like you've missed to add the type GLTFResult
provided with command
npx gltfjsx [model.gltf] -t
I've tried to reproduce scenario when command above fails with exported from Blender 3.4 default model (cube). But everything seems to work fine. My result
/*
Auto-generated by: https://github.com/pmndrs/gltfjsx
Command: npx gltfjsx@6.2.10 box.gltf -t
*/
import * as THREE from 'three'
import React, { useRef } from 'react'
import { useGLTF } from '@react-three/drei'
import { GLTF } from 'three-stdlib'
type GLTFResult = GLTF & {
nodes: {
Cube: THREE.Mesh
}
materials: {}
}
export function Model(props: JSX.IntrinsicElements['group']) {
const { nodes, materials } = useGLTF('/box.gltf') as GLTFResult
return (
<group {...props} dispose={null}>
<mesh geometry={nodes.Cube.geometry} material={nodes.Cube.material} />
</group>
)
}
useGLTF.preload('/box.gltf')
NB
You can also try to test your model with web version. Just do not forget to enable types
option
More of a question than an issue. When using it with a TS React project can't seem to get around this error - any ideas? Thanks! (Should mention that I did run it with the -t flag)
const { nodes, materials } = useGLTF('/scene.gltf');