maps & libs are finally loaded correctly

This commit is contained in:
Tubix
2024-12-18 22:47:31 +00:00
parent 736e6fb5e9
commit 3b619e137a
14 changed files with 143 additions and 36 deletions

Binary file not shown.

View File

@@ -714,7 +714,7 @@
<menuitem label="Library"> <menuitem label="Library">
<menuitem label="Clear" keyEquivalent="l" ctrlKey="true" altKey="true" click="onClearLibClick"/> <menuitem label="Clear" keyEquivalent="l" ctrlKey="true" altKey="true" click="onClearLibClick"/>
<menuitem label="Clear and load" keyEquivalent="l" ctrlKey="true" altKey="true" click="onClearAndLoadLibClick"/> <menuitem label="Clear and load" keyEquivalent="l" ctrlKey="true" altKey="true" click="onClearAndLoadLibClick"/>
<menuitem label="Load" keyEquivalent="l" ctrlKey="true" click="onLoadLibClick()"/> <menuitem label="Load" keyEquivalent="l" ctrlKey="true" click="onLoadLibClick"/>
</menuitem> </menuitem>
<menuitem label="Options"> <menuitem label="Options">
<menuitem label="Props intersection check"> <menuitem label="Props intersection check">

View File

@@ -17,6 +17,9 @@ package alternativa.editor
import flash.geom.Point; import flash.geom.Point;
import mx.core.UIComponent; import mx.core.UIComponent;
import alternativa.engine3d.core.Object3DContainer; import alternativa.engine3d.core.Object3DContainer;
import alternativa.engine3d.objects.Mesh;
import alternativa.engine3d.materials.Material;
import alternativa.engine3d.materials.TextureMaterial;
public class Preview extends UIComponent public class Preview extends UIComponent
{ {
@@ -74,10 +77,16 @@ package alternativa.editor
private function calculateOptimalCameraPosition(param1:Prop) : void private function calculateOptimalCameraPosition(param1:Prop) : void
{ {
var storedPoint:Point = this.propDistance[param1];
if(storedPoint != null)
{
return;
}
var loc7:BitmapData = null; var loc7:BitmapData = null;
var loc8:Vector.<Vertex> = null; //var loc8:Vector.<Vertex> = null;
var loc9:int = 0; //var loc9:int = 0;
var loc10:int = 0; //var loc10:int = 0;
var loc11:Point3D = new Point3D(); var loc11:Point3D = new Point3D();
var loc12:Number = NaN; var loc12:Number = NaN;
var loc13:Number = NaN; var loc13:Number = NaN;
@@ -96,9 +105,32 @@ package alternativa.editor
} }
else else
{ {
loc8 = param1.vertices; var vertex:Vertex = (param1.object as Mesh).vertexList;
loc9 = int(loc8.length); //loc8 = param1.vertices;
loc10 = 0; //loc9 = int(loc8.length);
while(vertex != null)
{
loc11.copyFromVertex(vertex);
loc12 = loc11.x - param1.x;
loc13 = loc11.y - param1.y;
loc14 = loc11.z - param1.z;
loc15 = loc12 * loc12 + loc13 * loc13 + loc14 * loc14;
if(loc15 > loc2)
{
loc2 = loc15;
}
if(loc11.z < loc4)
{
loc4 = loc11.z;
}
if(loc11.z > loc3)
{
loc3 = loc11.z;
}
vertex = vertex.next;
}
/*loc10 = 0;
while(loc10 < loc9) while(loc10 < loc9)
{ {
loc11.copyFromVertex(loc8[loc10]); loc11.copyFromVertex(loc8[loc10]);
@@ -119,22 +151,37 @@ package alternativa.editor
loc3 = loc11.z; loc3 = loc11.z;
} }
loc10++; loc10++;
} }*/
loc2 = 2 * Math.sqrt(loc2); loc2 = 2 * Math.sqrt(loc2);
} }
var loc6:Number = loc2 * (Math.SQRT2 / (2 * Math.tan(this.camera.fov / 2)) + 0.5); var loc6:Number = loc2 * (Math.SQRT2 / (2 * Math.tan(this.camera.fov / 2)) + 0.5);
this.propDistance.add(param1,new Point(loc6,(loc3 - loc4) / 2)); this.propDistance.add(param1,new Point(loc6,(loc3 - loc4) / 2));
} }
private const tmpMatrix:Matrix = new Matrix();
public function getPropIcon(param1:Prop) : Bitmap public function getPropIcon(param1:Prop) : Bitmap
{ {
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.scene.calculate(); this.scene.calculate(false);
var mesh:Mesh = (param1.object as Mesh);
if(mesh != null)
{
mesh.deleteResources();
var currMaterial:Material = mesh.faceList.material;
if(currMaterial is TextureMaterial)
{
(currMaterial as TextureMaterial).disposeResource();
}
}
var loc2:BitmapData = new BitmapData(ICON_SIZE,ICON_SIZE,false,0); var loc2:BitmapData = new BitmapData(ICON_SIZE,ICON_SIZE,false,0);
var loc3:Matrix = new Matrix(); 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);

View File

@@ -206,6 +206,7 @@ package alternativa.editor
//this.cursorScene.occupyMap = this.mainScene.occupyMap; //this.cursorScene.occupyMap = this.mainScene.occupyMap;
addChild(this.mainScene.view); addChild(this.mainScene.view);
//addChild(this.cursorScene.view); //addChild(this.cursorScene.view);
addChild(this.mainScene.camera.diagram);
this.boundBoxesOverlay = new Shape(); this.boundBoxesOverlay = new Shape();
addChild(this.boundBoxesOverlay); addChild(this.boundBoxesOverlay);
this.dominationOverlay = new Shape(); this.dominationOverlay = new Shape();
@@ -577,6 +578,10 @@ package alternativa.editor
private function onEnterFrame(param1:Event) : void private function onEnterFrame(param1:Event) : void
{ {
if(!this.mainScene.view.visible)
{
return;
}
this.cursorScene.containerController.yawLeft(this.keyMapper.keyPressed(0)); this.cursorScene.containerController.yawLeft(this.keyMapper.keyPressed(0));
this.cursorScene.containerController.yawRight(this.keyMapper.keyPressed(1)); this.cursorScene.containerController.yawRight(this.keyMapper.keyPressed(1));
this.cursorScene.containerController.pitchDown(this.keyMapper.keyPressed(6)); this.cursorScene.containerController.pitchDown(this.keyMapper.keyPressed(6));

View File

@@ -25,9 +25,9 @@ package alternativa.editor.engine3d
} }
public function calculate() : void public function calculate(present:Boolean = true) : void
{ {
var child:Object3D = _root.childrenList; /*var child:Object3D = _root.childrenList;
while(child != null) while(child != null)
{ {
if(child is Prop) if(child is Prop)
@@ -36,9 +36,9 @@ package alternativa.editor.engine3d
} }
child = child.next; child = child.next;
} }*/
this.camera.render(); this.camera.render(present);
} }
} }
} }

