diff --git a/bin/AlternativaEditor.swf b/bin/AlternativaEditor.swf index 95e3fee..dc6db7a 100644 Binary files a/bin/AlternativaEditor.swf and b/bin/AlternativaEditor.swf differ diff --git a/src/AlternativaEditor.mxml b/src/AlternativaEditor.mxml index 186de10..5be88dc 100644 --- a/src/AlternativaEditor.mxml +++ b/src/AlternativaEditor.mxml @@ -52,6 +52,8 @@ import mx.events.ListEvent; import mx.events.PropertyChangeEvent; import mx.managers.PopUpManager; + import alternativa.gfx.core.Device; + import alternativa.engine3d.core.View; public static var preview:Preview; @@ -131,7 +133,7 @@ loc2.addEventListener(Event.SELECT, this.specialAppendFromXMLClick); this.initMenuItems(); this.setSnapping(true); - this.initFunctionalLibrary(); + this.waitForContextAndInitFunctionalLibrary(); this.batchProcessor = new BatchProcessor(this.mainScene, this.libraryManager); this.batchProcessor.addEventListener(Event.COMPLETE, this.onBatchProcessingComplete); this.batchProcessor.addEventListener(EditorProgressEvent.PROGRESS, this.onBatchProcessingProgress); @@ -170,6 +172,22 @@ this.progressBar.setProgress(param1.progress, 1); } + private function waitForContextAndInitFunctionalLibrary() : void + { + var device:Device = View.getStaticDevice(); + if(device.getContext3D() != null) + { + initFunctionalLibrary(); + return; + } + device.addEventListener(Event.CONTEXT3D_CREATE, context3DCreated); + } + private function context3DCreated(e:Event):void + { + View.getStaticDevice().removeEventListener(Event.CONTEXT3D_CREATE, context3DCreated); + + initFunctionalLibrary(); + } private function initFunctionalLibrary():void { this.libraryManager.addLibrary(FunctionalProps.getFunctionalLibrary()); diff --git a/src/alternativa/editor/Preview.as b/src/alternativa/editor/Preview.as index fd4462c..4cb2448 100644 --- a/src/alternativa/editor/Preview.as +++ b/src/alternativa/editor/Preview.as @@ -34,6 +34,8 @@ package alternativa.editor private var cameraContainer:Object3DContainer; private var propDistance:Map; + + private var _renderingBlocked:Boolean = false; public function Preview() { @@ -71,6 +73,10 @@ package alternativa.editor private function onEnterFrame(param1:Event) : void { + if(_renderingBlocked) + { + return; + } this.cameraContainer.rotationZ += MathUtils.DEG1; this.scene.calculate(); } @@ -162,12 +168,26 @@ package alternativa.editor public function getPropIcon(param1:Prop) : Bitmap { + _renderingBlocked = true; + + //setup scene this.clearScene(); this.calculateOptimalCameraPosition(param1); this.setCameraCoords(param1); this.scene.root.addChild(param1); - this.scene.calculate(false); + + this.cameraContainer.rotationZ = Math.PI/2; + + //draw to bitmap + var screenBitmap:BitmapData = new BitmapData(stage.width, stage.height, true, 0xff000000); + + View.getStaticDevice().clear(1,1,1); //clear buffers to avoid context3d error + this.scene.calculate(false); + + view.getContext3D().drawToBitmapData(screenBitmap); + + //clean up var mesh:Mesh = (param1.object as Mesh); if(mesh != null) { @@ -179,13 +199,35 @@ package alternativa.editor (currMaterial as TextureMaterial).disposeResource(); } } + + this.scene.root.removeChild(param1); - var loc2:BitmapData = new BitmapData(ICON_SIZE,ICON_SIZE,false,0); + _renderingBlocked = false; + + //draw icon + var imagePos:Point = this.view.localToGlobal(new Point(0,0)); + + var bitmapData:BitmapData = new BitmapData(ICON_SIZE,ICON_SIZE,false,0x0); + + var scale:Number = ICON_SIZE/this.view.width; + + var matrix:Matrix = this.tmpMatrix; + matrix.a = scale; + matrix.d = scale; + matrix.tx = -imagePos.x * scale; + matrix.ty = -imagePos.y * scale; + + bitmapData.draw(screenBitmap,matrix); + screenBitmap.dispose(); + + return new Bitmap(bitmapData); + + /*var loc2:BitmapData = new BitmapData(ICON_SIZE,ICON_SIZE,false,0); var loc3:Matrix = tmpMatrix; loc3.a = ICON_SIZE / this.view.width; loc3.d = loc3.a; loc2.draw(this.view,loc3); - return new Bitmap(loc2); + return new Bitmap(loc2);*/ } private function setCameraCoords(param1:Object3D) : void @@ -223,6 +265,10 @@ package alternativa.editor { this.view.width = parent.width; this.view.height = parent.height; + if(_renderingBlocked) + { + return; + } this.scene.calculate(); } } diff --git a/src/alternativa/editor/engine3d/materials/WireMaterial.as b/src/alternativa/editor/engine3d/materials/WireMaterial.as index 662553a..c229cd5 100644 --- a/src/alternativa/editor/engine3d/materials/WireMaterial.as +++ b/src/alternativa/editor/engine3d/materials/WireMaterial.as @@ -32,6 +32,14 @@ package alternativa.editor.engine3d.materials super(createWireTexture()); } + public override function dispose() : void + { + super.dispose(); + + this.bitmap.dispose(); + this.bitmap = null; + } + override public function clone():Material { var _local_1:WireMaterial = new WireMaterial(_color, _thickness, _width, _height, _segments); diff --git a/src/alternativa/editor/prop/MeshProp.as b/src/alternativa/editor/prop/MeshProp.as index 3779033..85719df 100644 --- a/src/alternativa/editor/prop/MeshProp.as +++ b/src/alternativa/editor/prop/MeshProp.as @@ -41,6 +41,46 @@ package alternativa.editor.prop type = Prop.TILE; this.parseCollisionData(mainObject, objects); } + + public override function dispose() : void + { + if(this.bound) + { + this.bound.faceList.material.dispose(); + this.bound.setMaterialToAllFaces(null); + this.bound.deleteResources(); + this.bound.destroy(); + this.bound = null; + } + + var mesh:Mesh = _object as Mesh; + + if(mesh) + { + mesh.setMaterialToAllFaces(null); + mesh.deleteResources(); + } + + for each(var obj:Object3D in _objects) + { + var objMesh:Mesh = obj as Mesh; + objMesh.setMaterialToAllFaces(null); + objMesh.deleteResources(); + objMesh.destroy(); + } + _objects.length = 0; + _objects = null; + + this.collisionMaterial.dispose(); + this.collisionMaterial = null; + + this.collisionBoxes.clear(); + this.collisionBoxes = null; + + this.bitmaps = null; + + super.dispose(); + } private static function getMirrorBitmapData(param1:BitmapData) : BitmapData { @@ -118,10 +158,15 @@ package alternativa.editor.prop { bitmapData = this._isMirror ? getMirrorBitmapData(this.bitmaps[param1]) : this.bitmaps[param1]; } + if(_material != null) + { + _material.dispose(); + } _material = new TextureMaterial(bitmapData); if(_selected) { - _selectBitmapData.dispose(); + this.disposeSelectTexture(); + select(); } else @@ -141,7 +186,8 @@ package alternativa.editor.prop (_material as TextureMaterial).texture = bitmapData; if(selected) { - _selectBitmapData.dispose(); + this.disposeSelectTexture(); + select(); } else diff --git a/src/alternativa/editor/prop/Prop.as b/src/alternativa/editor/prop/Prop.as index a07e045..73190c6 100644 --- a/src/alternativa/editor/prop/Prop.as +++ b/src/alternativa/editor/prop/Prop.as @@ -63,6 +63,7 @@ package alternativa.editor.prop public var bitmapData:BitmapData; protected var _selectBitmapData:BitmapData; + private var _selectMaterial:Material; public var icon:Bitmap; @@ -89,6 +90,34 @@ package alternativa.editor.prop this.calculate(); } } + + public function dispose() : void + { + if(_material is TextureMaterial) + { + (_material as TextureMaterial).dispose(); + } + _material = null; + + bitmapData = null; + icon = null; + + if(_selectMaterial) + { + _selectMaterial.dispose(); + _selectMaterial = null; + } + if(_selectBitmapData) + { + _selectBitmapData.dispose(); + _selectBitmapData = null; + } + + _object.destroy(); + _object = null; + + super.destroy(); + } private static function calcDistance(param1:Number, param2:Number, param3:Number, param4:Number) : Point { @@ -154,6 +183,9 @@ package alternativa.editor.prop protected function initBitmapData() : void { this._material = Mesh(this._object).faceList.material; + if(this._material == null) + return; + this._material = this._material.clone(); //to easier dispose it if(_material is TextureMaterial && !(_material is FillMaterial)) { this.bitmapData = TextureMaterial(this._material).texture; @@ -281,17 +313,30 @@ package alternativa.editor.prop public function select() : void { - this._selectBitmapData = this.bitmapData.clone(); - _matrix.a = this.bitmapData.width / redBmp.width; - _matrix.d = _matrix.a; - this._selectBitmapData.draw(redBmp,_matrix,null,BlendMode.MULTIPLY); - this.setMaterial(this.newSelectedMaterial); + if(this._selectBitmapData == null) + { + this._selectBitmapData = this.bitmapData.clone(); + _matrix.a = this.bitmapData.width / redBmp.width; + _matrix.d = _matrix.a; + this._selectBitmapData.draw(redBmp,_matrix,null,BlendMode.MULTIPLY); + + _selectMaterial = new TextureMaterial(_selectBitmapData); + } + this.setMaterial(this._selectMaterial); this._selected = true; } + protected function disposeSelectTexture() : void + { + if(_selectBitmapData == null) + return; + _selectMaterial.dispose(); + _selectMaterial = null; + _selectBitmapData.dispose(); + _selectBitmapData = null; + } public function deselect() : void { - this._selectBitmapData.dispose(); if(this._hidden) { this.setMaterial(null); @@ -303,11 +348,6 @@ package alternativa.editor.prop this._selected = false; } - protected function get newSelectedMaterial() : Material - { - return new TextureMaterial(this._selectBitmapData); - } - public function setMaterial(param1:Material) : void { //var loc2:SurfaceMaterial = param1 as SurfaceMaterial; diff --git a/src/alternativa/editor/prop/Sprite3DProp.as b/src/alternativa/editor/prop/Sprite3DProp.as index f8391bb..9cf4af3 100644 --- a/src/alternativa/editor/prop/Sprite3DProp.as +++ b/src/alternativa/editor/prop/Sprite3DProp.as @@ -10,13 +10,18 @@ package alternativa.editor.prop public class Sprite3DProp extends MeshProp { private static const EMPTY_OBJECTS:Vector. = new Vector.(); - - private var spriteTextureMaterial:TextureMaterial; public function Sprite3DProp(param1:Sprite3D, param2:String, param3:String, param4:String, param5:Boolean = true) { super(param1,EMPTY_OBJECTS,param2,param3,param4,param5); } + + public override function dispose() : void + { + (_object as Sprite3D).material = null; + + super.dispose(); + } public function get scale() : Number { @@ -34,36 +39,20 @@ package alternativa.editor.prop override public function setMaterial(param1:Material) : void { - var loc2:TextureMaterial = param1 as TextureMaterial; - if(loc2) - { - //loc2.originX = this.spriteTextureMaterial.originX; - //loc2.originY = this.spriteTextureMaterial.originY; - } - (_object as Sprite3D).material = loc2; + (_object as Sprite3D).material = param1; } override protected function initBitmapData() : void { - _material = (_object as Sprite3D).material; - this.spriteTextureMaterial = _material as TextureMaterial; - bitmapData = this.spriteTextureMaterial.texture; + _material = (_object as Sprite3D).material; //no need to clone(), already cloned earlier + bitmapData = (_material as TextureMaterial).texture; } override public function get vertices() : Vector. { - /*var loc1:Vertex = new Vertex(0,0,0); - var loc2:Map = new Map(); - loc2.add("1",loc1); - return loc2;*/ return Vector.([new Vertex()]); } - override protected function get newSelectedMaterial() : Material - { - return new TextureMaterial(_selectBitmapData); - } - override public function clone() : Object3D { var loc1:Sprite3D = _object.clone() as Sprite3D; diff --git a/src/alternativa/editor/scene/MainScene.as b/src/alternativa/editor/scene/MainScene.as index a6d2de4..ee196bc 100644 --- a/src/alternativa/editor/scene/MainScene.as +++ b/src/alternativa/editor/scene/MainScene.as @@ -831,6 +831,7 @@ package alternativa.editor.scene if(loc2) { root.removeChild(loc2); + loc2.dispose(); } } this.selectedProp = null; diff --git a/src/alternativa/engine3d/core/View.as b/src/alternativa/engine3d/core/View.as index ce32c0f..a8cdb61 100644 --- a/src/alternativa/engine3d/core/View.as +++ b/src/alternativa/engine3d/core/View.as @@ -23,6 +23,7 @@ package alternativa.engine3d.core{ import flash.display.StageAlign; import __AS3__.vec.*; import alternativa.engine3d.alternativa3d; + import flash.display3D.Context3D; use namespace alternativa3d; @@ -112,6 +113,16 @@ package alternativa.engine3d.core{ addEventListener(Event.ADDED_TO_STAGE, this.onAddToStage); } + public static function getStaticDevice() : Device + { + return staticDevice; + } + + public function getContext3D() : Context3D + { + return this.device.getContext3D(); + } + private function onAddToStage(_arg_1:Event):void{ stage.addEventListener(KeyboardEvent.KEY_DOWN, this.onKeyDown); stage.addEventListener(KeyboardEvent.KEY_UP, this.onKeyUp); diff --git a/src/alternativa/gfx/core/Device.as b/src/alternativa/gfx/core/Device.as index d5d41d5..b2a4ea7 100644 --- a/src/alternativa/gfx/core/Device.as +++ b/src/alternativa/gfx/core/Device.as @@ -138,6 +138,11 @@ package alternativa.gfx.core{ dispatchEvent(new Event(Event.CONTEXT3D_CREATE)); } + public function getContext3D() : Context3D + { + return this._stage3D.context3D; + } + public function dispose():void{ var _local_1:*; this._stage3D.removeEventListener(Event.CONTEXT3D_CREATE, this.onContext3DCreate);