preview draw and general optimization

This commit is contained in:
Tubix
2024-12-19 00:52:12 +00:00
parent 3b619e137a
commit 843b99d027
10 changed files with 202 additions and 38 deletions

Binary file not shown.

View File

@@ -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());

View File

@@ -35,6 +35,8 @@ package alternativa.editor
private var propDistance:Map;
private var _renderingBlocked:Boolean = false;
public function Preview()
{
this.propDistance = new Map();
@@ -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.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)
{
@@ -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;
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();
}
}

View File

@@ -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);

View File

@@ -42,6 +42,46 @@ package alternativa.editor.prop
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
{
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];
}
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

View File

@@ -63,6 +63,7 @@ package alternativa.editor.prop
public var bitmapData:BitmapData;
protected var _selectBitmapData:BitmapData;
private var _selectMaterial:Material;
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
{
var loc5:Point = new 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;
@@ -280,18 +312,31 @@ package alternativa.editor.prop
}
public function select() : void
{
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);
this.setMaterial(this.newSelectedMaterial);
_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;

View File

@@ -11,13 +11,18 @@ package alternativa.editor.prop
{
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)
{
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
{
return (_object as Sprite3D).scaleX;
@@ -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.<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()]);
}
override protected function get newSelectedMaterial() : Material
{
return new TextureMaterial(_selectBitmapData);
}
override public function clone() : Object3D
{
var loc1:Sprite3D = _object.clone() as Sprite3D;

View File

@@ -831,6 +831,7 @@ package alternativa.editor.scene
if(loc2)
{
root.removeChild(loc2);
loc2.dispose();
}
}
this.selectedProp = null;

View File

@@ -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);

View File

@@ -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);