View File

@@ -155,6 +155,7 @@ package alternativa.editor.mapimport.xml
for(tName in loc5) for(tName in loc5)
{ {
tile.textureName = tName; tile.textureName = tName;
break;//
} }
Alert.show("Tile " + tile.name + ": texture " + textureName + " not found"); Alert.show("Tile " + tile.name + ": texture " + textureName + " not found");
} }
@@ -202,7 +203,7 @@ package alternativa.editor.mapimport.xml
if(loc3 != null) if(loc3 != null)
{ {
this.scene.addProp(loc3,new Point3D(Number(param1.x),Number(param1.y),Number(param1.z)),0,true,false); this.scene.addProp(loc3,new Point3D(Number(param1.x),Number(param1.y),Number(param1.z)),0,true,false);
this.scene.calculate(); //this.scene.calculate();
} }
} }
@@ -258,7 +259,7 @@ package alternativa.editor.mapimport.xml
{ {
this.scene.occupyMap.occupy(loc6); this.scene.occupyMap.occupy(loc6);
} }
this.scene.calculate(); //this.scene.calculate();
} }
loc3++; loc3++;
} }
@@ -295,7 +296,7 @@ package alternativa.editor.mapimport.xml
{ {
this.scene.occupyMap.occupy(loc3); this.scene.occupyMap.occupy(loc3);
} }
this.scene.calculate(); //this.scene.calculate();
} }
return SpawnPoint(loc3); return SpawnPoint(loc3);
} }
@@ -324,7 +325,7 @@ package alternativa.editor.mapimport.xml
this.scene.occupyMap.occupy(loc6); this.scene.occupyMap.occupy(loc6);
} }
this.loadDominationPointSpawns(loc4,ControlPoint(loc6)); this.loadDominationPointSpawns(loc4,ControlPoint(loc6));
this.scene.calculate(); //this.scene.calculate();
} }
} }
} }

