I would like to know how to use the drei/native package. I can't import my glb file.
The error comes from here but I can't fix it : useGLTF({GlbImage})
Here is the error that returned to me:
Uncaught Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.
import React, { Suspense, useRef, useState, useEffect } from "react"
import { Canvas, useFrame } from "@react-three/fiber"
import { ContactShadows, Environment, useGLTF, OrbitControls } from "@react-three/drei/native"
import { HexColorPicker } from "react-colorful"
import { proxy, useSnapshot } from "valtio"
import GlbImage from '../../img/shoe-draco.glb'
// Using a Valtio state model to bridge reactivity between
// the canvas and the dom, both can write to it and/or react to it.
async function Shoe() {
const ref = useRef()
// Drei's useGLTF hook sets up draco automatically, that's how it differs from useLoader(GLTFLoader, url)
// { nodes, materials } are extras that come from useLoader, these do not exist in threejs/GLTFLoader
// nodes is a named collection of meshes, materials a named collection of materials
const { nodes, materials } = await useGLTF({GlbImage})
// Animate model
useFrame((state) => {
const t = state.clock.getElapsedTime()
ref.current.rotation.z = -0.2 - (1 + Math.sin(t / 1.5)) / 20
ref.current.rotation.x = Math.cos(t / 4) / 8
ref.current.rotation.y = Math.sin(t / 4) / 8
ref.current.position.y = (1 + Math.sin(t / 1.5)) / 10
})
// Cursor showing current color
// Using the GLTFJSX output here to wire in app-state and hook up events
return (
<group ref={ref} dispose={null}>
<mesh receiveShadow castShadow geometry={nodes.shoe.geometry} material={materials.laces} material-color="green" />
<mesh receiveShadow castShadow geometry={nodes.shoe_1.geometry} material={materials.mesh} material-color="green" />
<mesh receiveShadow castShadow geometry={nodes.shoe_2.geometry} material={materials.caps} material-color="green" />
<mesh receiveShadow castShadow geometry={nodes.shoe_3.geometry} material={materials.inner} material-color="green" />
<mesh receiveShadow castShadow geometry={nodes.shoe_4.geometry} material={materials.sole} material-color="green" />
<mesh receiveShadow castShadow geometry={nodes.shoe_5.geometry} material={materials.stripes} material-color="green" />
<mesh receiveShadow castShadow geometry={nodes.shoe_6.geometry} material={materials.band} material-color="green" />
<mesh receiveShadow castShadow geometry={nodes.shoe_7.geometry} material={materials.patch} material-color="green" />
</group>
)
}
export default function ScreenFinal() {
return (
<>
<Canvas shadows dpr={[1, 2]} camera={{ position: [0, 0, 4], fov: 50 }}>
<ambientLight intensity={0.7} />
<spotLight intensity={0.5} angle={0.1} penumbra={1} position={[10, 15, 10]} castShadow />
<Suspense fallback={null}>
<Shoe />
<Environment preset="city" />
<ContactShadows rotation-x={Math.PI / 2} position={[0, -0.8, 0]} opacity={0.25} width={10} height={10} blur={1.5} far={0.8} />
</Suspense>
<OrbitControls minPolarAngle={Math.PI / 2} maxPolarAngle={Math.PI / 2} enableZoom={false} enablePan={false} />
</Canvas>
</>
)
}