#
luxiaotao1123
2024-04-23 26dede87608f9ced212a3f76acd358dc4544747b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { useMemo } 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
                    castShadow
                    receiveShadow
                    geometry={nodes.物件_1001.geometry}
                    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}
                />
            </group>
        </>
    )
}
 
export default Shelf;