-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.js
137 lines (111 loc) · 3.33 KB
/
main.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
import * as THREE from "https://cdn.skypack.dev/three@0.152.2";
var scene,
sceneLight,
portalLight,
cam,
renderer,
portalLightDistance = 900,
portalParticles = [];
const canvas = document.getElementById("main-container");
function getWidth() {
return parseInt(window.getComputedStyle(canvas).width);
}
function getHeight() {
if (getWidth() < 770) {
return parseInt(window.getComputedStyle(canvas).height) - 20;
} else {
return parseInt(window.getComputedStyle(canvas).height);
}
}
function getPixelFactor() {
if (getWidth() < 700) {
return 1.7;
} else {
return 0.78;
}
}
function initScene() {
scene = new THREE.Scene();
sceneLight = new THREE.DirectionalLight(0x241b50, 0.5);
sceneLight.position.set(0, 0, 1);
scene.add(sceneLight);
//#30D5C8
portalLight = new THREE.PointLight(0x61479c, 35, portalLightDistance, 4);
portalLight.position.set(0, 0, 250);
scene.add(portalLight);
cam = new THREE.PerspectiveCamera(160, getWidth() / getHeight(), 1, 1000);
cam.position.z = 112;
cam.position.x = -35;
cam.aspect = getWidth() / getHeight();
scene.add(cam);
renderer = new THREE.WebGLRenderer("high-performance");
renderer.setClearColor(0x0e0b1e, 1);
renderer.setSize(getWidth(), getHeight());
renderer.setPixelRatio(window.devicePixelRatio - getPixelFactor());
document.body.appendChild(renderer.domElement);
particleSetup();
}
function particleSetup() {
let loader = new THREE.TextureLoader();
loader.load("./assets/smoke5.png", function (texture) {
let portalGeo = new THREE.PlaneGeometry(350, 350);
let portalMaterial = new THREE.MeshStandardMaterial({
map: texture,
transparent: true,
});
let smokeGeo = new THREE.PlaneGeometry(1000, 1000);
let smokeMaterial = new THREE.MeshStandardMaterial({
map: texture,
transparent: true,
});
for (let p = 618; p > 250; p--) {
let particle = new THREE.Mesh(portalGeo, portalMaterial);
particle.position.set(
p * Math.cos((4 * p * Math.PI) / 180),
p * Math.sin((4 * p * Math.PI) / 180),
0.1 * p
);
particle.rotation.z = Math.random() * 360;
portalParticles.push(particle);
scene.add(particle);
}
for (let p = 0; p < 10; p++) {
let particle = new THREE.Mesh(smokeGeo, smokeMaterial);
particle.position.set(
Math.random() * 1000 - 500,
Math.random() * 400 - 200,
25
);
particle.rotation.z = Math.random() * 360;
particle.material.opacity = 0.6;
portalParticles.push(particle);
scene.add(particle);
}
window.addEventListener("resize", onWindowResize, false);
window.addEventListener("orientationchange", onWindowResize, false);
update();
});
}
function onWindowResize() {
cam.aspect = getWidth() / getHeight();
cam.updateProjectionMatrix();
renderer.setPixelRatio(window.devicePixelRatio - getPixelFactor());
renderer.setSize(getWidth(), getHeight());
}
let clock = new THREE.Clock();
let delta = 0;
// 30 fps
let interval1 = 1 / 30;
function update() {
requestAnimationFrame(update);
delta += clock.getDelta();
if (delta > interval1) {
// The draw or time dependent code are here
portalParticles.forEach((p) => {
p.rotation.z -= 0.003 * 2;
});
renderer.render(scene, cam);
delta = delta % interval1;
}
}
initScene();