mirror of
https://github.com/MapMakersAndProgrammers/alternativa-editor-mod.git
synced 2025-10-26 01:49:05 -07:00
preview draw and general optimization
This commit is contained in:
Binary file not shown.
@@ -52,6 +52,8 @@
|
|||||||
import mx.events.ListEvent;
|
import mx.events.ListEvent;
|
||||||
import mx.events.PropertyChangeEvent;
|
import mx.events.PropertyChangeEvent;
|
||||||
import mx.managers.PopUpManager;
|
import mx.managers.PopUpManager;
|
||||||
|
import alternativa.gfx.core.Device;
|
||||||
|
import alternativa.engine3d.core.View;
|
||||||
|
|
||||||
public static var preview:Preview;
|
public static var preview:Preview;
|
||||||
|
|
||||||
@@ -131,7 +133,7 @@
|
|||||||
loc2.addEventListener(Event.SELECT, this.specialAppendFromXMLClick);
|
loc2.addEventListener(Event.SELECT, this.specialAppendFromXMLClick);
|
||||||
this.initMenuItems();
|
this.initMenuItems();
|
||||||
this.setSnapping(true);
|
this.setSnapping(true);
|
||||||
this.initFunctionalLibrary();
|
this.waitForContextAndInitFunctionalLibrary();
|
||||||
this.batchProcessor = new BatchProcessor(this.mainScene, this.libraryManager);
|
this.batchProcessor = new BatchProcessor(this.mainScene, this.libraryManager);
|
||||||
this.batchProcessor.addEventListener(Event.COMPLETE, this.onBatchProcessingComplete);
|
this.batchProcessor.addEventListener(Event.COMPLETE, this.onBatchProcessingComplete);
|
||||||
this.batchProcessor.addEventListener(EditorProgressEvent.PROGRESS, this.onBatchProcessingProgress);
|
this.batchProcessor.addEventListener(EditorProgressEvent.PROGRESS, this.onBatchProcessingProgress);
|
||||||
@@ -170,6 +172,22 @@
|
|||||||
this.progressBar.setProgress(param1.progress, 1);
|
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
|
private function initFunctionalLibrary():void
|
||||||
{
|
{
|
||||||
this.libraryManager.addLibrary(FunctionalProps.getFunctionalLibrary());
|
this.libraryManager.addLibrary(FunctionalProps.getFunctionalLibrary());
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ package alternativa.editor
|
|||||||
|
|
||||||
private var propDistance:Map;
|
private var propDistance:Map;
|
||||||
|
|
||||||
|
private var _renderingBlocked:Boolean = false;
|
||||||
|
|
||||||
public function Preview()
|
public function Preview()
|
||||||
{
|
{
|
||||||
this.propDistance = new Map();
|
this.propDistance = new Map();
|
||||||
@@ -71,6 +73,10 @@ package alternativa.editor
|
|||||||
|
|
||||||
private function onEnterFrame(param1:Event) : void
|
private function onEnterFrame(param1:Event) : void
|
||||||
{
|
{
|
||||||
|
if(_renderingBlocked)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.cameraContainer.rotationZ += MathUtils.DEG1;
|
this.cameraContainer.rotationZ += MathUtils.DEG1;
|
||||||
this.scene.calculate();
|
this.scene.calculate();
|
||||||
}
|
}
|
||||||
@@ -162,12 +168,26 @@ package alternativa.editor
|
|||||||
|
|
||||||
public function getPropIcon(param1:Prop) : Bitmap
|
public function getPropIcon(param1:Prop) : Bitmap
|
||||||
{
|
{
|
||||||
|
_renderingBlocked = true;
|
||||||
|
|
||||||
|
//setup scene
|
||||||
this.clearScene();
|
this.clearScene();
|
||||||
this.calculateOptimalCameraPosition(param1);
|
this.calculateOptimalCameraPosition(param1);
|
||||||
this.setCameraCoords(param1);
|
this.setCameraCoords(param1);
|
||||||
this.scene.root.addChild(param1);
|
this.scene.root.addChild(param1);
|
||||||
|
|
||||||
|
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);
|
this.scene.calculate(false);
|
||||||
|
|
||||||
|
view.getContext3D().drawToBitmapData(screenBitmap);
|
||||||
|
|
||||||
|
//clean up
|
||||||
var mesh:Mesh = (param1.object as Mesh);
|
var mesh:Mesh = (param1.object as Mesh);
|
||||||
if(mesh != null)
|
if(mesh != null)
|
||||||
{
|
{
|
||||||
@@ -180,12 +200,34 @@ package alternativa.editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var loc2:BitmapData = new BitmapData(ICON_SIZE,ICON_SIZE,false,0);
|
this.scene.root.removeChild(param1);
|
||||||
|
|
||||||
|
_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;
|
var loc3:Matrix = tmpMatrix;
|
||||||
loc3.a = ICON_SIZE / this.view.width;
|
loc3.a = ICON_SIZE / this.view.width;
|
||||||
loc3.d = loc3.a;
|
loc3.d = loc3.a;
|
||||||
loc2.draw(this.view,loc3);
|
loc2.draw(this.view,loc3);
|
||||||
return new Bitmap(loc2);
|
return new Bitmap(loc2);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setCameraCoords(param1:Object3D) : void
|
private function setCameraCoords(param1:Object3D) : void
|
||||||
@@ -223,6 +265,10 @@ package alternativa.editor
|
|||||||
{
|
{
|
||||||
this.view.width = parent.width;
|
this.view.width = parent.width;
|
||||||
this.view.height = parent.height;
|
this.view.height = parent.height;
|
||||||
|
if(_renderingBlocked)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.scene.calculate();
|
this.scene.calculate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,14 @@ package alternativa.editor.engine3d.materials
|
|||||||
super(createWireTexture());
|
super(createWireTexture());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override function dispose() : void
|
||||||
|
{
|
||||||
|
super.dispose();
|
||||||
|
|
||||||
|
this.bitmap.dispose();
|
||||||
|
this.bitmap = null;
|
||||||
|
}
|
||||||
|
|
||||||
override public function clone():Material
|
override public function clone():Material
|
||||||
{
|
{
|
||||||
var _local_1:WireMaterial = new WireMaterial(_color, _thickness, _width, _height, _segments);
|
var _local_1:WireMaterial = new WireMaterial(_color, _thickness, _width, _height, _segments);
|
||||||
|
|||||||
@@ -42,6 +42,46 @@ package alternativa.editor.prop
|
|||||||
this.parseCollisionData(mainObject, objects);
|
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
|
private static function getMirrorBitmapData(param1:BitmapData) : BitmapData
|
||||||
{
|
{
|
||||||
var loc2:BitmapData = new BitmapData(param1.width,param1.height);
|
var loc2:BitmapData = new BitmapData(param1.width,param1.height);
|
||||||
@@ -118,10 +158,15 @@ package alternativa.editor.prop
|
|||||||
{
|
{
|
||||||
bitmapData = this._isMirror ? getMirrorBitmapData(this.bitmaps[param1]) : this.bitmaps[param1];
|
bitmapData = this._isMirror ? getMirrorBitmapData(this.bitmaps[param1]) : this.bitmaps[param1];
|
||||||
}
|
}
|
||||||
|
if(_material != null)
|
||||||
|
{
|
||||||
|
_material.dispose();
|
||||||
|
}
|
||||||
_material = new TextureMaterial(bitmapData);
|
_material = new TextureMaterial(bitmapData);
|
||||||
if(_selected)
|
if(_selected)
|
||||||
{
|
{
|
||||||
_selectBitmapData.dispose();
|
this.disposeSelectTexture();
|
||||||
|
|
||||||
select();
|
select();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -141,7 +186,8 @@ package alternativa.editor.prop
|
|||||||
(_material as TextureMaterial).texture = bitmapData;
|
(_material as TextureMaterial).texture = bitmapData;
|
||||||
if(selected)
|
if(selected)
|
||||||
{
|
{
|
||||||
_selectBitmapData.dispose();
|
this.disposeSelectTexture();
|
||||||
|
|
||||||
select();
|
select();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ package alternativa.editor.prop
|
|||||||
public var bitmapData:BitmapData;
|
public var bitmapData:BitmapData;
|
||||||
|
|
||||||
protected var _selectBitmapData:BitmapData;
|
protected var _selectBitmapData:BitmapData;
|
||||||
|
private var _selectMaterial:Material;
|
||||||
|
|
||||||
public var icon:Bitmap;
|
public var icon:Bitmap;
|
||||||
|
|
||||||
@@ -90,6 +91,34 @@ package alternativa.editor.prop
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
private static function calcDistance(param1:Number, param2:Number, param3:Number, param4:Number) : Point
|
||||||
{
|
{
|
||||||
var loc5:Point = new Point();
|
var loc5:Point = new Point();
|
||||||
@@ -154,6 +183,9 @@ package alternativa.editor.prop
|
|||||||
protected function initBitmapData() : void
|
protected function initBitmapData() : void
|
||||||
{
|
{
|
||||||
this._material = Mesh(this._object).faceList.material;
|
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))
|
if(_material is TextureMaterial && !(_material is FillMaterial))
|
||||||
{
|
{
|
||||||
this.bitmapData = TextureMaterial(this._material).texture;
|
this.bitmapData = TextureMaterial(this._material).texture;
|
||||||
@@ -281,17 +313,30 @@ package alternativa.editor.prop
|
|||||||
|
|
||||||
public function select() : void
|
public function select() : void
|
||||||
{
|
{
|
||||||
this._selectBitmapData = this.bitmapData.clone();
|
if(this._selectBitmapData == null)
|
||||||
_matrix.a = this.bitmapData.width / redBmp.width;
|
{
|
||||||
_matrix.d = _matrix.a;
|
this._selectBitmapData = this.bitmapData.clone();
|
||||||
this._selectBitmapData.draw(redBmp,_matrix,null,BlendMode.MULTIPLY);
|
_matrix.a = this.bitmapData.width / redBmp.width;
|
||||||
this.setMaterial(this.newSelectedMaterial);
|
_matrix.d = _matrix.a;
|
||||||
|
this._selectBitmapData.draw(redBmp,_matrix,null,BlendMode.MULTIPLY);
|
||||||
|
|
||||||
|
_selectMaterial = new TextureMaterial(_selectBitmapData);
|
||||||
|
}
|
||||||
|
this.setMaterial(this._selectMaterial);
|
||||||
this._selected = true;
|
this._selected = true;
|
||||||
}
|
}
|
||||||
|
protected function disposeSelectTexture() : void
|
||||||
|
{
|
||||||
|
if(_selectBitmapData == null)
|
||||||
|
return;
|
||||||
|
_selectMaterial.dispose();
|
||||||
|
_selectMaterial = null;
|
||||||
|
_selectBitmapData.dispose();
|
||||||
|
_selectBitmapData = null;
|
||||||
|
}
|
||||||
|
|
||||||
public function deselect() : void
|
public function deselect() : void
|
||||||
{
|
{
|
||||||
this._selectBitmapData.dispose();
|
|
||||||
if(this._hidden)
|
if(this._hidden)
|
||||||
{
|
{
|
||||||
this.setMaterial(null);
|
this.setMaterial(null);
|
||||||
@@ -303,11 +348,6 @@ package alternativa.editor.prop
|
|||||||
this._selected = false;
|
this._selected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function get newSelectedMaterial() : Material
|
|
||||||
{
|
|
||||||
return new TextureMaterial(this._selectBitmapData);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setMaterial(param1:Material) : void
|
public function setMaterial(param1:Material) : void
|
||||||
{
|
{
|
||||||
//var loc2:SurfaceMaterial = param1 as SurfaceMaterial;
|
//var loc2:SurfaceMaterial = param1 as SurfaceMaterial;
|
||||||
|
|||||||
@@ -11,13 +11,18 @@ package alternativa.editor.prop
|
|||||||
{
|
{
|
||||||
private static const EMPTY_OBJECTS:Vector.<Object3D> = new Vector.<Object3D>();
|
private static const EMPTY_OBJECTS:Vector.<Object3D> = new Vector.<Object3D>();
|
||||||
|
|
||||||
private var spriteTextureMaterial:TextureMaterial;
|
|
||||||
|
|
||||||
public function Sprite3DProp(param1:Sprite3D, param2:String, param3:String, param4:String, param5:Boolean = true)
|
public function Sprite3DProp(param1:Sprite3D, param2:String, param3:String, param4:String, param5:Boolean = true)
|
||||||
{
|
{
|
||||||
super(param1,EMPTY_OBJECTS,param2,param3,param4,param5);
|
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
|
public function get scale() : Number
|
||||||
{
|
{
|
||||||
return (_object as Sprite3D).scaleX;
|
return (_object as Sprite3D).scaleX;
|
||||||
@@ -34,36 +39,20 @@ package alternativa.editor.prop
|
|||||||
|
|
||||||
override public function setMaterial(param1:Material) : void
|
override public function setMaterial(param1:Material) : void
|
||||||
{
|
{
|
||||||
var loc2:TextureMaterial = param1 as TextureMaterial;
|
(_object as Sprite3D).material = param1;
|
||||||
if(loc2)
|
|
||||||
{
|
|
||||||
//loc2.originX = this.spriteTextureMaterial.originX;
|
|
||||||
//loc2.originY = this.spriteTextureMaterial.originY;
|
|
||||||
}
|
|
||||||
(_object as Sprite3D).material = loc2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override protected function initBitmapData() : void
|
override protected function initBitmapData() : void
|
||||||
{
|
{
|
||||||
_material = (_object as Sprite3D).material;
|
_material = (_object as Sprite3D).material; //no need to clone(), already cloned earlier
|
||||||
this.spriteTextureMaterial = _material as TextureMaterial;
|
bitmapData = (_material as TextureMaterial).texture;
|
||||||
bitmapData = this.spriteTextureMaterial.texture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function get vertices() : Vector.<Vertex>
|
override public function get vertices() : Vector.<Vertex>
|
||||||
{
|
{
|
||||||
/*var loc1:Vertex = new Vertex(0,0,0);
|
|
||||||
var loc2:Map = new Map();
|
|
||||||
loc2.add("1",loc1);
|
|
||||||
return loc2;*/
|
|
||||||
return Vector.<Vertex>([new Vertex()]);
|
return Vector.<Vertex>([new Vertex()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
override protected function get newSelectedMaterial() : Material
|
|
||||||
{
|
|
||||||
return new TextureMaterial(_selectBitmapData);
|
|
||||||
}
|
|
||||||
|
|
||||||
override public function clone() : Object3D
|
override public function clone() : Object3D
|
||||||
{
|
{
|
||||||
var loc1:Sprite3D = _object.clone() as Sprite3D;
|
var loc1:Sprite3D = _object.clone() as Sprite3D;
|
||||||
|
|||||||
@@ -831,6 +831,7 @@ package alternativa.editor.scene
|
|||||||
if(loc2)
|
if(loc2)
|
||||||
{
|
{
|
||||||
root.removeChild(loc2);
|
root.removeChild(loc2);
|
||||||
|
loc2.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.selectedProp = null;
|
this.selectedProp = null;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ package alternativa.engine3d.core{
|
|||||||
import flash.display.StageAlign;
|
import flash.display.StageAlign;
|
||||||
import __AS3__.vec.*;
|
import __AS3__.vec.*;
|
||||||
import alternativa.engine3d.alternativa3d;
|
import alternativa.engine3d.alternativa3d;
|
||||||
|
import flash.display3D.Context3D;
|
||||||
|
|
||||||
use namespace alternativa3d;
|
use namespace alternativa3d;
|
||||||
|
|
||||||
@@ -112,6 +113,16 @@ package alternativa.engine3d.core{
|
|||||||
addEventListener(Event.ADDED_TO_STAGE, this.onAddToStage);
|
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{
|
private function onAddToStage(_arg_1:Event):void{
|
||||||
stage.addEventListener(KeyboardEvent.KEY_DOWN, this.onKeyDown);
|
stage.addEventListener(KeyboardEvent.KEY_DOWN, this.onKeyDown);
|
||||||
stage.addEventListener(KeyboardEvent.KEY_UP, this.onKeyUp);
|
stage.addEventListener(KeyboardEvent.KEY_UP, this.onKeyUp);
|
||||||
|
|||||||
@@ -138,6 +138,11 @@ package alternativa.gfx.core{
|
|||||||
dispatchEvent(new Event(Event.CONTEXT3D_CREATE));
|
dispatchEvent(new Event(Event.CONTEXT3D_CREATE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getContext3D() : Context3D
|
||||||
|
{
|
||||||
|
return this._stage3D.context3D;
|
||||||
|
}
|
||||||
|
|
||||||
public function dispose():void{
|
public function dispose():void{
|
||||||
var _local_1:*;
|
var _local_1:*;
|
||||||
this._stage3D.removeEventListener(Event.CONTEXT3D_CREATE, this.onContext3DCreate);
|
this._stage3D.removeEventListener(Event.CONTEXT3D_CREATE, this.onContext3DCreate);
|
||||||
|
|||||||
Reference in New Issue
Block a user