pmndrs / gltfjsx

🎮 Turns GLTFs into JSX components
https://gltf.pmnd.rs
MIT License
4.73k stars 312 forks source link

When using typescript - Property 'nodes' does not exist on type 'GLTF' #63

Open SakoMe opened 3 years ago

SakoMe commented 3 years ago

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');

Code47X commented 3 years ago

Did it generate a GLTFResult type for you? This type is used to typecast useGLTF().

image

utiq commented 3 years ago

@Code47X where did you export GLTF from?

alvindrakes commented 2 years ago

@utiq @Code47X Hi, May I know where does GLTF comes from?

Auto imports suggest it's from the examples folder.

Code47X commented 1 year ago

It looks like thats where it was imported from.

Screenshot 2023-03-21 at 1 22 45 PM
myznikovgleb commented 1 year ago

@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