View File

@@ -199,7 +199,7 @@ package alternativa.editor.propslib
} }
var loc4:ObjectLoaderPair = new ObjectLoaderPair(); var loc4:ObjectLoaderPair = new ObjectLoaderPair();
loc4.propObject = new PropLibMesh(param1.@name); loc4.propObject = new PropLibMesh(param1.@name);
loc4.loader = new MeshLoader(this.url + loc2.attribute("file").toString().toLowerCase(),xmlReadAttrString(loc2,"object"),loc3); loc4.loader = new MeshLoader(this.url + loc2.attribute("file").toString().toLowerCase(),xmlReadAttrString(loc2,"object"),loc3,this.url);
return loc4; return loc4;
} }

View File

@@ -14,6 +14,10 @@ package alternativa.editor.propslib.loaders
import alternativa.engine3d.core.Face; import alternativa.engine3d.core.Face;
import alternativa.editor.engine3d.loaders.TextureMapsBatchLoader; import alternativa.editor.engine3d.loaders.TextureMapsBatchLoader;
import alternativa.engine3d.core.Object3D; import alternativa.engine3d.core.Object3D;
import alternativa.editor.engine3d.loaders.TextureMapsInfo;
import mx.controls.Alert;
import flash.display.BitmapData;
import alternativa.engine3d.materials.FillMaterial;
public class MeshLoader extends ObjectLoader public class MeshLoader extends ObjectLoader
{ {
@@ -34,13 +38,16 @@ package alternativa.editor.propslib.loaders
private var texturesLoader:TextureMapsBatchLoader; private var texturesLoader:TextureMapsBatchLoader;
private var loaderContext:LoaderContext; private var loaderContext:LoaderContext;
private var baseUrl:String;
public function MeshLoader(param1:String, param2:String, param3:Map) public function MeshLoader(param1:String, param2:String, param3:Map, baseUrl:String)
{ {
super(); super();
this.url = param1; this.url = param1;
this.objectName = param2; this.objectName = param2;
this.textures = param3; this.textures = param3;
this.baseUrl = baseUrl;
} }
override public function load(param1:LoaderContext) : void override public function load(param1:LoaderContext) : void
@@ -60,6 +67,12 @@ package alternativa.editor.propslib.loaders
private function on3DSLoadingComplete(param1:Event) : void private function on3DSLoadingComplete(param1:Event) : void
{ {
this.parser3DS.parse(this.loader3DS.data); this.parser3DS.parse(this.loader3DS.data);
this.loader3DS.removeEventListener(Event.COMPLETE,this.on3DSLoadingComplete);
this.loader3DS.removeEventListener(IOErrorEvent.IO_ERROR,onErrorEvent);
this.loader3DS.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,onErrorEvent);
this.loader3DS = null;
if(this.objectName != null) if(this.objectName != null)
{ {
this.object = this.parser3DS.getObjectByName(this.objectName) as Mesh; this.object = this.parser3DS.getObjectByName(this.objectName) as Mesh;
@@ -73,10 +86,14 @@ package alternativa.editor.propslib.loaders
this.objects = this.parser3DS.objects.concat(); this.objects = this.parser3DS.objects.concat();
this.objects.removeAt(this.objects.indexOf(this.object)); this.objects.removeAt(this.objects.indexOf(this.object));
this.loader3DS.removeEventListener(Event.COMPLETE,this.on3DSLoadingComplete); if(this.textures == null && this.parser3DS.textureMaterials.length > 0)
this.loader3DS.removeEventListener(IOErrorEvent.IO_ERROR,onErrorEvent); {
this.loader3DS.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,onErrorEvent); var defaultMaterial:TextureMaterial = this.parser3DS.textureMaterials[0];
this.loader3DS = null; this.textures = new Map();
var opacityUrl:String = (defaultMaterial.opacityMapURL != null ? this.baseUrl + defaultMaterial.opacityMapURL.toLowerCase() : null);
this.textures.add("DEFAULT", new TextureMapsInfo(this.baseUrl+defaultMaterial.diffuseMapURL.toLowerCase(), opacityUrl));
}
if(this.textures != null) if(this.textures != null)
{ {
this.texturesLoader = new TextureMapsBatchLoader(); this.texturesLoader = new TextureMapsBatchLoader();
@@ -109,6 +126,22 @@ package alternativa.editor.propslib.loaders
this.texturesLoader.removeEventListener(Event.COMPLETE,this.onTexturesLoadingComplete); this.texturesLoader.removeEventListener(Event.COMPLETE,this.onTexturesLoadingComplete);
this.texturesLoader.removeEventListener(IOErrorEvent.IO_ERROR,onErrorEvent); this.texturesLoader.removeEventListener(IOErrorEvent.IO_ERROR,onErrorEvent);
this.texturesLoader = null; this.texturesLoader = null;
if(this.object.faceList.material is FillMaterial)
{
this.object.setMaterialToAllFaces(null);
}
var defaultTexture:BitmapData = this.bitmaps["DEFAULT"];
if(defaultTexture != null)
{
this.object.setMaterialToAllFaces(new TextureMaterial(defaultTexture));
}
else if(this.bitmaps.length == 0)
{
Alert.show("no textures: " + toString());
}
complete(); complete();
} }

View File

@@ -44,7 +44,7 @@ package alternativa.editor.propslib.loaders
private function onLoadingComplete(param1:Event) : void private function onLoadingComplete(param1:Event) : void
{ {
this.sprite = new Sprite3D(100,150); this.sprite = new Sprite3D(100,100);
//this.sprite.material = new SpriteTextureMaterial(new Texture(this.loader.bitmapData),1,true,BlendMode.NORMAL,this.originX,this.originY); //this.sprite.material = new SpriteTextureMaterial(new Texture(this.loader.bitmapData),1,true,BlendMode.NORMAL,this.originX,this.originY);
this.sprite.material = new TextureMaterial(this.loader.bitmapData); this.sprite.material = new TextureMaterial(this.loader.bitmapData);
this.sprite.originX = this.originX; this.sprite.originX = this.originX;

View File

@@ -248,7 +248,7 @@ package alternativa.engine3d.core
this.shadows = new Dictionary(); this.shadows = new Dictionary();
} }
public function render():void public function render(present:Boolean = true):void
{ {
var _local_1:int; var _local_1:int;
var _local_2:int; var _local_2:int;
@@ -791,7 +791,10 @@ package alternativa.engine3d.core
{ {
this.onRender(); this.onRender();
}; };
this.view.present(); if(present)
{
this.view.present();
}
} else } else
{ {
this.view.clearArea(); this.view.clearArea();
@@ -799,7 +802,10 @@ package alternativa.engine3d.core
{ {
this.onRender(); this.onRender();
}; };
this.view.present(); if(present)
{
this.view.present();
}
}; };
this.device = null; this.device = null;
}; };

View File

@@ -43,7 +43,7 @@ package alternativa.engine3d.core
alternativa3d var index:int; alternativa3d var index:int;
alternativa3d var next:Vertex; public var next:Vertex;
alternativa3d var value:Vertex; alternativa3d var value:Vertex;

View File

@@ -53,11 +53,12 @@ package alternativa.engine3d.materials
this.smooth = _arg_3; this.smooth = _arg_3;
this._mipMapping = _arg_4; this._mipMapping = _arg_4;
this.resolution = _arg_5; this.resolution = _arg_5;
if (_arg_1 != null) this.bitmap = _arg_1;
/*if (_arg_1 != null)
{ {
this.bitmap = _arg_1; this.bitmap = _arg_1;
this.textureResource = TextureResourcesRegistry.getTextureResource(_arg_1, (this._mipMapping > 0), _arg_2, this._hardwareMipMaps); this.textureResource = TextureResourcesRegistry.getTextureResource(_arg_1, (this._mipMapping > 0), _arg_2, this._hardwareMipMaps);
}; };*/
} }
public function get texture():BitmapData public function get texture():BitmapData
@@ -66,7 +67,7 @@ package alternativa.engine3d.materials
{ {
return (this.textureResource.bitmapData); return (this.textureResource.bitmapData);
}; };
return (null); return this.bitmap;
} }
public function set texture(_arg_1:BitmapData):void public function set texture(_arg_1:BitmapData):void
@@ -81,9 +82,10 @@ package alternativa.engine3d.materials
}; };
if (_arg_1 != null) if (_arg_1 != null)
{ {
this.textureResource = TextureResourcesRegistry.getTextureResource(_arg_1, (this._mipMapping > 0), this.repeat, this._hardwareMipMaps); //this.textureResource = TextureResourcesRegistry.getTextureResource(_arg_1, (this._mipMapping > 0), this.repeat, this._hardwareMipMaps);
}; };
}; };
this.bitmap = _arg_1;
} }
public function get textureATF():ByteArray public function get textureATF():ByteArray
@@ -140,7 +142,7 @@ package alternativa.engine3d.materials
this._mipMapping = _arg_1; this._mipMapping = _arg_1;
if (this.bitmap != null) if (this.bitmap != null)
{ {
this.textureResource = TextureResourcesRegistry.getTextureResource(this.bitmap, (this._mipMapping > 0), this.repeat, this._hardwareMipMaps); //this.textureResource = TextureResourcesRegistry.getTextureResource(this.bitmap, (this._mipMapping > 0), this.repeat, this._hardwareMipMaps);
}; };
} }
@@ -170,6 +172,14 @@ package alternativa.engine3d.materials
}; };
} }
private function createResourceIfNeeded() : void
{
if(this.textureResource == null && this.bitmap != null)
{
this.textureResource = TextureResourcesRegistry.getTextureResource(this.bitmap, (this._mipMapping > 0), this.repeat, this._hardwareMipMaps);
}
}
override public function clone():Material override public function clone():Material
{ {
var _local_1:TextureMaterial = new TextureMaterial(this.texture, this.repeat, this.smooth, this._mipMapping, this.resolution); var _local_1:TextureMaterial = new TextureMaterial(this.texture, this.repeat, this.smooth, this._mipMapping, this.resolution);
@@ -214,6 +224,8 @@ package alternativa.engine3d.materials
{ {
return; return;
}; };
this.createResourceIfNeeded();
var _local_8:Device = _arg_1.device; var _local_8:Device = _arg_1.device;
var _local_9:Boolean = (_arg_6 is Decal); var _local_9:Boolean = (_arg_6 is Decal);
var _local_10:Boolean = ((!(_local_9)) && (zOffset)); var _local_10:Boolean = ((!(_local_9)) && (zOffset));
@@ -344,6 +356,8 @@ package alternativa.engine3d.materials
{ {
return; return;
}; };
this.createResourceIfNeeded();
var _local_9:Device = _arg_1.device; var _local_9:Device = _arg_1.device;
var _local_10:Boolean = zOffset; var _local_10:Boolean = zOffset;
var _local_11:Boolean = ((_arg_1.fogAlpha > 0) && (_arg_1.fogStrength > 0)); var _local_11:Boolean = ((_arg_1.fogAlpha > 0) && (_arg_1.fogStrength > 0));

View File

@@ -26,7 +26,7 @@ package alternativa.engine3d.objects
public var clipping:int = 2; public var clipping:int = 2;
public var sorting:int = 1; public var sorting:int = 1;
public var threshold:Number = 0.01; public var threshold:Number = 0.01;
alternativa3d var vertexList:Vertex; public var vertexList:Vertex;
public var faceList:Face; public var faceList:Face;
alternativa3d var vertexBuffer:VertexBufferResource; alternativa3d var vertexBuffer:VertexBufferResource;
alternativa3d var indexBuffer:IndexBufferResource; alternativa3d var indexBuffer:IndexBufferResource;
@@ -2962,7 +2962,7 @@ package alternativa.engine3d.objects
}; };
} }
alternativa3d function deleteResources():void public function deleteResources():void
{ {
if (this.vertexBuffer != null) if (this.vertexBuffer != null)
{ {

View File

@@ -70,6 +70,7 @@ package alternativa.gfx.core{
this.backBufferAntiAlias = -1; this.backBufferAntiAlias = -1;
this.backBufferEnableDepthAndStencil = false; this.backBufferEnableDepthAndStencil = false;
var _local_2:Context3D = this._stage3D.context3D; var _local_2:Context3D = this._stage3D.context3D;
//_local_2.ignoreResourceLimits = true;
_local_2.enableErrorChecking = this._enableErrorChecking; _local_2.enableErrorChecking = this._enableErrorChecking;
for (_local_3 in this.resourcesToUpload) for (_local_3 in this.resourcesToUpload)
{ {