-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
142 lines (110 loc) · 3.63 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>agar.client</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
color: #000;
font-family: Monospace;
font-size: 13px;
text-align: center;
font-weight: bold;
background-color: #fff;
margin: 0px;
overflow: hidden;
}
</style>
</head>
<body>
<script src="lib/three.min.js"></script>
<script src="lib/MapControls.js"></script>
<script src="lib/WebGL.js"></script>
<script src="lib/dat.gui.min.js"></script>
<script src="lib/stats.min.js"></script>
<script src="lib/threex.rendererstats.js"></script>
<script src="lib/KeyboardState.js"></script>
<script src="game.js"></script>
<script src="scene.js"></script>
<script>
if (WEBGL.isWebGLAvailable() === false) {
document.body.appendChild(WEBGL.getWebGLErrorMessage());
}
let region1, region2;
let camera, controls, scene, renderer, stats, rendererStats, clock, keyboard;
initScene()
initGame()
animate()
function initScene() {
scene = new THREE.Scene();
scene.background = new THREE.Color(0xcccccc);
//scene.fog = new THREE.FogExp2( 0xcccccc, 0.001 );
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
window.addEventListener('resize', onWindowResize, false);
camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.set(1600, 600, -1600 / 2);
// Time
clock = new THREE.Clock()
// controls
keyboard = new KeyboardState();
controls = new THREE.MapControls(camera, renderer.domElement);
controls.enableDamping = true; // an animation loop is required when either damping or auto-rotation are enabled
controls.dampingFactor = 0.25;
controls.screenSpacePanning = false;
controls.minDistance = 100;
controls.maxDistance = 10000;
controls.maxPolarAngle = Math.PI / 2;
// Monitoring
stats = new Stats();
stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom
document.body.appendChild(stats.dom);
rendererStats = new THREEx.RendererStats()
rendererStats.domElement.style.position = 'absolute'
rendererStats.domElement.style.left = '0px'
rendererStats.domElement.style.bottom = '0px'
document.body.appendChild(rendererStats.domElement)
// Helpers
let axesHelper = new THREE.AxesHelper(100);
scene.add(axesHelper);
// Light
setUpLight(scene)
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function initGame() {
region1 = new Region(1, 0, 0, 1600, "ws://127.0.0.1:8000/ws", scene)
region2 = new Region(2, 1600, 0, 1600, "ws://127.0.0.1:8001/ws", scene)
scene.add(region1.grid())
scene.add(region2.grid())
}
function animate() {
stats.begin();
const delta = clock.getDelta();
requestAnimationFrame(animate);
keyboard.update()
if (keyboard.up("R")) {
//TODO: Improve the lookAt
camera.position.set(2700, 1075, -900);
camera.lookAt(0, 0, -1600 / 2)
}
controls.update(); // only required if controls.enableDamping = true, or if controls.autoRotate = true
renderer.render(scene, camera);
// Rotate the energies
region1.energies.forEach(e => {
let mesh = e.getMesh()
mesh.rotation.x += delta * 0.9
mesh.rotation.y += delta * 0.9
})
rendererStats.update(renderer);
stats.end();
}
</script>
</body>
</html>