-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
522 lines (414 loc) · 13.8 KB
/
index.html
File metadata and controls
522 lines (414 loc) · 13.8 KB
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
<!DOCTYPE html>
<html>
<link href="https://fonts.googleapis.com/css?family=Titillium+Web&display=swap" rel="stylesheet">
<style>
/* remove controls for logo loading screen */
video::-webkit-media-controls,
video::-moz-media-controls,
video::-o-media-controls,
video::-ms-media-controls {
display: none !important;
}
button:focus {outline:0;}
.loading-screen{
display: flex;
align-items: center;
justify-content: center;
background-color: black;
position:relative;
background-position: center;
background-size: 600px 300px;
background-repeat: no-repeat;
width: 100vw;
height: 100vh;
text-align: center;
}
.controls {
position: fixed;
display: none;
bottom: 100px;
left: 0;
right: 0;
z-index: 100;
}
.controls-on {
display: flex;
justify-content: center;
}
.control-button:focus { animation: blinker 1s linear infinite; }
.control-button {
display: inline-block;
border-radius: 50%;
height: 20px;
width: 20px;
color: white;
opacity: .5;
margin: 10px;
}
.play-button {
position: absolute;
margin: auto;
bottom: 200px;
/* margin-top: 61%;
margin-bottom: 39%; */
border:none;
background-color:black;
width: auto;
}
p {
color: white;
font-family: 'Titillium Web', sans-serif;
font-size: 2em;
animation: blinker 3s linear infinite;
}
@keyframes blinker{
50% {
opacity: 0;
}
}
/* text */
.scene-title {
padding: 15px;
display: block;
font-family: 'Titillium Web', sans-serif;
color: #B20000;
font-size: 1em;
}
#spinning-video {
width: 425px;
}
body {
margin: 0;
background-color: black;
}
#container {
/* height: 100vh; */
align-content: center;
}
#vis-canvas {
display: none;
align-self: center;
height: 80vh !important;
}
</style>
<head>
<meta charset=utf-8>
<title>CMMND EP X Creative Labs</title>
<link rel='shortcut icon' href='./favicon.ico' type='image/x-icon' />
<meta name="description" content="Music Visualizer for CMMND EP">
<meta name="keywords" content="HTML,CSS,JavaScript,Threejs,music,visualizer,hip-hop,rap">
<meta name="author" content="Amanda Han, Angela Zhang, Katie Cai, Rohan Kumar, Tobey Lee">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="loading-screen">
<audio id="loading-audio" autoplay loop>
<source src="./assets/audio/loading_audio.mp3">
</audio>
<video id="spinning-video" autoplay loop>
<source src="./assets/CMMND spinning.mov">
</video>
</div>
<div class="text-container scene-title"></div>
<section class="controls">
<!-- each button corresponds to a scene, switch between scenes (only initscene once) -->
<button class="control-button" data-index="0"></button>
<button class="control-button" data-index="1"></button>
<button class="control-button" data-index="2"></button>
<button class="control-button" data-index="3"></button>
<button class="control-button" data-index="4"></button>
<button class="control-button" data-index="5"></button>
</section>
<div id="container">
</div>
<!-- Load libs -->
<script src="./lib/three.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tween.js/17.2.0/Tween.min.js"></script>
<script src="./lib/BufferGeometryUtils.js"></script>
<script src="./lib/OrbitControls.js"></script>
<script src="./lib/OBJLoader.js"></script>
<script src="./lib/MTLLoader.js"></script>
<script src="./lib/EffectComposer.js"></script>
<script src="./lib/RenderPass.js"></script>
<script src="./lib/ShaderPass.js"></script>
<script src="./lib/CopyShader.js"></script>
<script src="./lib/BadTVShader.js"></script>
<script src="./lib/FilmPass.js"></script>
<script src="./lib/RGBShiftShader.js"></script>
<script src="./lib/threex.proceduralcity.js"></script>
<!-- Scenes and objects -->
<script src="./src/scenes/cmmnd.js"></script>
<script src="./src/scenes/beach.js"></script>
<script src="./src/scenes/space.js"></script>
<script src="./src/scenes/intersection.js"></script>
<script src="./src/scenes/sky.js"></script>
<script src="./src/scenes/twinpeaks.js"></script>
<!-- 3D Modeled Objects -->
<script src="./src/objects.js"> </script>
<script>
/* TO DO
- postprocessing for all scenes
-
- delta time change to clock.delta
- clone common objects in each scene
- base class for scenes? (handling postprocessing, object cloning, etc.)
*/
const context = window.AudioContext || window.webkitAudioContext;
/*
audioController object
controls audio data
interfaces user audio interaction
controls order of scenes in playloop()
*/
class AudioController {
constructor() {
/* web audio stuff */
this.context = new context;
this.analyser = this.context.createAnalyser();
this.analyser.smoothingTimeConstant = .90;
this.bufferlen = this.analyser.frequencyBinCount;
this.pitch_array = new Uint8Array(this.bufferlen);
this.volume_array = new Uint8Array(this.bufferlen);
/* animation stuff */
this.animationID;
/* audio and scene render */
this.songs = {
INTRO: new Audio("./assets/cmmnd_live/1.wav"),
THEWAY: new Audio("./assets/cmmnd_live/2.wav"),
TENTOES: new Audio("./assets/cmmnd_live/3.wav"),
BAGFLIP: new Audio("./assets/cmmnd_live/4.wav"),
SUICIDE: new Audio("./assets/cmmnd_live/5.wav"),
INDAROCKET: new Audio("./assets/cmmnd_live/6.wav"),
}
/* scene name to audio mapping */
this.scenes = {
INTRO: "CMMND",
THEWAY: "SKY",
TENTOES: "BEACH",
INDAROCKET: "SPACE",
SUICIDE: "TWINPEAKS",
BAGFLIP: "INTERSECTION",
}
this.text = {
INTRO: "WTF IS CMMND? - CMMND",
THEWAY: "THE WAY - KIR.ON, ZÉ ROSÉ, JHERZ, SEIJI ODA, CØLEMAN",
TENTOES: "TENTOES - SLEEPYBOYBRYAN, KRISTA MARINA, BEN 10K, SEIJI ODA, CØLEMAN",
BAGFLIP: "BAGFLIP - ZÉ ROSÉ, YT APEX, GC OKE, SEIJI ODA",
SUICIDE: "SUICIDE DOORS - SEIJI ODA, BEN 10K, KIR.ON FOURTÉ" ,
INDAROCKET: "INDAROCKET - BEN SENSELESS, LANCE CHU, JELEEL!, KEALA ANGELIQUE, CØLEMAN",
}
this.sceneObjects = {
"CMMND": new CMMNDScene,
"BEACH": new BeachScene,
"SPACE": new SpaceScene,
"TWINPEAKS": new TwinPeaksScene,
"INTERSECTION": new IntersectionScene,
"SKY": new SkyScene
}
this.titles = Object.keys(this.songs);
// new array of audio sources
this.sources = [];
this.titles.forEach((title) => {
this.sources.push(this.context.createMediaElementSource(this.songs[title]));
});
// the current scene object being rendered
this.currentScene;
this.scene;
this.currentSong;
this.index = 0;
}
initializeScenes() {
// initialize all scenes once objects are done
for(let scene of Object.values(this.sceneObjects)) {
scene.initScene()
}
}
// returns the audio for the next song
getAudio () {
const title = this.titles[this.index];
return this.songs[title];
};
// gets scene to render based off the current scene
getScene () {
return this.sceneObjects[this.currentScene];
}
// web audio freq data
getFreqData() {
this.analyser.getByteFrequencyData(this.pitch_array);
return this.pitch_array;
}
// web audio vol data
getVolumeData() {
this.analyser.getByteTimeDomainData(this.volume_array);
return this.volume_array;
}
// play song by index
playIndex(idx){
this.getAudio().pause();
this.currentSong.removeEventListener("song ended ", this.songEnded);
if (idx > -1 && idx < 6) {
this.index = idx;
this.playLoop();
}
else {
console.log("error playing song, index not found. Resetting...")
this.index = 0;
this.playLoop();
};
}
// setup webaudio to play next song
// add event listener to each song
// callback increments index
// last callback restarts the index
// play first song
playLoop() {
function songEnded(){
console.log("song ended ");
// // play the next song
console.log("play next song");
this.index++;
if (this.index === 6)
{
this.index = 0;
this.playLoop();
console.log('song loop restarted');
} // restart audio on last song
else this.playLoop();
}
// play first song
const i = this.index;
this.currentSong = this.songs[this.titles[i]];
this.currentScene = this.scenes[this.titles[i]];
this.scene = this.sceneObjects[this.currentScene];
// get text
document.querySelector('.text-container').innerHTML = this.text[this.titles[i]];
console.log("setting scene...");
// this.scene.setObjects();
this.scene.setScene();
console.log("scene set");
this.currentSong.addEventListener("ended", songEnded.bind(this) );
// this.getAudio().currentTime = 0;
console.log("playing", this.titles[i])
this.getAudio().play();
this.sources[i].connect(this.analyser);
this.analyser.connect(this.context.destination);
}
}
/* three.js initialization */
const clock = new THREE.Clock();
const manager = new THREE.LoadingManager();
manager.onStart = function ( url, itemsLoaded, itemsTotal ) {
console.log( 'Started loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );
};
// finish loading
manager.onLoad = function () {
console.log("finished loading models");
audio = new AudioController;
// initialize scenes
audio.initializeScenes();
setTimeout(function() {
// add click to play
let loading = document.querySelector('.loading-screen');
loading.removeChild(document.querySelector('#loading-audio'));
let btn = document.createElement("BUTTON");
btn.classList += " play-button";
btn.id = "play"
btn.innerHTML = '<p>click to play</p>'
loading.appendChild(btn);
function playVis() {
// add controls
let playerControls = document.querySelector('.controls');
playerControls.className += " controls-on";
audio.context.resume();
audio.playLoop();
render(audio.scene);
document.removeEventListener("click", playVis);
loading.parentNode.removeChild(loading);
let renderCanvas = document.getElementById('vis-canvas'); // get canvas
renderCanvas.style.display = "flex";
}
document.addEventListener("click", playVis);
}, 1)
// initialize audio when objects load
console.log( 'Loading complete!');
// display play button
}
manager.onError = function ( url ) {
console.log( 'There was an error loading ' + url );
};
var objLoader = new THREE.OBJLoader(manager);
var textureLoader = new THREE.TextureLoader(manager);
var mtlLoader = new THREE.MTLLoader(manager);
var controls;
var renderer = new THREE.WebGLRenderer({alpha: true});
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.domElement.id = 'vis-canvas';
// models class handles loading
function Models() {
this.car = new THREE.Group()
this.cliff;
this.grass;
this.stereo;
this.archLogo;
this.tower
this.plane;
this.rocket;
this.satellite;
this.platform;
this.logoTexture;
var _this = this;
this.init = () => {
// add cmmnd log
console.log("loading models and textures ...");
loadObj( _this, "rocket", "./assets/models/rocket/rocket.obj", "./assets/models/rocket/rocket.mtl");
loadObj( _this, "plane", "./assets/models/plane/plane.obj", "./assets/models/plane/plane.mtl");
loadObj( _this, "satellite", "./assets/models/satellite/satellite.obj", "./assets/models/satellite/satellite.mtl");
loadObj( _this, "stereo", "./assets/models/stereo.obj");
loadObj( _this, "archLogo", "./assets/models/archLogo.obj");
loadObj( _this, "grass", "./assets/models/obj_Dandelion/Dandelion.obj", "./assets/models/obj_Dandelion/Dandelion.mtl");
loadObj( _this, "tower", "./assets/models/sutroTower.obj");
getCliff(_this);
getCar(_this);
getPlatform(_this);
getTextures(_this, "logoTexture");
};
}
// instantiate objects
const models = new Models();
models.init();
var audio;
/* buttons */
var buttons = document.querySelectorAll('.control-button')
buttons.forEach((button)=>{
let index = button.getAttribute('data-index')
button.addEventListener('click', function(){
audio.playIndex(index)
});
})
/* initialize renderer */
/* post processing effects use these on your scene */
// effect composer
// each scene has a separate render pass
// song ends, 2 seconds to load next scene, shows a bad signal graphic
// renderpass is used on ending of one scene and beginning of next
// instantiated in initscene? or constructor
// settimeout to call function that disables the renderpass after some time
// each scene has own composer and renderpass that uses the badTVPass
document.getElementById('container').appendChild( renderer.domElement );
// render();
// updated scene
// use audio.getScene to get the scene class to render
// pass the scene object we need in to render through a callback function that calls render
// sceneScene.scene, sceneScene.animate (call these two functions)
// save render id somewhere to cancel it
function render(scene){
requestAnimationFrame(() => (render(audio.scene)));
scene.animate();
if( scene.postprocessing ) {
scene.composer.render( clock.getDelta )
}
else renderer.render( scene.scene, scene.camera );
}
</script>
</body>
</html>