-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ethereum.js
48 lines (36 loc) · 1.42 KB
/
Ethereum.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
37
38
39
40
41
42
43
44
45
46
47
48
import React, { useEffect, 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 Ethereum = ({ position, scale }) => {
const Ref = useRef();
const url = "Models/Ethereum3/Ethereum3.gltf"
const gltf = useLoader(GLTFLoader, url);
const [xRotSpeed] = useState(() => Math.random());
const [yRotSpeed] = useState(() => Math.random());
useFrame((state, delta) => {
gltf.scene.traverse((object) => {
if (object instanceof Mesh) {
object.rotation.y += delta * xRotSpeed
}
// Ref.current.rotation.x += delta * xRotSpeed
// Ref.current.rotation.y += delta * yRotSpeed
// console.log(boxRef.current)
})
}, [xRotSpeed, yRotSpeed]);
useEffect(() => {
// gltf.scene.scale.set(0.05, 0.005, 0.005);
gltf.scene.traverse((object) => {
if (object instanceof Mesh) {
object.castShadow = true;
object.receiveShadow = true;
object.material.envMapIntensity = 20;
}
})
}, [gltf])
return (
<group ref={Ref}>
<primitive object={gltf.scene} position={position} scale={scale} />
</group>
)
}