| | |
| | | import { useMemo } from 'react'; |
| | | import { useMemo, useState, useEffect } from 'react'; |
| | | 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 dracoLoader = new DRACOLoader(); |
| | | dracoLoader.setDecoderPath('draco/'); |
| | | useGLTF.setDecoderPath('/draco/'); |
| | | // const { scene } = useGLTF('/models/shelf/row.glb', '/draco/'); |
| | | |
| | | const { nodes, materials } = useGLTF('/models/shelf/row.glb'); |
| | | console.log(nodes); |
| | | |
| | | |
| | | const { nodes: nodes1, materials1, animations } = useGLTF('/models/shelf/Horse.glb'); |
| | | |
| | | return ( |
| | | <> |
| | | <group rotation-y={rotationY} position={position}> |
| | | <primitive object={generateScene()} /> |
| | | <mesh |
| | | <primitive |
| | | castShadow |
| | | receiveShadow |
| | | geometry={nodes.物件_1001.geometry} |
| | | object={nodes.物件_1001} |
| | | material={materials['材质_1.002']} |
| | | position={[0, 2, 0.3]} |
| | | rotation={[Math.PI / 2, 0, Math.PI / 2]} |
| | | scale={70} |
| | | /> |
| | | <mesh |
| | | castShadow |
| | | receiveShadow |
| | | geometry={nodes1.mesh_0.geometry} |
| | | material={nodes1.mesh_0.material} |
| | | morphTargetDictionary={nodes1.mesh_0.morphTargetDictionary} |
| | | morphTargetInfluences={nodes1.mesh_0.morphTargetInfluences} |
| | | position={[0, 0, 0]} |
| | | scale={10000} |
| | | /> |
| | | </group> |
| | | </> |