/
index.tsx
141 lines (134 loc) · 3.36 KB
/
index.tsx
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
'use client'
import { Canvas, useFrame } from '@react-three/fiber'
import {
Environment,
Center,
Lightformer,
Sparkles,
Shadow,
Sky,
} from '@react-three/drei'
import { Model } from './Fuku-san'
import { ReactNode, useRef, useState } from 'react'
export const Fuku3D = ({ position = [0, 0, 2.5], fov = 25 }: any) => {
const [perfSucks, degrade] = useState(true)
return (
<Canvas
shadows
camera={{ position, fov }}
gl={{ preserveDrawingBuffer: true }}
eventPrefix="client"
className="z-1"
//className='touch-none w-full h-full m-0 p-0 overflow-hidden user-select-none'
>
<Env perfSucks={perfSucks} />
<CameraRig>
<Center>
<Model scale={0.3} />
<Shadow
rotation={[-Math.PI / 2, 0, 0]}
scale={0.3}
position={[0, -0.3, 0]}
color={'black'}
opacity={0.5}
/>
</Center>
</CameraRig>
<Sparkles
count={25}
scale={0.3 * 2}
size={6}
speed={0.3}
color={'white'}
/>
<Sky
distance={450000}
sunPosition={[0, 1, 0.8]}
inclination={0}
azimuth={0.25}
/>
</Canvas>
)
}
type RigType = {
children: ReactNode
}
function CameraRig({ children }: RigType) {
const groupRef = useRef<THREE.Group>(null)
useFrame((state, delta) => {
if (groupRef.current) {
//console.info("group rotation", groupRef.current.rotation)
const rotationY = (Math.sin(state.clock.elapsedTime * 0.3) * Math.PI) / 3
groupRef.current.rotation.y = rotationY
//easing.damp3(state.camera.position, [-state.viewport.width / 4, 0, 2], 0.25, delta)
//easing.dampE(group.current.rotation, [state.pointer.y / 10, -state.pointer.x / 5, 0], 0.25, delta)
}
})
return <group ref={groupRef}>{children}</group>
}
type EnvProps = {
perfSucks: boolean
}
function Env({ perfSucks }: EnvProps) {
return (
<Environment
frames={perfSucks ? 1 : Infinity}
preset="sunset"
resolution={256}
background
blur={0.8}
>
<Lightformer
intensity={4}
rotation-x={Math.PI / 2}
position={[0, 5, -9]}
scale={[10, 10, 1]}
/>
<Lightformer
intensity={4}
rotation-x={Math.PI / 2}
position={[0, 5, -9]}
scale={[10, 10, 1]}
/>
<group rotation={[Math.PI / 2, 1, 0]}>
{[2, -2, 2, -4, 2, -5, 2, -9].map((x, i) => (
<Lightformer
key={i}
intensity={1}
rotation={[Math.PI / 4, 0, 0]}
position={[x, 4, i * 4]}
scale={[4, 1, 1]}
/>
))}
<Lightformer
intensity={0.5}
rotation-y={Math.PI / 2}
position={[-5, 1, -1]}
scale={[50, 2, 1]}
/>
<Lightformer
intensity={0.5}
rotation-y={Math.PI / 2}
position={[-5, -1, -1]}
scale={[50, 2, 1]}
/>
<Lightformer
intensity={0.5}
rotation-y={-Math.PI / 2}
position={[10, 1, 0]}
scale={[50, 2, 1]}
/>
</group>
<group>
<Lightformer
intensity={9}
form="ring"
color="white"
rotation-y={Math.PI / 2}
position={[-5, 2, -1]}
scale={[10, 10, 1]}
/>
</group>
</Environment>
)
}