src/nu/xero/gui/audioVisualizer.as
package nu.xero.gui {
import org.papervision3d.materials.shadematerials.*;
import org.papervision3d.core.geom.renderables.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.core.render.data.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.view.layer.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.lights.*;
import org.papervision3d.view.*;
import caurina.transitions.*;
import flash.display.*;
import flash.filters.*;
import flash.events.*;
import flash.media.*;
import flash.utils.*;
public class audioVisualizer extends BasicView {
public var stats : RenderStatistics;
private var spikey : Sphere;
private var thelight : PointLight3D;
private var bytes : ByteArray;
public function audioVisualizer() {
super(0, 0, true, false, CameraType.TARGET);
thelight = new PointLight3D;
thelight.moveDown(50);
spikey = new Sphere(new FlatShadeMaterial(thelight, 0xfff000, 0x00ff00), 100, 16, 16);
spikey.y+=200;
var vpl:ViewportLayer = viewport.getChildLayer(spikey);
vpl.filters = [new GlowFilter(0x006600, 1, 90, 90, 1, 1, false, false)];
for each(var i:Vertex3D in spikey.geometry.vertices){
i.extra = {baseX:i.x, baseY:i.y, baseZ:i.z, b001: 0};
}
scene.addChild(spikey);
camera.target = spikey;
camera.zoom = 1;
camera.focus = 1000;
bytes = new ByteArray();
stats = renderer.renderScene(scene, camera, viewport);
startRendering();
}
override protected function onRenderTick(e:Event=null):void {
//mouse influence
spikey.rotationY -= (mouseX-(stage.width*.5))/100;
spikey.rotationX -= (mouseY-(stage.height*.5))/100;
//audio visualization
SoundMixer.computeSpectrum(bytes, true, 1);
var byteData: Number = 0;
var scale: Number = 5.5;
var bias: Number = 1;
var num:Number=1;
for each(var i:Vertex3D in spikey.geometry.vertices) {
if(num%6==0){
if(i.extra.b00l == 0){
bias += 0.1;
byteData = Math.abs(bytes.readFloat() * (scale+bias));
Tweener.addTween( i, {
x :i.extra.baseX*byteData,
y :i.extra.baseY*byteData,
z :i.extra.baseZ*byteData,
time :0.2,
delay :0,
transition :"easeNone"
} );
i.extra.b00l=1;
}else{
Tweener.addTween( i, {
x :i.extra.baseX,
y :i.extra.baseY,
z :i.extra.baseZ,
time :0.2,
delay :0,
transition :"easeNone"
} );
i.extra.b00l=0;
}
}
num++;
}
//render scene
super.onRenderTick(e);
}
}
}