package { import flash.display.*; import flash.events.MouseEvent; import flash.geom.*; import caurina.transitions.*; import org.papervision3d.cameras.*; import org.papervision3d.view.*; import org.papervision3d.materials.*; import org.papervision3d.objects.*; import org.papervision3d.objects.primitives.* [SWF(width = "720", height = "480", frameRate = "60", quality = "low")] public class Main extends BasicView { [Embed(source = 'image.jpg')] private var BitmapImage:Class; // cells static private const MAX_CELL_W:uint = 20; static private const MAX_CELL_H:uint = 15; // array of 3D object private var planeArr:Array /* type of Array */ = []; public function Main() { // init BasicView super(0, 0, true, false, CameraType.TARGET); // capture cell image var bitmap:Bitmap = new BitmapImage(); var bmpDataArr:Array /* type of BitmapData */ = []; // double loop var i:int = 0; var j:int = 0; for (i = 0; i < MAX_CELL_W; i++ ) { for (j = 0; j < MAX_CELL_H; j++ ) { var bmpData:BitmapData = new BitmapData(bitmap.width / MAX_CELL_W, bitmap.height/ MAX_CELL_H, false, 0xFF000000); // use Matrix for image capture var matrix:Matrix = new Matrix(); matrix.translate( - bitmap.width / MAX_CELL_W * i, - bitmap.height / MAX_CELL_H * j); bmpData.draw(bitmap, matrix); bmpDataArr.push(bmpData); } } // Create plane var wrap:DisplayObject3D = scene.addChild(new DisplayObject3D()); wrap.x = - bitmap.width / 2; wrap.y = - bitmap.height / 2; for (i = 0; i < MAX_CELL_W; i++ ) { planeArr[i] /* type of Plane */ = []; for (j = MAX_CELL_H; j > 0 ; j-- ) { var material:BitmapMaterial = new BitmapMaterial(BitmapData(bmpDataArr.shift())); var plane:Plane = new Plane(material, bitmap.width / MAX_CELL_W, bitmap.height / MAX_CELL_H, 1, 1); plane.x = bitmap.width / MAX_CELL_W * i; plane.y = bitmap.height / MAX_CELL_H * j; planeArr[i][j] = wrap.addChild(plane); } } // start render startRendering(); motion(); // and mouse click event stage.addEventListener(MouseEvent.CLICK, motion); // and bg var bgMatrix:Matrix = new Matrix(); bgMatrix.rotate(90 * Math.PI / 180); graphics.beginGradientFill("linear", [0xFFFFFF, 0x001122], [100, 100], [0, 255], bgMatrix); graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight); } /** * Motion * @param event */ private function motion(event:MouseEvent = null):void { // double loop var i:int = 0; var j:int = 0; // plane motion for (i = 0; i < planeArr.length; i++ ) { for (j = 1; j < planeArr[i].length ; j++ ) { var plane:Plane = Plane(planeArr[i][j]); plane.z = -2000; plane.rotationY = 360; var distance:Number = Math.sqrt(i * i + j * j); Tweener.addTween(plane, { z : 0, time : 1.5, transition : "easeOutExpo", delay : distance * .08 }); Tweener.addTween(plane, { rotationY : 0, time : .75, transition : "easeOutExpo", delay : distance * .05 + 1.2 }); } } // camera motion camera.focus = 100; camera.zoom = 2; camera.x = 400; camera.y = 400; camera.z = -1500; Tweener.addTween(camera, { x:0, y:0, z:-200, time :3, transition :"easeInOutExpo" }); } } }