-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
1808 lines (1560 loc) · 67.7 KB
/
script.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
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import * as THREE from "three";
import vshaderString from "./shaders/string/vertex.glsl?raw";
import fshaderString from "./shaders/string/fragment.glsl?raw";
import vshaderString2 from "./shaders/string/vertex2.glsl?raw";
import fshaderString2 from "./shaders/string/fragment2.glsl?raw";
import vshaderString3 from "./shaders/string/vertex3.glsl?raw";
import fshaderString3 from "./shaders/string/fragment3.glsl?raw";
import vshaderString4 from "./shaders/string/vertex4.glsl?raw";
import fshaderString4 from "./shaders/string/fragment4.glsl?raw";
import vshaderProton from "./shaders/proton/vertex.glsl?raw";
import fshaderProton from "./shaders/proton/fragment.glsl?raw";
import vshaderQuark from "./shaders/quark/vertex.glsl?raw";
import fshaderQuark from "./shaders/quark/fragment.glsl?raw";
import vshaderMolecule from "./shaders/molecule/vertex.glsl?raw";
import fshaderMolecule from "./shaders/molecule/fragment.glsl?raw";
import vshaderCloud from "./shaders/cloud/vertex.glsl?raw";
import fshaderCloud from "./shaders/cloud/fragment.glsl?raw";
import vshaderLightning from "./shaders/lightning/vertex.glsl?raw";
import fshaderLightning from "./shaders/lightning/fragment.glsl?raw";
import vshaderLanding1 from "./shaders/landingshaders/vertex1.glsl?raw";
import fshaderLanding1 from "./shaders/landingshaders/fragment1.glsl?raw";
import vshaderLanding3 from "./shaders/landingshaders/vertex3.glsl?raw";
import fshaderLanding3 from "./shaders/landingshaders/fragment3.glsl?raw";
import { FontLoader } from "three/examples/jsm/loaders/FontLoader.js";
import { TextGeometry } from "three/examples/jsm/geometries/TextGeometry.js";
import { Water } from "three/examples/jsm/objects/Water.js";
import { Sky } from "three/examples/jsm/objects/Sky.js";
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass.js';
import { UnrealBloomPass } from 'three/examples/jsm/postprocessing/UnrealBloomPass.js';
import { OutputPass } from 'three/examples/jsm/postprocessing/OutputPass.js';
import { TessellateModifier } from 'three/examples/jsm/modifiers/TessellateModifier.js';
import { ImprovedNoise } from 'three/examples/jsm/math/ImprovedNoise.js'
import { CSS2DRenderer, CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer.js'
import WebGL from 'three/examples/jsm//capabilities/WebGL.js';
let scene,
camera,
renderer,
alight,
animeIDs,
canvas,
textureLoader,
protonTexture,
fontLoader,
clock,
width,
height,
labelRenderer;
const init = () => {
animeIDs = new Object();
canvas = document.getElementById("canvas");
scene = new THREE.Scene();
scene.background = new THREE.Color(0x00030c);
width = window.innerWidth;
height = window.innerHeight;
camera = new THREE.PerspectiveCamera(
35,
width / height,
0.001,
5000
);
camera.position.x = 0;
camera.position.y = 0;
camera.position.z = -1;
scene.add(camera);
renderer = new THREE.WebGLRenderer({
canvas,
alpha: true,
antialias: true,
});
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
labelRenderer = new CSS2DRenderer();
labelRenderer.setSize(window.innerWidth, window.innerHeight);
labelRenderer.domElement.style.position = 'absolute';
labelRenderer.domElement.style.top = '0px';
document.body.appendChild(labelRenderer.domElement);
textureLoader = new THREE.TextureLoader();
protonTexture = textureLoader.load("/textures/blue-clouds.jpg");
fontLoader = new FontLoader();
alight = new THREE.AmbientLight(0xffffff, 1000);
scene.add(alight);
clock = new THREE.Clock();
window.addEventListener("resize", () => {
width = window.innerWidth;
height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
labelRenderer.setSize(width, height);
});
window.addEventListener("dblclick", () => {
const fullscreenElement =
document.fullscreenElement || document.webkitFullscreenElement;
if (!fullscreenElement) {
if (canvas.requestFullscreen) {
canvas.requestFullscreen();
} else if (canvas.webkitRequestFullscreen) {
canvas.webkitRequestFullscreen();
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
});
landing();
};
const landing = () => {
camera.position.set(0, 0, 499);
window.scrollTo(0, 0);
fontLoader.load('./fonts/p1.typeface.json', function (font) {
const scrollText = 'Scroll To Navigate';
const text0 = 'Drift Into The Abstract';
const text = 'Désobéir';
const text2 = '( French Verb, Meaning, To Disobey )';
const text3 = 'Disobey the rule of a 2D web';
const text4 = "It's too much of a cruel rule!";
const text5 = 'Worlds Within Worlds';
const text6 = 'Version a.0.0.1';
const text7 = 'A WebGL Experience by desobe.ir';
const ringGeo = new THREE.RingGeometry(5, 5.5, 32);
const ringMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff });
const ring = new THREE.Mesh(ringGeo, ringMaterial);
ringGeo.scale(1, 2, 1);
const circleGeometry = new THREE.CircleGeometry(2.7);
const circleMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff });
const circle = new THREE.Mesh(circleGeometry, circleMaterial);
let worldsSphereRadius = width >= height ? 250 : 125;
const worldsSphereGeo = new THREE.SphereGeometry(worldsSphereRadius, 32, 32);
const worldsSphereMaterial = new THREE.ShaderMaterial({
side: THREE.BackSide,
vertexShader: vshaderLanding1,
fragmentShader: fshaderLanding1,
uniforms: {
time: { value: 0 },
resolution: { value: new THREE.Vector2(width, height) },
}
});
const worldsSphere = new THREE.Mesh(worldsSphereGeo, worldsSphereMaterial);
worldsSphere.rotation.z = Math.PI / 2;
worldsSphere.rotation.y = Math.PI / 2;
worldsSphere.position.set(0, 0, -750);
scene.add(worldsSphere);
const textOptions = {
font: font,
curveSegments: 12,
bevelEnabled: false,
bevelThickness: 0.1,
bevelSize: 0.1,
bevelOffset: 0,
bevelSegments: 5
};
// 1
textOptions.size = width >= height ? 30 : 15;
textOptions.height = width >= height ? 8 : 5;
const textGeometry = new TextGeometry(text, textOptions);
textGeometry.center();
const textMaterial = new THREE.MeshStandardMaterial({ color: 0x151600 });
const textMesh = new THREE.Mesh(textGeometry, textMaterial);
scene.add(textMesh);
//0
textOptions.size = width >= height ? 8 : 5;
textOptions.height = width >= height ? .2 : .1;
const text0Geometry = new TextGeometry(text0, textOptions);
text0Geometry.center();
const text0Material = textMaterial.clone();
text0Material.color = new THREE.Color(0xffffff);
const text0Mesh = new THREE.Mesh(text0Geometry, text0Material);
text0Mesh.position.set(0, 25, 0);
scene.add(text0Mesh);
//2
textOptions.size = width >= height ? 5 : 3;
textOptions.height = width >= height ? .2 : .1;
const text2Geometry = new TextGeometry(text2, textOptions);
text2Geometry.center();
const text2Material = textMaterial.clone();
text2Material.color = new THREE.Color(0xffffff);
const text2Mesh = new THREE.Mesh(text2Geometry, text2Material);
text2Mesh.position.set(0, -25, 0);
scene.add(text2Mesh);
// textRule
textOptions.size = width >= height ? 5 : 3;
textOptions.height = width >= height ? 1 : .3;
const textRuleGeometry = new TextGeometry(text3, textOptions);
textRuleGeometry.center();
const textRuleMaterial = textMaterial.clone();
textRuleMaterial.color = new THREE.Color(0xffffff);
const textRuleMesh = new THREE.Mesh(textRuleGeometry, textRuleMaterial);
textRuleMesh.position.set(0, 0, -300);
scene.add(textRuleMesh);
textRuleMesh.visible = false;
// textCruel
const textCruelGeometry = new TextGeometry(text4, textOptions);
textCruelGeometry.center();
const textCruelMaterial = textMaterial.clone();
textCruelMaterial.color = new THREE.Color(0xffffff);
const textCruelMesh = new THREE.Mesh(textCruelGeometry, textCruelMaterial);
textCruelMesh.position.set(0, -30, -450);
scene.add(textCruelMesh);
textCruelMesh.visible = false;
// textVersion
textOptions.size = width >= height ? 3 : 2;
textOptions.height = width >= height ? 1 : .2;
const textVersionGeometry = new TextGeometry(text6, textOptions);
textVersionGeometry.center();
const textVersionMaterial = textMaterial.clone();
textVersionMaterial.color = new THREE.Color(0xffffff);
const textVersionMesh = new THREE.Mesh(textVersionGeometry, textVersionMaterial);
textVersionMesh.position.set(40, 30, -800);
scene.add(textVersionMesh);
textVersionMesh.visible = false;
// textCredit
textOptions.size = width >= height ? 6 : 3;
textOptions.height = width >= height ? 1 : .3;
const textCreditGeometry = new TextGeometry(text7, textOptions);
textCreditGeometry.center();
const textCreditMaterial = textMaterial.clone();
textCreditMaterial.color = new THREE.Color(0xffffff);
const textCreditMesh = new THREE.Mesh(textCreditGeometry, textCreditMaterial);
textCreditMesh.position.set(0, 10, -800);
scene.add(textCreditMesh);
textCreditMesh.visible = false;
// play
const play = new THREE.Group();
textOptions.size = width >= height ? 5 : 2;
textOptions.height = width >= height ? 1 : .2;
const textPlayGeometry = new TextGeometry('Play', textOptions);
textPlayGeometry.center();
const textPlayMaterial = textMaterial.clone();
textPlayMaterial.color = new THREE.Color(0xf2be22);
const textPlayMesh = new THREE.Mesh(textPlayGeometry, textPlayMaterial);
textPlayMesh.position.set(-2.5, 0, 0);
let coneRadius = width >= height ? 20 : 10;
let coneHeight = width >= height ? 40 : 20;
const coneGeometry = new THREE.ConeGeometry(coneRadius, coneHeight, 3);
textPlayMaterial.wireframe = true;
const playIcon = new THREE.Mesh(coneGeometry, textPlayMaterial);
playIcon.rotation.z = - Math.PI / 2;
play.add(textPlayMesh, playIcon);
play.position.set(0, -30, -800);
scene.add(play);
play.visible = false;
// tessellation
textOptions.size = width >= height ? 15 : 6;
textOptions.height = width >= height ? 3 : .5;
let tessellatedGeometry = new TextGeometry(text5, textOptions);
tessellatedGeometry.center();
const tessellatedMaterial = new THREE.ShaderMaterial({
uniforms: {
amplitude: { value: 100.0 }
},
vertexShader: vshaderLanding3,
fragmentShader: fshaderLanding3,
});
const tessellateModifier = new TessellateModifier(8, 6);
tessellatedGeometry = tessellateModifier.modify(tessellatedGeometry);
const numFaces = tessellatedGeometry.attributes.position.count / 3;
const colors = new Float32Array(numFaces * 3 * 3);
const displacement = new Float32Array(numFaces * 3 * 3);
const color = new THREE.Color();
for (let f = 0; f < numFaces; f++) {
const index = 9 * f;
const h = 0.2 * Math.random();
const s = 0.5 + 0.5 * Math.random();
const l = 0.2 + 0.5 * Math.random();
color.setHSL(h, s, l);
const d = 10 * (0.5 - Math.random());
for (let i = 0; i < 3; i++) {
colors[index + (3 * i)] = color.r;
colors[index + (3 * i) + 1] = color.g;
colors[index + (3 * i) + 2] = color.b;
displacement[index + (3 * i)] = d;
displacement[index + (3 * i) + 1] = d;
displacement[index + (3 * i) + 2] = d;
}
}
tessellatedGeometry.setAttribute('customColor', new THREE.BufferAttribute(colors, 3));
tessellatedGeometry.setAttribute('displacement', new THREE.BufferAttribute(displacement, 3));
const tessellatedMesh = new THREE.Mesh(tessellatedGeometry, tessellatedMaterial);
tessellatedMesh.position.set(0, 50, -800);
scene.add(tessellatedMesh);
tessellatedMesh.visible = false;
textOptions.size = width >= height ? 5 : 2;
textOptions.height = 0.2;
const scrollTextGeometry = new TextGeometry(scrollText, textOptions);
scrollTextGeometry.center();
const scrollTextMaterial = textMaterial.clone();
scrollTextMaterial.color = new THREE.Color(0xffffff);
const scrollTextMesh = new THREE.Mesh(scrollTextGeometry, scrollTextMaterial);
scrollTextMesh.position.set(0, -25, 0);
scrollTextMesh.lookAt(camera.position);
let scrollIcon = new THREE.Group();
scrollIcon.add(scrollTextMesh, circle, ring);
scrollIcon.position.set(-50, -110, 25);
scene.add(scrollIcon);
textMesh.lookAt(camera.position);
//particles
const ringParticleCount = 4000;
const ringParticles = new THREE.BufferGeometry();
const ringParticlePositions = new Float32Array(ringParticleCount * 3);
for (let i = 0; i < ringParticleCount; i++) {
const angle = Math.random() * Math.PI * 2;
const radius = width >= height ? 100 : 50;
const x = Math.cos(angle) * radius;
const y = Math.sin(angle) * radius;
ringParticlePositions[i * 3] = x;
ringParticlePositions[i * 3 + 1] = y;
ringParticlePositions[i * 3 + 2] = 0;
}
ringParticles.setAttribute('position', new THREE.BufferAttribute(ringParticlePositions, 3));
const ringParticleMaterial = new THREE.PointsMaterial({
color: 0xffffff,
size: 10,
map: new THREE.TextureLoader().load('./textures/disc.png'),
blending: THREE.AdditiveBlending,
transparent: true
});
const ringParticleSystem = new THREE.Points(ringParticles, ringParticleMaterial);
scene.add(ringParticleSystem);
// clicking
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
const pointermoveCallback = (event) => {
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = - (event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
const intersects = raycaster.intersectObject(play);
if (intersects.length > 0) {
textPlayMaterial.color.set(0x000000);
} else {
textPlayMaterial.color.set(0xf2be22);
}
};
document.addEventListener('pointermove', pointermoveCallback);
//fadePlane
const fadePlaneGeo = new THREE.PlaneGeometry(200, 200);
const fadePlaneMaterial = new THREE.MeshBasicMaterial({ color: 0x000000, transparent: true, opacity: 0 });
const fadePlane = new THREE.Mesh(fadePlaneGeo, fadePlaneMaterial);
let fadeFlag = false;
const clickCallback = (event) => {
raycaster.setFromCamera(mouse, camera);
const intersects = raycaster.intersectObject(play);
if (intersects.length > 0) {
textPlayMaterial.color.set(0x121200);
fadePlane.position.set(camera.position.x, camera.position.y, camera.position.z - 0.1);
scene.add(fadePlane);
fadeFlag = true;
}
}
document.addEventListener('click', clickCallback);
//scrolling
let scrollY = window.scrollY;
const maxScrollY = Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);
const amplitudeRange = 100 - 1;
const scrollRange = maxScrollY * 0.2;
let amplitudeValue = Math.max(100 - (window.scrollY - 0.55 * maxScrollY) / scrollRange * amplitudeRange, 1);
let lastScrollY = window.scrollY;
const scrollCallback = (e) => {
scrollY = window.scrollY;
const scrollPercent = scrollY / maxScrollY;
text2Mesh.lookAt(camera.position);
textRuleMesh.lookAt(camera.position);
textCruelMesh.lookAt(camera.position);
let disPosition = scrollY / window.innerHeight * 100;
let scrollIconPosition = disPosition + 110;
text0Mesh.position.x = Math.sin(disPosition * 0.2);
textMesh.position.y = disPosition * 0.1;
scrollIcon.position.y = -scrollIconPosition;
if (scrollPercent < 0.2) {
textVersionMesh.visible = false;
textCreditMesh.visible = false;
play.visible = false;
tessellatedMesh.visible = false;
textRuleMesh.visible = false;
textCruelMesh.visible = false;
camera.position.z = -disPosition + 499;
} else if (scrollPercent >= 0.2 && scrollPercent < 0.4) {
textVersionMesh.visible = false;
textCreditMesh.visible = false;
play.visible = false;
tessellatedMesh.visible = false;
textRuleMesh.visible = true;
textCruelMesh.visible = false;
camera.position.z = -disPosition + 499;
}
else if (scrollPercent >= 0.4 && scrollPercent < 0.55) {
textVersionMesh.visible = false;
textCreditMesh.visible = false;
play.visible = false;
tessellatedMesh.visible = false;
camera.position.z = -disPosition + 499;
textCruelMesh.visible = true;
}
else if (scrollPercent >= 0.55 && scrollPercent <= 0.76) {
textVersionMesh.visible = false;
textCreditMesh.visible = false;
play.visible = false;
tessellatedMesh.visible = true;
if (scrollY > lastScrollY) {
amplitudeValue = Math.max(amplitudeValue - (scrollY - lastScrollY) / scrollRange * amplitudeRange, 1);
} else if (scrollY < lastScrollY) {
amplitudeValue = Math.min(amplitudeValue + (lastScrollY - scrollY) / scrollRange * amplitudeRange, 100);
}
if (scrollPercent >= 0.75) {
tessellatedMesh.material.uniforms.amplitude.value = 0
} else {
tessellatedMesh.material.uniforms.amplitude.value = amplitudeValue;
}
lastScrollY = scrollY;
}
else if (scrollPercent > 0.76 && scrollPercent <= 0.85) {
textVersionMesh.visible = false;
textCreditMesh.visible = false;
play.visible = false;
textVersionMesh.visible = true;
} else if (scrollPercent > 0.85 && scrollPercent <= 0.90) {
textVersionMesh.visible = false;
play.visible = false;
textCreditMesh.visible = true;
textVersionMesh.visible = true;
} else if (scrollPercent > 0.90) {
play.visible = true;
}
};
document.addEventListener('scroll', scrollCallback);
clock = new THREE.Clock();
let scatterTime = 0;
const animate = () => {
const time = clock.getElapsedTime();
if (fadeFlag) {
if (fadePlane.material.opacity < 1) {
if (width>=height){
fadePlane.material.opacity += 0.005;
} else {
fadePlane.material.opacity += 0.01;
}
} else {
cancelAnimationFrame(animeIDs['landing']);
document.removeEventListener('pointermove', pointermoveCallback);
document.removeEventListener('click', clickCallback);
document.removeEventListener('scroll', scrollCallback);
strings();
return;
}
}
if (scrollY > 100) {
scatterTime += 0.05;
const positions = ringParticles.getAttribute('position').array;
for (let i = 0; i < ringParticleCount; i++) {
const angle = Math.random() * Math.PI * 2;
const radius = Math.random() * 100;
const displacementX = Math.cos(angle) * radius;
const displacementY = Math.sin(angle) * radius;
const displacementZ = Math.random() * 100 - 50;
const t = scatterTime * Math.random(); // Randomize the start time for each ringParticle
// Update the position of the ringParticle based on its original position and the random displacement
positions[i * 3] = ringParticlePositions[i * 3] + displacementX * t;
positions[i * 3 + 1] = ringParticlePositions[i * 3 + 1] + displacementY * t;
positions[i * 3 + 2] = displacementZ;
// Clamp the ringParticle position to its original position if it has moved too far away
const maxDistance = 100;
const distance = Math.sqrt(displacementX ** 2 + displacementY ** 2);
if (distance > maxDistance) {
positions[i * 3] = ringParticlePositions[i * 3];
positions[i * 3 + 1] = ringParticlePositions[i * 3 + 1];
positions[i * 3 + 2] = 0;
}
}
ringParticles.getAttribute('position').needsUpdate = true;
}
if (scrollY <= 100) {
scatterTime = 0;
const positions = ringParticles.getAttribute('position').array;
for (let i = 0; i < ringParticleCount; i++) {
const angle = Math.random() * Math.PI * 2;
const radius = width >= height ? 100 : 50;
const x = Math.cos(angle) * radius;
const y = Math.sin(angle) * radius;
positions[i * 3] = x;
positions[i * 3 + 1] = y;
positions[i * 3 + 2] = 0;
}
ringParticles.getAttribute('position').needsUpdate = true;
}
worldsSphereMaterial.uniforms.time.value = time;
playIcon.rotation.x += 0.01;
const y = Math.sin(time * 2) * 5;
circle.position.set(circle.position.x, y, circle.position.z);
renderer.render(scene, camera);
labelRenderer.render(scene, camera);
animeIDs['landing'] = requestAnimationFrame(animate);
};
animate();
});
};
const strings = () => {
scene = new THREE.Scene();
window.scrollTo(0, 0);
document.body.style.height = height + 'px';
document.body.style.overflow = 'hidden';
camera.position.set(1, 1, 1);
scene.add(camera);
const oStringGeo = new THREE.PlaneGeometry(0.1, 5, 64, 64);
const stringMaterial = new THREE.ShaderMaterial({
side: THREE.DoubleSide,
transparent: true,
uniforms: {
time: { value: 0 },
color: { value: null },
uFrequency: { value: null },
},
});
let oStringParticles = [];
const oStringParticleCount = 80;
for (let i = 0; i < oStringParticleCount; i++) {
const oStringMaterial = stringMaterial.clone();
oStringMaterial.vertexShader = vshaderString4;
oStringMaterial.fragmentShader = fshaderString4;
oStringMaterial.uniforms.color.value = new THREE.Vector3(0, 225, 0);
oStringMaterial.uniforms.uFrequency.value = 5.0 * Math.random() + 5;
let oString = new THREE.Mesh(oStringGeo, oStringMaterial);
oString.position.set(
Math.random() * 30 - 10,
Math.random() * 30 - 10,
Math.random() * 30 - 10
);
oString.rotation.set(
Math.random() * 3,
Math.random() * 6,
Math.random() * 9
);
scene.add(oString);
oStringParticles.push(oString);
}
let StringParticles = [];
const stringParticleCount = 400;
const stringGeo = new THREE.SphereGeometry(3, 32, 32, 0, 1, 1, 2);
const stringCount = stringGeo.attributes.position.count;
const sRandoms = new Float32Array(stringCount);
const stringShaderArray = [
[vshaderString, fshaderString],
[vshaderString2, fshaderString2],
[vshaderString3, fshaderString3],
];
for (let i = 0; i < stringCount; i++) {
sRandoms[i] = Math.random();
}
stringGeo.setAttribute("sRandom", new THREE.BufferAttribute(sRandoms, 1));
for (let i = 0; i < stringParticleCount; i++) {
const materialShaders =
stringShaderArray[Math.floor(Math.random() * stringShaderArray.length)];
const particleMat = stringMaterial.clone();
particleMat.vertexShader = materialShaders[0];
particleMat.fragmentShader = materialShaders[1];
let string = new THREE.Mesh(stringGeo, particleMat);
string.position.set(
Math.random() * 30 - 10,
Math.random() * 30 - 10,
Math.random() * 30 - 10
);
string.rotation.set(
Math.random() * 3,
Math.random() * 6,
Math.random() * 9
);
scene.add(string);
StringParticles.push(string);
}
clock = new THREE.Clock();
const stringText1 = "Starting at late 1960s, a theoretical framework called <span class='red'>string theory</span> was developed which proposes that the fundamental building blocks of the universe are not particles, but strings.";
const stringText2 = "Strings are theorized as tiny, one-dimensional physical entities that vibrate at different frequencies to give rise to<span class='red'> all the particles and forces in the universe</span>.";
const stringText3 = "The properties of the strings, such as their<span class='red'> tension and vibration modes</span>, determine the properties of the particles they create.";
const stringText4 = "One of the challenges of string theory is that it requires the existence of<span class='red'> additional dimensions</span> beyond the familiar three spatial dimensions and one time dimension. These extra dimensions are thought to be compactified, or curled up, into tiny, inaccessible spaces, which is why<span class='red'> we don't perceive them in our everyday lives</span>.";
const stringDiv = document.createElement('div');
stringDiv.className = 'label';
stringDiv.innerHTML = stringText1;
const stringLabel = new CSS2DObject(stringDiv);
stringLabel.position.set(0, 0, 0);
stringLabel.center.set(0, .5);
scene.add(stringLabel);
const animateString = () => {
animeIDs["strings"] = requestAnimationFrame(animateString);
const time = clock.getElapsedTime();
for (let i = 0; i < StringParticles.length; i++) {
const particleMesh = StringParticles[i];
const speed = 0.01;
particleMesh.rotation.y += speed * Math.random();
particleMesh.material.uniforms.time.value = time;
}
for (let i = 0; i < oStringParticles.length; i++) {
const particleMesh = oStringParticles[i];
const speed = 0.01;
particleMesh.rotation.y += speed * Math.random();
particleMesh.material.uniforms.time.value = time;
particleMesh.material.uniforms.uFrequency.value = Math.random() * 20.0;
}
if (time < 15) {
stringLabel.position.y -= 0.005;
camera.position.set(2, 9, 2);
camera.lookAt(0, 0, 0);
} else if (time >= 15 && time < 30) {
stringLabel.element.innerHTML = stringText2;
stringLabel.position.set(-0.01 * time, 4, 0);
stringLabel.position.y += 0.01;
stringLabel.center.set(0, 1);
camera.position.set(0, 2, 0);
camera.lookAt(0, 10, 0);
} else if (time >= 30 && time < 40) {
stringLabel.element.innerHTML = stringText3;
stringLabel.position.set(0, 3, 0);
stringLabel.center.set(1, 1);
camera.rotation.y += 0.0005;
stringLabel.position.x -= 0.05;
} else if (time >= 40 && time < 70) {
stringLabel.element.innerHTML = stringText4;
stringLabel.position.set(0, -20, 0);
stringLabel.center.set(0, .2);
camera.position.x += 0.002;
camera.position.y += 0.08;
camera.rotation.y += 0.05;
camera.lookAt(0, 0, 0);
}
else if (time >= 70) {
cancelAnimationFrame(animeIDs["strings"]);
scene.remove(stringLabel);
quarks();
return;
}
renderer.render(scene, camera);
labelRenderer.render(scene, camera);
};
animateString();
};
const quarks = () => {
scene = new THREE.Scene();
let uQuarks = [];
let dQuark, uQuark1Material, uQuark2Material, dQuarkMaterial;
const quarkMaterial = new THREE.ShaderMaterial({
vertexShader: vshaderQuark,
fragmentShader: fshaderQuark,
uniforms: {
uColor: { value: new THREE.Color(0x0000ff) },
},
});
const lineMaterial = new THREE.LineBasicMaterial({ color: 0xffffff });
const lineGeometry = new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute([0, 0, 0, 0, 0, 0], 3)
);
const dischargeLine = new THREE.Line(lineGeometry, lineMaterial);
scene.add(dischargeLine);
const uQuarkGeometry = new THREE.SphereGeometry(.5, 16, 16);
uQuark1Material = quarkMaterial.clone();
uQuark2Material = quarkMaterial.clone();
const uQuark1 = new THREE.Mesh(uQuarkGeometry, uQuark1Material);
uQuark1.position.set(5, 0, 0);
scene.add(uQuark1);
uQuarks.push(uQuark1);
const uQuark2 = new THREE.Mesh(uQuarkGeometry, uQuark2Material);
uQuark2.position.set(-5, 0, 0);
scene.add(uQuark2);
uQuarks.push(uQuark2);
const dQuarkGeometry = new THREE.SphereGeometry(.5, 16, 16);
dQuarkMaterial = quarkMaterial.clone();
dQuarkMaterial.uniforms.uColor.value = new THREE.Color(0x00ff00);
dQuark = new THREE.Mesh(dQuarkGeometry, dQuarkMaterial);
dQuark.position.set(0, 0, 3);
scene.add(dQuark);
const minDistance = 2;
const maxDistance = 5;
const quarkText1 = "Quarks are elementary particles that are the building blocks of protons and neutrons, which in turn make up the nuclei of atoms. Quarks are believed to be<span class='red'> truly fundamental particles</span>, meaning that they cannot be broken down into smaller constituents.";
const quarkText2 = "There are <span class='red'>six different types of quarks</span>, known as flavors, which are labeled up, down, charm, strange, top, and bottom. <span class='blue'>Up</span> and <span class='green'>down</span> quarks, which are the lightest and most common, make up the protons and neutrons in ordinary matter.";
const quarkText3 = "One of the most striking features of quarks is that they are <span class='red'>always found in combinations of two or three, never as isolated particles</span>. This property is known as confinement, and it is thought to arise from the strong nuclear force, which binds quarks together and prevents them from existing in isolation.";
const quarkText4 = "Quarks interact through the <span class='red'>strong nuclear force</span>, mediated by particles known as <span class='emph'>gluons</span>. The strong force is responsible for holding protons and neutrons together in atomic nuclei, and it is one of the four fundamental forces of nature, along with <span class='green'>gravity</span>, <span class='blue'>electromagnetism</span>, and <span class='red'>the weak force</span>.";
const quarkDiv = document.createElement('div');
quarkDiv.className = 'label';
quarkDiv.innerHTML = quarkText1;
const quarkLabel = new CSS2DObject(quarkDiv);
quarkLabel.position.set(0, 0, 2);
quarkLabel.center.set(0, 0);
scene.add(quarkLabel);
clock = new THREE.Clock();
camera.position.set(0, 0, 1.5);
const quarkLoop = () => {
animeIDs["quarks"] = requestAnimationFrame(quarkLoop);
const time = clock.getElapsedTime();
for (let i = 0; i < 2; i++) {
const uQuarkMesh = uQuarks[i];
const axis = new THREE.Vector3(
Math.random() - 0.5,
Math.random() - 0.5,
Math.random() - 0.5
).normalize();
const angle = Math.random() * Math.PI * 2;
uQuarkMesh.quaternion.multiply(
new THREE.Quaternion().setFromAxisAngle(axis, angle)
);
uQuarkMesh.position.x += (Math.random() - 0.5) * 0.1;
uQuarkMesh.position.y += (Math.random() - 0.5) * 0.1;
uQuarkMesh.position.z += (Math.random() - 0.5) * 0.1;
const distance = uQuarks[0].position.distanceTo(uQuarks[1].position);
if (distance < minDistance) {
const pushVector = uQuarkMesh.position
.clone()
.sub(uQuarks[1 - i].position)
.normalize()
.multiplyScalar(minDistance - distance);
uQuarkMesh.position.add(pushVector);
} else if (distance > maxDistance) {
const pushVector = uQuarkMesh.position
.clone()
.sub(uQuarks[1 - i].position)
.normalize()
.multiplyScalar(distance - maxDistance);
uQuarkMesh.position.sub(pushVector);
}
}
const axis = new THREE.Vector3(
Math.random() - 0.5,
Math.random() - 0.5,
Math.random() - 0.5
).normalize();
const angle = Math.random() * Math.PI * 2;
dQuark.quaternion.multiply(
new THREE.Quaternion().setFromAxisAngle(axis, angle)
);
dQuark.position.x += (Math.random() - 0.5) * 0.1;
dQuark.position.y += (Math.random() - 0.5) * 0.1;
dQuark.position.z += (Math.random() - 0.5) * 0.1;
let distance = dQuark.position.distanceTo(uQuarks[0].position);
if (distance < minDistance) {
const pushVector = dQuark.position
.clone()
.sub(uQuarks[0].position)
.normalize()
.multiplyScalar(minDistance - distance);
dQuark.position.add(pushVector);
} else if (distance > maxDistance) {
const pushVector = dQuark.position
.clone()
.sub(uQuarks[0].position)
.normalize()
.multiplyScalar(distance - maxDistance);
dQuark.position.sub(pushVector);
}
distance = dQuark.position.distanceTo(uQuarks[1].position);
if (distance < minDistance) {
const pushVector = dQuark.position
.clone()
.sub(uQuarks[1].position)
.normalize()
.multiplyScalar(minDistance - distance);
dQuark.position.add(pushVector);
} else if (distance > maxDistance) {
const pushVector = dQuark.position
.clone()
.sub(uQuarks[1].position)
.normalize()
.multiplyScalar(distance - maxDistance);
dQuark.position.sub(pushVector);
}
for (let i = 0; i < 2; i++) {
const uQuarkMesh = uQuarks[i];
if (Math.random() < 0.2) {
let target = i === 0 ? uQuarks[1] : uQuarks[0];
if (Math.random() < 0.5) {
target = dQuark;
}
const start = uQuarkMesh.position.clone();
dischargeLine.geometry.attributes.position.setXYZ(
0,
start.x,
start.y,
start.z
);
const end = target.position.clone();
dischargeLine.geometry.attributes.position.setXYZ(
1,
end.x,
end.y,
end.z
);
dischargeLine.geometry.attributes.position.needsUpdate = true;
const duration = Math.random() * 0.5;
const startTime = time;
const animateLine = (time) => {
const t = (time - startTime) / duration;
if (t < 1) {
dischargeLine.material.opacity = 1 - t;
} else {
dischargeLine.material.opacity = 0;
dischargeLine.geometry.attributes.position.setXYZ(0, 0, 0, 0);
dischargeLine.geometry.attributes.position.setXYZ(1, 0, 0, 0);
dischargeLine.geometry.attributes.position.needsUpdate = true;
scene.remove(dischargeLine);
return;
}
animeIDs["animateLine"] = requestAnimationFrame(animateLine);
};
scene.add(dischargeLine);
}
}
if (time < 15) {
quarkLabel.position.set(-0.75, 0, 1);
quarkLabel.position.y += 0.01;
quarkLabel.center.set(0, 0);
camera.position.x += 0.02;
camera.position.y += 0.01;
// camera.rotation.y -= 0.02;
camera.lookAt(0, 0, 1);
} else if (time >= 15 && time < 30) {
quarkLabel.element.innerHTML = quarkText2;
quarkLabel.position.set(0.01 * time, 0.01 * time, 0);
quarkLabel.center.set(0, 1);
camera.position.set(-5, 25, 0);
camera.lookAt(0, 0, 1);
} else if (time >= 30 && time < 38) {
quarkLabel.visible = false;
camera.position.set(uQuarks[0].position.x - 10, uQuarks[0].position.y + 5, uQuarks[0].position.z - 10);
camera.lookAt(dQuark.position)
} else if (time >= 38 && time < 45) {
camera.position.set(uQuarks[1].position.x + 10, uQuarks[1].position.y + 5, uQuarks[1].position.z - 10);
camera.lookAt(uQuarks[0].position)
} else if (time >= 45 && time < 60) {
quarkLabel.visible = true;
quarkLabel.element.innerHTML = quarkText3;
quarkLabel.position.set(0.01 * time, 0, 0);
quarkLabel.center.set(0, 1);
camera.position.set(0, 25, 0);
camera.lookAt(-1, 0, -1);
} else if (time >= 60 && time < 75) {
quarkLabel.element.innerHTML = quarkText4;
quarkLabel.position.set(0, 0, 0);
quarkLabel.center.set(0, 0);
camera.position.z += .1;
camera.lookAt(0, 0, 0);
} else if (time >= 75) {
scene.remove(quarkLabel);
cancelAnimationFrame(animeIDs["quarks"]);
cancelAnimationFrame(animeIDs["animateLine"]);
nucleus();
return;
}
renderer.render(scene, camera);
labelRenderer.render(scene, camera);
};
quarkLoop();
};
const nucleus = () => {
scene = new THREE.Scene();
let protonGeo = new THREE.SphereGeometry(0.125, 32, 32);
const protonCount = protonGeo.attributes.position.count;
const pRandoms = new Float32Array(protonCount);
for (let i = 0; i < protonCount; i++) {
pRandoms[i] = Math.random();
}
protonGeo.setAttribute("sRandom", new THREE.BufferAttribute(pRandoms, 1));
const protonMaterial = new THREE.ShaderMaterial({
vertexShader: vshaderProton,
fragmentShader: fshaderProton,
side: THREE.FrontSide,
transparent: true,
uniforms: {
randomness: { value: Math.random() },
utime: { value: 0 },
uTexture: { value: protonTexture },
},