-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
68 lines (58 loc) · 1.75 KB
/
index.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
import * as THREE from "three";
import getLayer from "./getLayer.js";
import { OrbitControls } from 'jsm/controls/OrbitControls.js';
import { getParticleSystem } from "./getParticleSystem.js";
const w = window.innerWidth;
const h = window.innerHeight;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, w / h, 0.1, 1000);
camera.position.z = 5;
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(w, h);
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.outputColorSpace = THREE.SRGBColorSpace;
document.body.appendChild(renderer.domElement);
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.03;
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshStandardMaterial({
color: 0xffff00,
});
const cube = new THREE.Mesh(geometry, material);
cube.position.y = -1;
scene.add(cube);
const fireEffect = getParticleSystem({
camera,
emitter: cube,
parent: scene,
rate: 50.0,
texture: 'img/fire.png',
});
const hemiLight = new THREE.HemisphereLight(0xffffff, 0x444444);
scene.add(hemiLight);
// Sprites BG
const gradientBackground = getLayer({
hue: 0.6,
numSprites: 8,
opacity: 0.2,
radius: 10,
size: 24,
z: -10.5,
});
scene.add(gradientBackground);
function animate() {
requestAnimationFrame(animate);
cube.rotation.x += 0.01;
cube.rotation.y += 0.02;
fireEffect.update(0.016);
renderer.render(scene, camera);
controls.update();
}
animate();
function handleWindowResize () {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener('resize', handleWindowResize, false);