| | |
| | | import { useGLTF } from '@react-three/drei'; |
| | | import * as THREE from 'three'; |
| | | import { MODEL_SHELF_SCALE } from '@/config/setting' |
| | | import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader'; |
| | | import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'; |
| | | |
| | | const generateScene = async () => { |
| | | const loader = new GLTFLoader(); |
| | | const dracoLoader = new DRACOLoader(); |
| | | dracoLoader.setDecoderPath('/draco/'); |
| | | loader.setDRACOLoader(dracoLoader); |
| | | |
| | | return await new Promise((resolve, reject) => { |
| | | loader.load('/models/shelf/row.glb', function (mesh) { |
| | | console.log(mesh); |
| | | resolve(mesh.scene) |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | const Shelf = (props) => { |
| | | const { position = [0, 300, 0], rotationY = 0 } = props; |
| | | |
| | | const { scene } = useGLTF('/models/shelf/row.glb'); |
| | | console.log(scene); |
| | | const dracoLoader = new DRACOLoader(); |
| | | dracoLoader.setDecoderPath('draco/'); |
| | | useGLTF.setDecoderPath('/draco/'); |
| | | // const { scene } = useGLTF('/models/shelf/row.glb', '/draco/'); |
| | | |
| | | const model = useMemo(() => scene.clone(), [scene]); |
| | | const { nodes, materials } = useGLTF('/models/shelf/row.glb'); |
| | | console.log(nodes); |
| | | |
| | | |
| | | const { nodes: nodes1, materials1, animations } = useGLTF('/models/shelf/Horse.glb'); |
| | | |
| | | return ( |
| | | <> |
| | | <mesh position={position}> |
| | | <boxGeometry args={[50, 50, 50]} /> |
| | | <meshStandardMaterial color={'hotpink'} /> |
| | | </mesh> |
| | | {/* <group rotation-y={rotationY} position={position}> |
| | | <primitive |
| | | object={model} |
| | | <group rotation-y={rotationY} position={position}> |
| | | <primitive object={generateScene()} /> |
| | | <mesh |
| | | castShadow |
| | | receiveShadow |
| | | scale={[MODEL_SHELF_SCALE, MODEL_SHELF_SCALE, MODEL_SHELF_SCALE]} |
| | | geometry={nodes.物件_1001.geometry} |
| | | material={materials['材质_1.002']} |
| | | position={[0, 2, 0.3]} |
| | | rotation={[Math.PI / 2, 0, Math.PI / 2]} |
| | | scale={70} |
| | | /> |
| | | </group> */} |
| | | <mesh |
| | | castShadow |
| | | receiveShadow |
| | | geometry={nodes1.mesh_0.geometry} |
| | | material={nodes1.mesh_0.material} |
| | | morphTargetDictionary={nodes1.mesh_0.morphTargetDictionary} |
| | | morphTargetInfluences={nodes1.mesh_0.morphTargetInfluences} |
| | | /> |
| | | </group> |
| | | </> |
| | | ) |
| | | } |