package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.text.TextField; import flash.utils.setTimeout; import away3d.containers.ObjectContainer3D; import away3d.containers.View3D; import away3d.core.base.Geometry; import away3d.debug.AwayStats; import away3d.entities.Mesh; import away3d.materials.TextureMaterial; import away3d.primitives.CubeGeometry; import away3d.textures.BitmapTexture; import away3d.tools.commands.Merge; [SWF(frameRate="60", width="960", height="540")] public class Main extends Sprite { //---------------------------------------------------------- // // Static Property // //---------------------------------------------------------- private static const CELL_NUM:uint = 45; //---------------------------------------------------------- // // Constructor // //---------------------------------------------------------- public function Main() { if (stage) addedToStageHanlder(); else addEventListener(Event.ADDED_TO_STAGE, addedToStageHanlder); } //---------------------------------------------------------- // // Property // //---------------------------------------------------------- [Embed(source="/assets/image.png")] private var ImageCls:Class; private var container:ObjectContainer3D; private var cubes:Vector. = new Vector.; private var view:View3D; //---------------------------------------------------------- // // Function // //---------------------------------------------------------- private function addedToStageHanlder(event:Event = null):void { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; var tf:TextField = new TextField(); tf.text = "NOW INITIALIZING\nPLEASE WAIT A MOMENT"; tf.autoSize = "left"; tf.x = (stage.stageWidth - tf.textWidth)/2>>0; tf.y = stage.stageHeight/2>>0; addChild(tf); setTimeout(init, 50); } private function init():void { view = new View3D(); view.antiAlias = 0; this.addChild(view); addChild(new AwayStats(view)); container = new ObjectContainer3D(); view.scene.addChild(container); view.camera.z = -2400; var box:CubeGeometry = new CubeGeometry(30, 30, 30, 1, 1, 1, false); var mesh:Mesh = new Mesh(box); // Box for (var i:int = 0; i < CELL_NUM; i++) { for (var j:int = 0; j < CELL_NUM; j++) { for (var k:int = 0; k < CELL_NUM; k++) { var cube:Mesh = mesh.clone() as Mesh; cube.x = 50 * (i - CELL_NUM / 2); cube.y = 50 * (j - CELL_NUM / 2); cube.z = 50 * (k - CELL_NUM / 2); this.cubes.push(cube); } } } cubes.fixed = true; // marge var merge:Merge = new Merge(); var material:TextureMaterial = new TextureMaterial(new BitmapTexture(new ImageCls().bitmapData)); var meshReceiver:Mesh = new Mesh(new Geometry(), material); merge.applyToMeshes(meshReceiver, cubes); container.addChild(meshReceiver); this.addEventListener(Event.ENTER_FRAME, enterFrameHandler); removeChildAt(0); //remove TextFiled } private function enterFrameHandler(ev:Event):void { container.rotationX += 1; container.rotationY += 1; view.render(); } } }