package { import flash.display.*; import flash.events.*; import flash.media.Sound; import flash.media.SoundMixer; import flash.net.URLRequest; import flash.utils.ByteArray; // Import Papervision3D import org.papervision3d.scenes.*; import org.papervision3d.objects.*; import org.papervision3d.cameras.*; import org.papervision3d.materials.*; import org.papervision3d.events.*; import com.mrdoob_as3.PV3D.*; import com.mrdoob_as3.utils.*; public class main extends Sprite { // ___________________________________________________________________ 3D vars private var container :Sprite; private var scene :MovieScene3D; private var camera :Camera3D; private var root3D :DisplayObject3D; private var timer :Number = 0; private var sound :Sound; private var bytes :ByteArray; private var amount :Number = 15; private var values :Array; // ___________________________________________________________________________________________ main public function main() { stage.quality = "LOW"; stage.scaleMode = "noScale"; this.addEventListener( Event.ENTER_FRAME, loop3D ); init3D(); } // ___________________________________________________________________________________________ init3D private function init3D():void { // Create canvas movieclip and center it this.container = new Sprite(); addChild( this.container ); this.container.x = 500; this.container.y = 300; // Create scene //this.scene = new Scene3D( this.container ); this.scene = new MovieScene3D( this.container ); //fps_system = new fps(); //addChild( fps_system.createText() ); // Create camera camera = new Camera3D(); camera.x = 2000; camera.y = 500; camera.z = 500; //camera.target.y = 2400; camera.zoom = 5; camera.focus = 100; camera.sort = false; var sound:Sound = new Sound(); sound.load(new URLRequest("Crankshaft - Ocean Machine.mp3")); sound.play(); bytes = new ByteArray(); var p:DisplayObject3D; var spacingx:Number = 0; var spacingz:Number = 0; values = new Array(); for (var x:Number = 0; x < amount; x++) { for (var z:Number = 0; z < amount; z++) { values[x+(z*100)] = 0; //if (spacingx == 5 || spacingz == 5) { // p = scene.addChild( new Plane( new ColorMaterial( Math.random()*0xFFFFFF ), 100, 100, 1, 1), "tile"+x+"_"+z ); // p.rotationX = -90; //} else { p = scene.addChild( new Cube( new ColorMaterial( 0x447711 ), 100, 100, 100, 5, 5, 5 ), "tile"+x+"_"+z ); //} p.container.blendMode = BlendMode.ADD; p.sortFaces = false; //p.material.doubleSided = true; //p.rotationX = Math.random()*360; //p.rotationY = Math.random()*360; //p.rotationZ = Math.random()*360; //spacingz ++; //if (spacingz == 6) spacingz = 0; p.rotationY = Math.random()*360; p.scale = Math.random()*3; p.x = Math.random()*2000 - 1000; p.y = Math.random()*2000 - 1000; p.z = Math.random()*2000 - 1000; //p.x = x*150 - ((150*amount) / 2); //p.z = z*150 - ((150*amount) / 2); } //spacingz = 0; //spacingx ++; //if (spacingx == 6) spacingx = 0; } } // ___________________________________________________________________________________________ loop3D private function loop3D( event :Event ):void { timer ++; this.camera.x += ((-this.container.mouseX * 5) - this.camera.x) / 40; this.camera.y += ((-this.container.mouseY * 5) - this.camera.y) / 40; SoundMixer.computeSpectrum( bytes, true, 0 ); var value: Number = 0; var scale: Number = 0.5; var bias: Number = 0.5; for (var x:Number = 0; x < amount; x++) { for (var z:Number = 0; z < amount; z++) { value = bytes.readFloat()* (scale+bias); //trace(value); bias += 0.1; var tile:DisplayObject3D = scene.getChildByName("tile"+x+"_"+z); values[x+(z*100)] -= 0.5; if (value > values[x+(z*100)]) { values[x+(z*100)] = value; } else if (values[x+(z*100)] < 0) { values[x+(z*100)] = 0; } tile.rotationY ++; tile.container.alpha = values[x+(z*100)]+0.05; //tile.rotationY ++; //tile.scaleY = sc.leftPeak; //Math.sin((timer+x+z)/10)+1; } } this.scene.renderCamera( this.camera ); //fps_system.update(); } } }