From 1146660a842f4bd961cbc173dff39d1f560f524d Mon Sep 17 00:00:00 2001 From: Marviel Date: Sat, 20 Oct 2018 10:39:14 -0400 Subject: [PATCH] Average frequencies for world is a cube --- js/modes/WorldIsACubeMode.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/js/modes/WorldIsACubeMode.js b/js/modes/WorldIsACubeMode.js index 807772b..10c7064 100644 --- a/js/modes/WorldIsACubeMode.js +++ b/js/modes/WorldIsACubeMode.js @@ -16,6 +16,10 @@ class WorldIsACubeMode { this.material.specularMap = new THREE.TextureLoader().load( "img/earthspec1k.jpg" ); this.material.specular = new THREE.Color('grey') + this.hemLight = new THREE.HemisphereLight( 0xffffbb, 0x080820, 1 ); + vRoot.scene.add(this.hemLight); + + // Sort our vertices into the octants. // --- // --+ @@ -76,9 +80,17 @@ class WorldIsACubeMode { var onCount = 0; + var total = dataArray.reduce((acc, v) => acc + v); + var avg = total / binCount; + + var totalBass = dataArray.slice(binCount/8).reduce((acc, v) => acc + v); + var avgBass = totalBass / (binCount/8); + this.hemLight.intensity = avgBass/255; + for ( var i = 0; i < 8; i ++ ) { - var dataArrI = i % binCount; // Math.floor(i*(binCount/this.spacing)); // Evenly spaced over frequencies. - this.mesh.morphTargetInfluences[ i ] = 1 - dataArray[dataArrI]/255; + //var dataArrI = i % binCount; // Math.floor(i*(binCount/this.spacing)); // Evenly spaced over frequencies. + var dataArrI = binCount / 2; + this.mesh.morphTargetInfluences[ i ] = 1 - avg/255; } } }