-
Notifications
You must be signed in to change notification settings - Fork 1
/
Carpet.js
36 lines (28 loc) · 1018 Bytes
/
Carpet.js
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
import React, { useEffect, useMemo, useRef, useState } from "react";
import { useFrame, useLoader } from "@react-three/fiber";
import { Mesh } from "three";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
export const Carpet = ({ n }) => {
const group = useRef()
const url = "Models/Carpet/Carpet.gltf"
const gltf = useLoader(GLTFLoader, url);
const copiedScene = useMemo(() => gltf.scene.clone(), [gltf.scene])
const x = 0
const y = 0.4
useEffect(() => {
gltf.scene.scale.set(8, 4, 5);
// gltf.scene.rotation.set(0, 0, 0);
gltf.scene.traverse((object) => {
if (object instanceof Mesh) {
object.castShadow = true;
object.receiveShadow = true;
object.material.envMapIntensity = 20;
}
})
}, [gltf])
return (
<group ref={group}>
<primitive object={copiedScene} position={[x, y, n * -10]} scale={[8, 4, 5]} />
</group>
)
}