-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.mjs
68 lines (52 loc) · 1.7 KB
/
main.mjs
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 Stats from 'three/addons/libs/stats.module.js';
import VideoManager from './video_manager.mjs';
import DataOverlay from './data_overlay.mjs';
let canvas;
let renderer, scene, camera;
let dataOverlay;
let stats;
let vidMgr;
function init() {
THREE.Cache.enabled = true;
canvas = document.querySelector('#c');
renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
renderer.autoClear = false;
vidMgr = new VideoManager();
dataOverlay = new DataOverlay(vidMgr, renderer);
window.addEventListener("click", onclick, true);
const fov = 75;
const aspect = canvas.innerWidth / canvas.innerHeight;
const near = 0.1;
const far = 100;
camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
camera.position.z = 5;
scene = new THREE.Scene();
vidMgr.addTextureUser(scene, 'background');
stats = new Stats();
document.body.appendChild(stats.dom);
}
function resizeRendererToDisplaySize(renderer) {
const canvas = renderer.domElement;
const width = canvas.clientWidth;
const height = canvas.clientHeight;
const needResize = canvas.width !== width || canvas.height !== height;
if (needResize) {
renderer.setSize(width, height, false);
}
return needResize;
}
function render(time) {
if (resizeRendererToDisplaySize(renderer)) {
const canvas = renderer.domElement;
camera.aspect = canvas.clientWidth / canvas.clientHeight;
camera.updateProjectionMatrix();
}
stats.update();
vidMgr.doPreprocess(renderer);
renderer.clear();
renderer.render(scene, camera);
dataOverlay.render(renderer);
}
init();
renderer.setAnimationLoop(render);