forked from pkargupta/firemusic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
89 lines (73 loc) · 2.49 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
import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.127/build/three.module.js';
import {OrbitControls} from 'https://cdn.jsdelivr.net/npm/three@0.127/examples/jsm/controls/OrbitControls.js';
import FluidFireSystem from './FluidFireSystem.js';
class ParticleSystemDemo {
constructor() {
this._Initialize();
}
_Initialize() {
this._threejs = new THREE.WebGLRenderer({
antialias: true,
});
this._threejs.shadowMap.enabled = true;
this._threejs.shadowMap.type = THREE.PCFSoftShadowMap;
this._threejs.setPixelRatio(window.devicePixelRatio);
this._threejs.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(this._threejs.domElement);
window.addEventListener('resize', () => {
this._OnWindowResize();
}, false);
const fov = 60;
const aspect = 1920 / 1080;
const near = 1.0;
const far = 1000.0;
this._camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
this._camera.position.set(15, 0, 0);
this._scene = new THREE.Scene();
let light = new THREE.DirectionalLight(0xFFFFFF, 1.0);
light.position.set(20, 100, 10);
light.target.position.set(0, 0, 0);
light.castShadow = true;
light.shadow.bias = -0.001;
light.shadow.mapSize.width = 2048;
light.shadow.mapSize.height = 2048;
light.shadow.camera.near = 0.1;
light.shadow.camera.far = 500.0;
light.shadow.camera.near = 0.5;
light.shadow.camera.far = 500.0;
light.shadow.camera.left = 100;
light.shadow.camera.right = -100;
light.shadow.camera.top = 100;
light.shadow.camera.bottom = -100;
this._scene.add(light);
light = new THREE.AmbientLight(0x101010);
this._scene.add(light);
const controls = new OrbitControls(
this._camera, this._threejs.domElement);
controls.target.set(0, 0, 0);
controls.update();
this._realistic_fire = new FluidFireSystem({
scene: this._scene,
camera: this._camera,
renderer: this._threejs,
_z_spawn: 0,
});
this._simulate();
}
_OnWindowResize() {
this._camera.aspect = window.innerWidth / window.innerHeight;
this._camera.updateProjectionMatrix();
this._threejs.setSize(window.innerWidth, window.innerHeight);
}
_simulate() {
requestAnimationFrame((t) => {
this._simulate();
this._realistic_fire.update()
this._threejs.render(this._scene, this._camera);
});
}
}
let _APP = null;
window.addEventListener('DOMContentLoaded', () => {
_APP = new ParticleSystemDemo();
});