-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathscript.js
638 lines (546 loc) · 23.7 KB
/
script.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
/**
* Project Brief:
* This is a direct port of the same code I wrote for Unity (which was much cleaner and more organized).
* This is mostly for fun and to mess with the limits of browser rendering (though we aren't getting anywhere NEAR the limits!)
* It's a pretty cool resume filler project I think.
*
* Basically, we render an infinte (chunk-based, like many procedural games) museum and fill it with images from the
* art gallery, which has a free API for the general public to use. Very cool!
*
* Originally, I was going to implement the Harvard Art Gallery API, or another. But after thinking on it, I realized that
* this project could have more value if it instead got art that people like us create. So instead, it swipes art from Reddit
* (SFW content only) created by anyone in the world, with zero bias on vote count. Isn't that incredible?
*/
const clearOverlay = function() {
if (document.getElementById("click-warning-overlay")) {
document.body.removeChild(document.getElementById("click-warning-overlay"));
}
}
import * as THREE from "https://cdn.skypack.dev/pin/three@v0.143.0-Cpkbmg37IsbIniRRPFSZ/mode=imports,min/optimized/three.js"
import { FontLoader } from "/FontLoader.js"
import { TextGeometry } from "/TextGeometry.js"
import TouchControls from "/TouchControls/TouchControls-master/js/TouchControls.js"
let touchControls;
// find out if a device is mobile (no keyboard or mouse)
function isMobile() {
if (navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPad/i) ||
navigator.userAgent.match(/iPod/i) ||
navigator.userAgent.match(/BlackBerry/i) ||
navigator.userAgent.match(/Windows Phone/i)) {
clearOverlay();
console.log("Detected Mobile Device, rerouting to original version...");
window.location.href = "https://gallery.nowaythis.works/mobile.html";
// on fail, attempt mobile controls with new setup
return true;
} else {
// find elements tagged movement-pad and hide them
return false;
}
}
const mobile = isMobile();
/**
* Engine and Player Setup
*/
const groundHeight = 0;
const ceilingHeight = 7;
const playerHeight = 2;
const playerSpeed = 6;
const playerSpeedSprintMod = 0.5;
const artwallSpawnDistance = 30;
/**
* Basic THREE.JS Scene Setup
* This will set up our world and camera tools
*/
// Internal
const scene = new THREE.Scene();
// scene.fog = new THREE.FogExp2(0xe5e8ea, 0.05);
scene.background = new THREE.Color(0xe5e8ea);
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setClearColor(0xe5e8ea, 1);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Textures and Materials
// carpet texture
const carpetTexture = new THREE.TextureLoader().load('img/carpet.png', function (texture) {
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(5, 5);
});
const ceilingTexture = new THREE.TextureLoader().load('img/ceiling.png', function (texture) {
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(3.5, 3.5);
});
const wallTexture = new THREE.TextureLoader().load('img/ceiling.png', function (texture) {
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(5, 2.5);
});
// Camera Starting Position
camera.position.set(0, playerHeight, 0);
// touch screen controls
function addControls() {
// Controls
let options = {
delta: 0.75, // coefficient of movement
moveSpeed: 0.15, // speed of movement
rotationSpeed: 0.002, // coefficient of rotation
maxPitch: 55, // max camera pitch angle
hitTest: true, // stop on hitting objects
hitTestDistance: 40 // distance to test for hit
}
console.log("EL: " + renderer.domElement);
touchControls = new TouchControls(document.body, camera, options)
touchControls.setPosition(0, 25, 400)
touchControls.addToScene(scene)
}
if (mobile) addControls();
// child cube for the camera, will be directly in front of it at all times
const followCube = new THREE.Mesh(new THREE.BoxGeometry(0.1, 0.1, 0.1), new THREE.MeshBasicMaterial({ color: 0xff00ff, transparent: true, opacity: 0 }));
followCube.position.set(0, 0, -artwallSpawnDistance);
camera.add(followCube);
scene.add(camera);
/**
* Fonts
*/
const fontLoader = new FontLoader();
const backgroundCube = new THREE.Mesh(new THREE.BoxGeometry(14, 12, 1), new THREE.MeshBasicMaterial({ color: 0x000000 }));
backgroundCube.position.set(0, 0.5, -5.5);
scene.add(backgroundCube);
if (mobile) document.querySelector("#removal").style.textAlign = "center";
var loadingText;
var font;
fontLoader.load('fonts/Montserrat SemiBold_Regular.json', function (montserrat) {
font = montserrat;
loadingText = new TextGeometry('Loading...', {
font: font,
size: 0.45,
height: 1,
curveSegments: 2
});
const headerGeometry = new TextGeometry('The Infinite Gallery', {
font: font,
size: 80,
height: 5,
curveSegments: 2
});
const header = new THREE.Mesh(headerGeometry, new THREE.MeshBasicMaterial({ color: 0xffffff }));
scene.add(header);
header.position.set(-6, 4, -5);
header.scale.set(header.scale.x / 100, header.scale.y / 100, header.scale.z / 500);
if (mobile) {
header.scale.set(header.scale.x / 3, header.scale.y / 3, header.scale.z);
header.position.set(-1.85, 4, -5);
}
var visitorText = 'This is an infinite procedurally-generated 3D art gallery. Every piece of art is pulled from Reddit\'s r/Art.\nMeaning, everything in this gallery was created by a person like you or me! Plus, there is no bias on the\namount of votes a post got, so absolutely anyone\'s art could appear here, regardless of fame.\nCurrently, there are over 2.1 MILLION pieces of art in this room. Just start walking and the exhibit\nwill appear around you.\n\nThanks for visiting!';
if (mobile) {
visitorText = 'This is an infinite 3D art gallery. Every piece of art is pulled from\nReddit\'s r/Art. Meaning, everything in this gallery was created by a\nperson like you or me! Plus, there is no bias on the amount of votes\na post got, so absolutely anyone\'s art could appear here, regardless of fame.\nCurrently, there are over 2.1 MILLION pieces of art in this room.\nJust start walking and the exhibit will appear around you.\n\nThanks for visiting!';
visitorText += '\n[Mobile Beta Version] Some features are only accessible on\na device with a keyboard and mouse.';
}
const subheaderGeometry = new TextGeometry(visitorText, {
font: font,
size: 15,
height: 5,
curveSegments: 2
});
const subheader = new THREE.Mesh(subheaderGeometry, new THREE.MeshBasicMaterial({ color: 0xffffff }));
scene.add(subheader);
subheader.position.set(-6, 3.5, -5);
subheader.scale.set(subheader.scale.x / 100, subheader.scale.y / 100, subheader.scale.z / 500);
if (mobile) {
subheader.scale.set(subheader.scale.x / 2, subheader.scale.y / 2, subheader.scale.z);
subheader.position.set(-1.85, 3.7, -5);
}
var tutorialText = 'Use Arrow Keys or [WASD] to walk. Use your mouse to look around.\nExplore and have fun!';
if (mobile) {
tutorialText = 'Drag your finger forwards on the circle to progress.\n(Access this page on a laptop or desktop PC for the full experience!)'
}
const tutorialGeometry = new TextGeometry(tutorialText, {
font: font,
size: 20,
height: 5,
curveSegments: 2
});
const tutorial = new THREE.Mesh(tutorialGeometry, new THREE.MeshBasicMaterial({ color: 0x711ca6 }));
scene.add(tutorial);
tutorial.position.set(-6, 1.1, -5);
tutorial.scale.set(tutorial.scale.x / 100, tutorial.scale.y / 100, tutorial.scale.z / 500);
if (mobile) {
tutorial.scale.set(tutorial.scale.x / 3, tutorial.scale.y / 3, tutorial.scale.z);
tutorial.position.set(-1.85, 2.1, -5);
}
});
/**
* First Person Controls
* Mouse Look and Keyboard (WASD and Arrow Keys) Movement
*/
// MOUSE LOOK
var pointerIsLocked = false;
const canvas = document.body;
canvas.requestPointerLock = canvas.requestPointerLock || canvas.msRequestPointerLock || canvas.mozRequestPointerLock || canvas.webkitRequestPointerLock;
canvas.onclick = function () {
if (mobile) return;
canvas.requestPointerLock();
}
var mouseNegative = 1;
const euler = new THREE.Euler(0, 0, 0, 'YXZ');
canvas.onmousemove = function (event) {
if (pointerIsLocked) {
const mouseX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
const mouseY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
euler.y -= mouseX * 0.002;
euler.x -= mouseY * 0.002 * mouseNegative;
euler.x = Math.max(-Math.PI / 2, Math.min(Math.PI / 2, euler.x));
camera.quaternion.setFromEuler(euler);
}
}
if ("onpointerlockchange" in document) {
document.addEventListener('pointerlockchange', lockChangeAlert, false);
} else if ("onmozpointerlockchange" in document) {
document.addEventListener('mozpointerlockchange', lockChangeAlert, false);
} else if ("onwebkitpointerlockchange" in document) {
document.addEventListener('webkitpointerlockchange', lockChangeAlert, false);
}
function lockChangeAlert() {
if (mobile) return;
if (document.pointerLockElement === canvas || document.mozPointerLockElement === canvas || document.webkitPointerLockElement === canvas) {
pointerIsLocked = true;
} else {
pointerIsLocked = false;
}
}
// WASD MOVEMENT
const keys = {};
document.addEventListener('keydown', function (event) {
keys[event.code] = true;
}), document.addEventListener('keyup', function (event) {
keys[event.code] = false;
});
/**
* USER INTERFACE AND EVENT LISTENERS
* Control the game UI's state and respond to user input
*/
// crosshair color
/**
* RENDERING AND OBJECT UPDATING
* Render the scene's elements and update the states of objects
*/
const chunkPositions = []; // separate list for faster sorting
const chunkPieces = [];
const chunkSize = 20;
const renderDistance = 8;
// check (cannot use includes due to exess data in each Vector2 object)
function hasChunk(pos) {
for (let x = 0; x < chunkPositions.length; x++) {
if (chunkPositions[x].x == pos.x && chunkPositions[x].y == pos.y) {
return true;
}
}
return false;
}
// Round to nearest chunksize
function RoundToChunkSize(num) {
return Math.round(num / chunkSize) * chunkSize;
}
var readyToGenerate = true;
function startGenerateCountdown() {
readyToGenerate = false;
setTimeout(function () {
readyToGenerate = true;
}, 0.5 * 1000);
}
// lerp the transparency 0 to 1
const artboardMaterials = [];
// format is Y X Z
var isSprinting = false;
const moveVector = new THREE.Vector3();
function update(delta) {
// COVER-UPS
scene.attach(followCube);
followCube.position.y = 0;
camera.attach(followCube);
// WORLD GENERATION
for (let x = -renderDistance / 2; x < renderDistance / 2; x++) {
for (let y = -renderDistance / 2; y < renderDistance / 2; y++) {
const playerRelativeLocation = new THREE.Vector2(RoundToChunkSize(camera.position.x), RoundToChunkSize(camera.position.z));
let newLocation = new THREE.Vector2(x * chunkSize, y * chunkSize);
newLocation = newLocation.add(playerRelativeLocation);
if (!hasChunk(newLocation)) {
if (newLocation.distanceTo(new THREE.Vector2(camera.position.x, camera.position.z)) < (renderDistance * chunkSize / 2)) {
generateChunk(newLocation);
}
}
}
}
// Lerp Artboard Materials
for (let i = 0; i < artboardMaterials.length; i++) {
if (artboardMaterials[i].opacity < 1) {
artboardMaterials[i].opacity += 0.5 * delta;
}
}
// cleanup
for (let i = 0; i < chunkPieces.length; i++) {
if (chunkPieces[i].position.distanceTo(camera.position) > (renderDistance * (chunkSize / 2))) {
scene.remove(chunkPieces[i]);
chunkPieces[i].geometry.dispose();
chunkPieces[i].material.dispose();
chunkPositions.splice(chunkPositions.indexOf(chunkPieces[i].position), 1);
chunkPieces.splice(chunkPieces.indexOf(chunkPieces[i]), 1);
}
}
// CONTROLS
if (mobile) touchControls.update();
if (mobile == false) {
var movementPad = document.querySelector(".movement-pad");
// remove the element
if (movementPad != undefined) movementPad.parentNode.removeChild(movementPad);
}
const moveSpeed = playerSpeed * delta * (1 + Number(isSprinting) * playerSpeedSprintMod);
if (keys['KeyW'] || keys['ArrowUp'] || (mobile && touchControls.moveForward)) {
if (mobile && touchControls.moveBackward) {
camera.position.z -= moveSpeed;
} else {
// forward movement
moveVector.setFromMatrixColumn(camera.matrix, 0);
moveVector.crossVectors(camera.up, moveVector);
moveVector.multiplyScalar(moveSpeed);
camera.position.addScaledVector(moveVector, 1);
}
}
if (keys['KeyS'] || keys['ArrowDown'] || (mobile && touchControls.moveBackward)) {
if (mobile && touchControls.moveBackward) {
moveVector.setFromMatrixColumn(camera.matrix, 0);
moveVector.crossVectors(camera.up, moveVector);
moveVector.multiplyScalar(moveSpeed);
camera.position.addScaledVector(moveVector, -1);
}
else {
// backward movement
moveVector.setFromMatrixColumn(camera.matrix, 0);
moveVector.crossVectors(camera.up, moveVector);
moveVector.multiplyScalar(moveSpeed);
camera.position.addScaledVector(moveVector, -1);
}
}
if (keys['KeyA'] || keys['ArrowLeft'] || (mobile && touchControls.moveLeft)) {
if (mobile && touchControls.moveLeft) {
camera.position.x += moveSpeed;
}
else {
// left movement
moveVector.setFromMatrixColumn(camera.matrix, 0);
moveVector.multiplyScalar(moveSpeed);
camera.position.addScaledVector(moveVector, -1);
}
}
if (keys['KeyD'] || keys['ArrowRight'] || (mobile && touchControls.moveRight)) {
if (mobile && touchControls.moveRight) {
camera.position.x -= moveSpeed;
}
else {
// right movement
moveVector.setFromMatrixColumn(camera.matrix, 0);
moveVector.multiplyScalar(moveSpeed);
camera.position.addScaledVector(moveVector, 1);
}
}
isSprinting = keys['ShiftLeft'] || keys['ShiftRight'] || false;
// update coords display
document.querySelector("#coords").innerHTML = camera.position.x.toFixed(0) + ", " + camera.position.y.toFixed(0) + ", " + camera.position.z.toFixed(0);
}
// to prevent dupes
const artImages = [];
function generateChunk(pos) {
// add to global chunks list
chunkPositions.push(pos);
// generate rand seeded on chunk position
const posString = pos.x + "" + pos.y + "" + pos.z;
const rand = Math.floor(new Math.seedrandom(posString).quick() * 100);
// chunk mesh
const chunk = new THREE.Mesh(
new THREE.PlaneGeometry(chunkSize, chunkSize, 1, 1),
new THREE.MeshBasicMaterial({
color: 0xffffff,
map: carpetTexture
})
);
chunk.rotation.x = -Math.PI / 2;
chunk.position.set(pos.x, groundHeight, pos.y);
scene.add(chunk);
chunkPieces.push(chunk);
// chunk ceiling
const ceiling = new THREE.Mesh(
new THREE.PlaneGeometry(chunkSize, chunkSize, 1, 1),
new THREE.MeshBasicMaterial({
color: 0xffffff,
map: ceilingTexture
})
);
ceiling.rotation.x = Math.PI / 2;
ceiling.position.set(pos.x, ceilingHeight, pos.y);
scene.add(ceiling);
chunkPieces.push(ceiling);
// min distance for walls is 15 away from spawn
if (pos.distanceTo(new THREE.Vector2(0, 0)) > 15) {
// check for dupes
for (let i = 0; i < chunkPieces.length; i++) {
if (chunkPieces[i].name == "wall") {
if (chunkPieces[i].position.equals(new THREE.Vector3(pos.x, 3.5, pos.y))) {
return;
}
}
}
const wallBaseMesh = new THREE.Mesh(new THREE.BoxGeometry(chunkSize, chunkSize, 0.2), new THREE.MeshBasicMaterial({ color: 0xe8e6e6 }));
wallBaseMesh.position.set(pos.x, 3.5, pos.y);
wallBaseMesh.name = "wall";
const wallArtMesh = new THREE.Mesh(new THREE.BoxGeometry(chunkSize / 4, chunkSize / 4, 0.4), new THREE.MeshBasicMaterial({ color: 0x000000, transparent: true, opacity: 0 }));
wallArtMesh.position.set(pos.x + 0.01, 3.5, pos.y + 0.01);
wallArtMesh.name = "art";
let canGenerate = true;
if (rand < 50) {
wallBaseMesh.rotation.y = Math.PI / 2;
wallArtMesh.rotation.y = Math.PI / 2;
}
scene.add(wallArtMesh);
scene.add(wallBaseMesh);
chunkPieces.push(wallBaseMesh);
chunkPieces.push(wallArtMesh);
for (let i = 0; i < chunkPieces.length; i++) {
if (chunkPieces[i].name == "art" || chunkPieces[i].name == "plaque") {
if (chunkPieces[i].position.equals(new THREE.Vector3(pos.x, 3.5, pos.y))) {
canGenerate = false;
}
}
}
// 10% wont have nothin, excusing the generator cooldown. this consistently adds nice spacing in between artworks.
if (rand < 45) {
if (!readyToGenerate) return;
// first make a request to random-image-identify
console.log("Making Request");
const xhr = new XMLHttpRequest();
xhr.open("GET", "https://blog.nowaythis.works/random-image-identify");
xhr.send();
xhr.onload = function () {
if (xhr.status == 200) {
startGenerateCountdown();
const loadingTextMesh = new THREE.Mesh(
loadingText,
new THREE.MeshBasicMaterial({
color: 0x000000
})
);
scene.add(loadingTextMesh);
loadingTextMesh.scale.z /= 50;
loadingTextMesh.position.set(pos.x+0.1, 1, pos.y+0.1);
loadingTextMesh.rotation.y = Math.PI/2;
const response = xhr.responseText.split('|||||');
let metadata = response[0];
// add a '\n' to metadata every 48 characters
let metadataFormatted = "";
for (let i = 0; i < metadata.length; i++) {
if (i % 48 == 0) {
metadataFormatted += "\n";
}
metadataFormatted += metadata[i];
}
metadata = metadataFormatted;
const urlToRequest = response[1];
console.log("Got Response");
const loader = new THREE.TextureLoader();
loader.setCrossOrigin("anonymous");
loader.load(
"https://blog.nowaythis.works/get-image-direct?url=" + urlToRequest,
function (art) {
// chance for chunk to spawn ART!!
for (let x = 0; x < artImages.length; x++) {
if (artImages[x] == art) {
artImages.splice(artImages.indexOf(artImages[i].position), 1);
canGenerate = false;
console.log("Failed. Dupe Found.");
scene.remove(wallArtMesh);
}
}
if (canGenerate) {
artImages.push(art);
wallArtMesh.geometry = new THREE.BoxGeometry(art.image.width / 600, art.image.height / 600, 0.01);
wallArtMesh.material = new THREE.MeshBasicMaterial({
map: art,
transparent: true,
opacity: 0
});
artboardMaterials.push(wallArtMesh.material);
// create a plaque with the metadata (which includes the author + title)
const plaqueMesh = new THREE.Mesh(
new THREE.BoxGeometry(4.5, 1.25, 0.25),
new THREE.MeshBasicMaterial({
color: 0xb59e1b
})
);
plaqueMesh.rotation.y = Math.PI / 2;
plaqueMesh.position.set(pos.x+0.25, 1, pos.y);
plaqueMesh.name = "plaque";
wallArtMesh.position.x += 0.25;
scene.add(plaqueMesh);
// plaque text
const plaqueTextMesh = new THREE.Mesh(
new TextGeometry(metadata, {
font: font,
size: 0.1,
height: 0.13
}),
new THREE.MeshBasicMaterial({
color: 0x000000
})
);
plaqueTextMesh.position.x -= 2;
plaqueTextMesh.position.y += 0.3;
plaqueMesh.add(plaqueTextMesh);
}
scene.remove(loadingTextMesh);
}
);
}
}
}
return true;
}
}
// generateChunk(new THREE.Vector2(0, 0));
const time = new THREE.Clock();
function render() {
requestAnimationFrame(render);
const delta = time.getDelta();
update(delta);
renderer.render(scene, camera);
}
render();
// window rescaling fix
window.addEventListener('resize', function () {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
// on press of V key
document.addEventListener('keydown', function (event) {
if (event.code === 'KeyV') {
mouseNegative = -1 * mouseNegative;
}
});
// on press of E key, move the camera UP 1 unit. on press of Q key, move the camera DOWN 1 unit.
document.addEventListener('keydown', function (event) {
if (event.code === 'KeyE') {
camera.position.y += 1;
}
if (event.code === 'KeyQ') {
camera.position.y -= 1;
}
});
// on body click, delete element "click-warning-overlay" if it exists
document.body.addEventListener('click', function (event) {
clearOverlay();
});