-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
391 lines (249 loc) · 8.35 KB
/
index.html
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<!DOCTYPE html>
<html lang="en">
<head>
<title>EraX</title>
<meta charset="utf-8">
<style>
#my_canvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
img {
position: absolute;
/* background-color: black; */
max-width: 70%;
top: 10%;
left: 50%;
transform: translate(-50%, 50%);
user-select: none;
-moz-user-select: none;
-webkit-user-drag: none;
-webkit-user-select: none;
-ms-user-select: none;
}
</style>
</head>
<body>
<div id="container"></div>
<img src="logo.png" alt="">
<canvas id="my_canvas"></canvas>
<script type="module">
import * as THREE from './build/three.module.js';
import { EffectComposer } from './postprocessing/EffectComposer.js';
import { RenderPass } from './postprocessing/RenderPass.js';
import { ShaderPass } from './postprocessing/ShaderPass.js';
import { BloomPass } from './postprocessing/BloomPass.js';
import { FilmPass } from './postprocessing/FilmPass.js';
import { FocusShader } from './shaders/FocusShader.js';
import { OBJLoader } from './loaders/OBJLoader.js';
let camera, scene, renderer, mesh;
let parent;
const meshes = [], clonemeshes = [];
let composer, effectFocus;
const clock = new THREE.Clock();
let stats;
init();
animate();
function init() {
const container = document.querySelector('#container');
camera = new THREE.PerspectiveCamera(20, window.innerWidth / window.innerHeight, 1, 50000);
camera.position.set(0, 700, 7000);
scene = new THREE.Scene();
scene.background = new THREE.Color(0x000104);
scene.fog = new THREE.FogExp2(0x000104, 0.0000675);
camera.lookAt(scene.position);
const loader = new OBJLoader();
loader.load('male.obj', function (object) {
const positions = combineBuffer(object, 'position');
createMesh(positions, scene, 4.05, - 500, - 350, 600, 0xff7744);
createMesh(positions, scene, 4.05, 500, - 350, 0, 0xff5522);
createMesh(positions, scene, 4.05, - 250, - 350, 1500, 0xff9922);
createMesh(positions, scene, 4.05, - 250, - 350, - 1500, 0xff99ff);
});
loader.load('female.obj', function (object) {
const positions = combineBuffer(object, 'position');
createMesh(positions, scene, 4.05, - 1000, - 350, 0, 0xffdd44);
createMesh(positions, scene, 4.05, 0, - 350, 0, 0xffffff);
createMesh(positions, scene, 4.05, 1000, - 350, 400, 0xff4422);
createMesh(positions, scene, 4.05, 250, - 350, 1500, 0xff9955);
createMesh(positions, scene, 4.05, 250, - 350, 2500, 0xff77dd);
});
renderer = new THREE.WebGLRenderer({ canvas: my_canvas });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.autoClear = false;
container.appendChild(renderer.domElement);
parent = new THREE.Object3D();
scene.add(parent);
const grid = new THREE.Points(new THREE.PlaneGeometry(15000, 15000, 64, 64), new THREE.PointsMaterial({ color: 0xff0000, size: 10 }));
grid.position.y = - 400;
grid.rotation.x = - Math.PI / 2;
parent.add(grid);
// postprocessing
const renderModel = new RenderPass(scene, camera);
const effectBloom = new BloomPass(0.75);
const effectFilm = new FilmPass(0.5, 0.5, 1448, false);
effectFocus = new ShaderPass(FocusShader);
effectFocus.uniforms["screenWidth"].value = window.innerWidth * window.devicePixelRatio;
effectFocus.uniforms["screenHeight"].value = window.innerHeight * window.devicePixelRatio;
composer = new EffectComposer(renderer);
composer.addPass(renderModel);
composer.addPass(effectBloom);
composer.addPass(effectFilm);
composer.addPass(effectFocus);
//stats
window.addEventListener('resize', onWindowResize);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
camera.lookAt(scene.position);
renderer.setSize(window.innerWidth, window.innerHeight);
composer.setSize(window.innerWidth, window.innerHeight);
effectFocus.uniforms["screenWidth"].value = window.innerWidth * window.devicePixelRatio;
effectFocus.uniforms["screenHeight"].value = window.innerHeight * window.devicePixelRatio;
}
function combineBuffer(model, bufferName) {
let count = 0;
model.traverse(function (child) {
if (child.isMesh) {
const buffer = child.geometry.attributes[bufferName];
count += buffer.array.length;
}
});
const combined = new Float32Array(count);
let offset = 0;
model.traverse(function (child) {
if (child.isMesh) {
const buffer = child.geometry.attributes[bufferName];
combined.set(buffer.array, offset);
offset += buffer.array.length;
}
});
return new THREE.BufferAttribute(combined, 3);
}
function createMesh(positions, scene, scale, x, y, z, color) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', positions.clone());
geometry.setAttribute('initialPosition', positions.clone());
geometry.attributes.position.setUsage(THREE.DynamicDrawUsage);
const clones = [
[6000, 0, - 4000],
[5000, 0, 0],
[1000, 0, 5000],
[1000, 0, - 5000],
[4000, 0, 2000],
[- 4000, 0, 1000],
[- 5000, 0, - 5000],
[0, 0, 0]
];
for (let i = 0; i < clones.length; i++) {
const c = (i < clones.length - 1) ? 0x252525 : color;
mesh = new THREE.Points(geometry, new THREE.PointsMaterial({ size: 30, color: c }));
mesh.scale.x = mesh.scale.y = mesh.scale.z = scale;
mesh.position.x = x + clones[i][0];
mesh.position.y = y + clones[i][1];
mesh.position.z = z + clones[i][2];
parent.add(mesh);
clonemeshes.push({ mesh: mesh, speed: 0.5 + Math.random() });
}
meshes.push({
mesh: mesh, verticesDown: 0, verticesUp: 0, direction: 0, speed: 15, delay: Math.floor(200 + 200 * Math.random()),
start: Math.floor(100 + 200 * Math.random()),
});
}
function animate() {
requestAnimationFrame(animate);
render();
stats.update();
}
function render() {
let delta = 10 * clock.getDelta();
delta = delta < 2 ? delta : 2;
parent.rotation.y += - 0.02 * delta;
for (let j = 0; j < clonemeshes.length; j++) {
const cm = clonemeshes[j];
cm.mesh.rotation.y += - 0.1 * delta * cm.speed;
}
for (let j = 0; j < meshes.length; j++) {
const data = meshes[j];
const positions = data.mesh.geometry.attributes.position;
const initialPositions = data.mesh.geometry.attributes.initialPosition;
const count = positions.count;
if (data.start > 0) {
data.start -= 1;
} else {
if (data.direction === 0) {
data.direction = - 1;
}
}
for (let i = 0; i < count; i++) {
const px = positions.getX(i);
const py = positions.getY(i);
const pz = positions.getZ(i);
// falling down
if (data.direction < 0) {
if (py > 0) {
positions.setXYZ(
i,
px + 1.5 * (0.50 - Math.random()) * data.speed * delta,
py + 3.0 * (0.25 - Math.random()) * data.speed * delta,
pz + 1.5 * (0.50 - Math.random()) * data.speed * delta
);
} else {
data.verticesDown += 1;
}
}
// rising up
if (data.direction > 0) {
const ix = initialPositions.getX(i);
const iy = initialPositions.getY(i);
const iz = initialPositions.getZ(i);
const dx = Math.abs(px - ix);
const dy = Math.abs(py - iy);
const dz = Math.abs(pz - iz);
const d = dx + dy + dx;
if (d > 1) {
positions.setXYZ(
i,
px - (px - ix) / dx * data.speed * delta * (0.85 - Math.random()),
py - (py - iy) / dy * data.speed * delta * (1 + Math.random()),
pz - (pz - iz) / dz * data.speed * delta * (0.85 - Math.random())
);
} else {
data.verticesUp += 1;
}
}
}
// all vertices down
if (data.verticesDown >= count) {
if (data.delay <= 0) {
data.direction = 1;
data.speed = 5;
data.verticesDown = 0;
data.delay = 320;
} else {
data.delay -= 1;
}
}
// all vertices up
if (data.verticesUp >= count) {
if (data.delay <= 0) {
data.direction = - 1;
data.speed = 15;
data.verticesUp = 0;
data.delay = 120;
} else {
data.delay -= 1;
}
}
positions.needsUpdate = true;
}
composer.render(0.01);
}
</script>
</body>
</html>