Permalink
Browse files

Save and restore GlobalOptions

  • Loading branch information...
1 parent dfee430 commit bd3d83150a3c1371b5dfcb2be9e2dafdd2979f8d @80prozent 80prozent committed Jun 21, 2013
View
3 awaybuilder-core/src/awaybuilder/controller/document/ConcatenateDocumentDataCommand.as
@@ -59,6 +59,9 @@ package awaybuilder.controller.document
document.methods = new ArrayCollection(document.methods.source.concat( data.methods.source ));
+ if(document.empty)
+ document.globalOptions.fill(data.globalOptions);
+
document.empty = false;
if( event.canUndo )
View
130 awaybuilder-core/src/awaybuilder/model/SmartDocumentServiceBase.as
@@ -1,18 +1,5 @@
package awaybuilder.model
{
- import flash.display.Bitmap;
- import flash.display.Loader;
- import flash.display.LoaderInfo;
- import flash.events.Event;
- import flash.net.URLRequest;
- import flash.utils.ByteArray;
-
- import mx.controls.Alert;
- import mx.core.FlexGlobals;
- import mx.managers.CursorManager;
-
- import spark.components.Application;
-
import away3d.cameras.Camera3D;
import away3d.containers.ObjectContainer3D;
import away3d.entities.Mesh;
@@ -23,8 +10,11 @@ package awaybuilder.model
import away3d.library.assets.AssetType;
import away3d.library.assets.BitmapDataAsset;
import away3d.lights.LightBase;
+ import away3d.loaders.AssetLoader;
+ import away3d.loaders.misc.AssetLoaderToken;
import away3d.loaders.parsers.AWDParser;
import away3d.loaders.parsers.Parsers;
+ import away3d.loaders.parsers.utils.ParserUtil;
import away3d.materials.MaterialBase;
import away3d.materials.TextureMaterial;
import away3d.materials.methods.EffectMethodBase;
@@ -38,8 +28,22 @@ package awaybuilder.model
import awaybuilder.model.vo.scene.GeometryVO;
import awaybuilder.utils.logging.AwayBuilderLoadErrorLogger;
+ import flash.display.Bitmap;
+ import flash.display.Loader;
+ import flash.display.LoaderInfo;
+ import flash.events.Event;
+ import flash.net.URLRequest;
+ import flash.utils.ByteArray;
+ import flash.utils.Endian;
+
+ import mx.controls.Alert;
+ import mx.core.FlexGlobals;
+ import mx.managers.CursorManager;
+
import org.robotlegs.mvcs.Actor;
+ import spark.components.Application;
+
public class SmartDocumentServiceBase extends Actor
{
@@ -49,6 +53,7 @@ package awaybuilder.model
private var _document:DocumentVO;
private var _objects:Vector.<ObjectContainer3D> = new Vector.<ObjectContainer3D>();
+ private var _loaderToken:AssetLoaderToken;
protected function loadBitmap( url:String ):void
{
@@ -80,7 +85,8 @@ package awaybuilder.model
AssetLibrary.addEventListener(AssetEvent.TEXTURE_SIZE_ERROR, textureSizeErrorHandler);
AssetLibrary.addEventListener(LoaderEvent.RESOURCE_COMPLETE, resourceCompleteHandler);
AssetLibrary.addEventListener(LoaderEvent.LOAD_ERROR, loadErrorHandler);
- AssetLibrary.load(new URLRequest(url));
+ _loaderToken=AssetLibrary.load(new URLRequest(url));
+ _loaderToken.addEventListener(LoaderEvent.RESOURCE_COMPLETE, resourceCompleteHandlerToken);
CursorManager.setBusyCursor();
Application(FlexGlobals.topLevelApplication).mouseEnabled = false;
@@ -98,7 +104,8 @@ package awaybuilder.model
AssetLibrary.addEventListener(AssetEvent.TEXTURE_SIZE_ERROR, textureSizeErrorHandler);
AssetLibrary.addEventListener(LoaderEvent.RESOURCE_COMPLETE, resourceCompleteHandler);
AssetLibrary.addEventListener(LoaderEvent.LOAD_ERROR, loadErrorHandler);
- AssetLibrary.loadData(data);
+ _loaderToken=AssetLibrary.loadData(data);
+ _loaderToken.addEventListener(LoaderEvent.RESOURCE_COMPLETE, resourceCompleteHandlerToken);
CursorManager.setBusyCursor();
Application(FlexGlobals.topLevelApplication).mouseEnabled = false;
@@ -115,6 +122,22 @@ package awaybuilder.model
AwayBuilderLoadErrorLogger.logError("WARN:"+bdAsset.name+" - Bitmap dimensions are not a power of 2 or larger than 2048. Size:"+bdAsset.bitmapData.width+"x"+bdAsset.bitmapData.height, { assetEvent:bdAsset });
}
+ private function resourceCompleteHandlerToken( event:LoaderEvent ):void
+ {
+ if(AssetLoader(event.target).baseDependency.data)
+ if(AssetLoader(event.target).baseDependency.data is ByteArray)
+ parseGlobalSettings(AssetLoader(event.target).baseDependency.data);
+ _loaderToken.removeEventListener(LoaderEvent.RESOURCE_COMPLETE, resourceCompleteHandlerToken);
+ documentReady( _document );
+
+ }
+
+
+ private function testBitflag(flags:uint, testFlag:uint):Boolean
+ {
+ return (flags & testFlag) == testFlag;
+ }
+
private function resourceCompleteHandler( event:LoaderEvent ):void
{
AssetLibrary.removeEventListener(AssetEvent.ASSET_COMPLETE, assetCompleteHandler);
@@ -134,7 +157,6 @@ package awaybuilder.model
dispatch( new ErrorLogEvent(ErrorLogEvent.LOG_ENTRY_MADE));
}
- documentReady( _document );
CursorManager.removeBusyCursor();
Application(FlexGlobals.topLevelApplication).mouseEnabled = true;
@@ -198,8 +220,8 @@ package awaybuilder.model
_document.lights.addItem( assets.GetAsset( event.asset ) );
break;
case AssetType.MATERIAL:
- if(!( event.asset is TextureMaterial))
- _document.materials.addItem( assets.GetAsset( event.asset ) );
+ if(!( event.asset is TextureMaterial)){
+ _document.materials.addItem( assets.GetAsset( event.asset ) );}
else
if (!assets.checkIfMaterialIsDefault(TextureMaterial(event.asset)))
_document.materials.addItem( assets.GetAsset( event.asset ) );
@@ -226,6 +248,78 @@ package awaybuilder.model
}
}
+ private function parseGlobalSettings(byteData:ByteArray):void
+ {
+ byteData.position=0;
+ var magicString:String=byteData.readUTFBytes(3);
+ if (magicString=="AWD"){
+
+ var awdVersionMajor:uint=byteData.readUnsignedByte();//_version[0]
+ var awdVersionMinor:uint=byteData.readUnsignedByte();//_version[1]
+
+ var flags:uint = byteData.readUnsignedShort(); // Parse bit flags
+ //_streaming = bitFlags.test(flags, bitFlags.FLAG1);//streaming is disabled for now, because it is not used in the parsersystem anyway
+ if ((awdVersionMajor == 2) && (awdVersionMinor == 1)){
+ if (testBitflag(flags, 2))//flag 2
+ _document.globalOptions.matrixStorage="Precision";
+ if (testBitflag(flags, 4))//flag 3
+ _document.globalOptions.geometryStorage="Precision";
+ if (testBitflag(flags, 8))//flag 4
+ _document.globalOptions.propertyStorage ="Precision";
+ if (testBitflag(flags, 16))//flag 5
+ _document.globalOptions.attributesStorage ="Precision";
+ if (!testBitflag(flags, 32))//flag 6
+ _document.globalOptions.includeNormal=false;
+ if (!testBitflag(flags, 64))//flag 7
+ _document.globalOptions.includeTangent=false;
+ if (!testBitflag(flags, 128))//flag 7
+ _document.globalOptions.embedTextures=false;
+ }
+ var _compression:uint = byteData.readUnsignedByte(); // Get Compression
+ var body_len:uint = byteData.readUnsignedInt();
+ var _body:ByteArray;
+ var _curPosition:uint=byteData.position;
+ switch (_compression)
+ {
+ case 0:
+ _document.globalOptions.compression="UNCOMPRESSED";
+ _body = byteData;
+ break;
+ case 1:
+ _document.globalOptions.compression="DEFLATE";
+ _body = new ByteArray();
+ byteData.readBytes(_body, 0, byteData.bytesAvailable);
+ _body.uncompress();
+ break;
+ case 2:
+ _document.globalOptions.compression="LZMA";
+ _body = new ByteArray();
+ byteData.readBytes(_body, 0, byteData.bytesAvailable);
+ _body.uncompress("lzma");
+ break;
+ }
+ _body.endian = Endian.LITTLE_ENDIAN;
+ var foundNameSpaceBlock:Boolean;
+ var blockType:uint;
+ var blockLength:uint;
+ while ((_body.bytesAvailable>0) && (!foundNameSpaceBlock)){
+ _body.position+=5; //id=4, ns=1,
+ blockType=_body.readUnsignedByte();
+ _body.position+=1; //flags=1;
+ blockLength=_body.readUnsignedInt();
+ if(blockType==254){
+ foundNameSpaceBlock=true;
+ _body.position+=1; //ns-id
+ var len:uint = _body.readUnsignedShort();
+ _document.globalOptions.namespace = _body.readUTFBytes(len);
+ }
+ else{
+ _body.position+=blockLength;
+ }
+ }
+ }
+ }
+
private function isGeometryInList( geometry:GeometryVO ):Boolean
{
for each ( var asset:AssetVO in _document.geometry )
View
2 awaybuilder-core/src/awaybuilder/model/vo/DocumentVO.as
@@ -20,5 +20,7 @@ package awaybuilder.model.vo
public var lights:ArrayCollection = new ArrayCollection();
public var methods:ArrayCollection = new ArrayCollection();
+
+ public var globalOptions:GlobalOptionsVO = new GlobalOptionsVO();
}
}
View
46 awaybuilder-core/src/awaybuilder/utils/encoders/AWDEncoder.as
@@ -93,6 +93,7 @@ package awaybuilder.utils.encoders
private var _geomStoragePrecision:uint=0;
private var _matrixStoragePrecision:uint=0;
private var _propsStoragePrecision:uint=0;
+ private var _attrStoragePrecision:uint=0;
private var _embedtextures:Boolean=true;
private var _matrixNrType : uint;
@@ -153,7 +154,6 @@ package awaybuilder.utils.encoders
_nameSpaceID=1;
_nameSpaceString=document.globalOptions.namespace;
_embedtextures=document.globalOptions.embedTextures;
-
// get the type of compression to use
_compression=0;
if(document.globalOptions.compression=="UNCOMPRESSED")
@@ -168,7 +168,6 @@ package awaybuilder.utils.encoders
_blockCompress=_compression;
_compression=0;
}
-
// set the global - storage - precision
_matrixNrType=FLOAT32;
if (document.globalOptions.matrixStorage=="Precision"){
@@ -188,11 +187,24 @@ package awaybuilder.utils.encoders
_attributeNrType=FLOAT32;
if (document.globalOptions.attributesStorage=="Precision"){
_attributeNrType=FLOAT64;
+ _attrStoragePrecision=1;
}
- _exportNormals=document.globalOptions.includeNormal;
- _exportTangents=document.globalOptions.includeTangent;
+ var _embedtexturesInt:int=0;
+ var _exportNormalsInt:int=0;
+ var _exportTangentsInt:int=0;
+ if (document.globalOptions.embedTextures) {
+ _embedtexturesInt=1;
+ }
+ if (document.globalOptions.includeNormal) {
+ _exportNormalsInt=1;
+ }
+ if (document.globalOptions.includeTangent) {
+ _exportTangentsInt=1;
+ }
+
+
if(_debug)trace("start encoding");
//create a AWDBlock class for all supported Assets
@@ -237,10 +249,10 @@ package awaybuilder.utils.encoders
bf |= 0<<10; //Set bit 11
bf |= 0<<9; //Set bit 10
bf |= 0<<8; //Set bit 9
- bf |= 0<<7; //Set bit 8
- bf |= 0<<6; //Set bit 7
- bf |= 0<<5; //Set bit 6
- bf |= 0<<4; //Set bit 5
+ bf |= _embedtexturesInt<<7; //Set bit 8 embed textures AwayBuilder settings
+ bf |= _exportTangentsInt<<6; //Set bit 7 includeTangents AwayBuilder settings
+ bf |= _exportNormalsInt<<5; //Set bit 6 includeNormals AwayBuilder settings
+ bf |= _attrStoragePrecision<<4; //Set bit 5 attrStoragePrecision AwayBuilder settings
bf |= _propsStoragePrecision<<3; //Set bit 4
bf |= _geomStoragePrecision<<2; //Set bit 3
bf |= _matrixStoragePrecision<<1; //Set bit 2
@@ -451,8 +463,8 @@ package awaybuilder.utils.encoders
thisBlock.id=newParentID;
break;
case (vo is MeshVO):
- if(_debug)trace("MeshVO = "+MeshVO(vo).name+" parentID = "+parentID);
- trace("MeshVO(vo).animator = "+MeshVO(vo).animator);
+ if(_debug)trace("MeshVO = "+MeshVO(vo).name+" parentID = "+parentID+" | animator = "+MeshVO(vo).animator);
+
if (MeshVO(vo).animator){
if(!_translateAnimatiorToMesh[MeshVO(vo).animator.id])
_translateAnimatiorToMesh[MeshVO(vo).animator.id]=new Vector.<MeshVO>;
@@ -990,13 +1002,15 @@ package awaybuilder.utils.encoders
var gloss:Number;//19
var specularColor:uint;//20
var specularTexture:uint;//21
- var lightPicker:int;//22
+ var lightPicker:int;//22
var allMethods:Vector.<AWDmethod>=_encodeAllShadingMethods(mtl);
+ texture=-1;
if (mtl.diffuseTexture) texture=_getBlockIDorEncodeAsset(mtl.diffuseTexture);
+ ambientTexture=-1;
if (mtl.ambientTexture) ambientTexture=_getBlockIDorEncodeAsset(mtl.ambientTexture);
- if ((texture)||(ambientTexture)) matType=2;
- if ((texture==0)||(ambientTexture==0)) matType=2;
- if (matType==1) color=mtl.diffuseColor;
+ if ((texture>=0)||(ambientTexture>=0)) matType=2;
+ if (matType==1) color=mtl.diffuseColor;
+
if (mtl.type==MaterialVO.SINGLEPASS){
if (mtl.alpha!=1.0) alpha=mtl.alpha;
if (mtl.alphaBlending!=false) alphaBlending=mtl.alphaBlending;
@@ -1037,7 +1051,7 @@ package awaybuilder.utils.encoders
// Property list
_beginElement(); // Prop list
if (color){ _encodeProperty(1,color, COLOR);}//color
- if (texture){_encodeProperty(2,texture, BADDR);}//texture
+ if (texture>=0){_encodeProperty(2,texture, BADDR);}//texture
if (normalTexture){_encodeProperty(3,normalTexture, BADDR);}//normalMap
if (spezialType){_encodeProperty(4,spezialType, UINT8);}// multi/singlepass
if (smooth==false){_encodeProperty(5, smooth, BOOL);} // smooth
@@ -1052,7 +1066,7 @@ package awaybuilder.utils.encoders
//if (diffuse){_encodeProperty(14, diffuse, FLOAT32);}// diffuse-level (might come in later version)
if (ambient){_encodeProperty(15, ambient, _propNrType);}// ambient-level
if (ambientColor){_encodeProperty(16, ambientColor, COLOR);}// ambient-color
- if (ambientTexture){_encodeProperty(17, ambientTexture, BADDR);}//ambientMap
+ if (ambientTexture>=0){_encodeProperty(17, ambientTexture, BADDR);}//ambientMap
if (specular){_encodeProperty(18, specular, _propNrType);}// specular-level
if (gloss){_encodeProperty(19, gloss, _propNrType);}// specular-gloss
if (specularColor){_encodeProperty(20, specularColor, COLOR);}// specular-color
View
BIN exampleScenes/awd/ogre.awd
Binary file not shown.

0 comments on commit bd3d831

Please sign in to comment.