/src/away3d/loaders/parsers/AWD2Parser.as
http://github.com/away3d/away3d-core-fp11 · ActionScript · 2525 lines · 2175 code · 222 blank · 128 comment · 451 complexity · 91d69d19eb815a7708649ac5d008dfc6 MD5 · raw file
Large files are truncated click here to view the full file
- package away3d.loaders.parsers
- {
- import away3d.*;
- import away3d.animators.*;
- import away3d.animators.data.*;
- import away3d.animators.nodes.*;
- import away3d.cameras.*;
- import away3d.cameras.lenses.*;
- import away3d.containers.*;
- import away3d.core.base.*;
- import away3d.entities.*;
- import away3d.library.assets.*;
- import away3d.lights.*;
- import away3d.lights.shadowmaps.*;
- import away3d.loaders.misc.*;
- import away3d.loaders.parsers.utils.*;
- import away3d.materials.*;
- import away3d.materials.lightpickers.*;
- import away3d.materials.methods.*;
- import away3d.materials.utils.*;
- import away3d.primitives.*;
- import away3d.textures.*;
- import away3d.tools.utils.*;
-
- import flash.display.*;
- import flash.geom.*;
- import flash.net.*;
- import flash.utils.*;
-
- use namespace arcane;
-
- /**
- * AWDParser provides a parser for the AWD data type.
- */
- public class AWD2Parser extends ParserBase
- {
- //set to "true" to have some traces in the Console
- private var _debug:Boolean = false;
- private var _byteData:ByteArray;
- private var _cur_block_id:uint;
- private var _blocks:Vector.<AWDBlock>;
- private var _newBlockBytes:ByteArray;
-
- private var _version:Array;
- private var _compression:uint;
-
- private var _accuracyOnBlocks:Boolean;
-
- private var _accuracyMatrix:Boolean;
- private var _accuracyGeo:Boolean;
- private var _accuracyProps:Boolean;
-
- private var _matrixNrType:uint;
- private var _geoNrType:uint;
- private var _propsNrType:uint;
-
- private var _streaming:Boolean;
-
- private var _texture_users:Object;
-
- private var _body:ByteArray;
-
- private var _defaultTexture:BitmapTexture;
- private var _defaultCubeTexture:BitmapCubeTexture;
- private var _defaultBitmapMaterial:TextureMaterial;
- private var _cubeTextures:Array;
-
- public static const COMPRESSIONMODE_LZMA:String = "lzma";
-
- public static const UNCOMPRESSED:uint = 0;
- public static const DEFLATE:uint = 1;
- public static const LZMA:uint = 2;
-
- public static const INT8:uint = 1;
- public static const INT16:uint = 2;
- public static const INT32:uint = 3;
- public static const UINT8:uint = 4;
- public static const UINT16:uint = 5;
- public static const UINT32:uint = 6;
- public static const FLOAT32:uint = 7;
- public static const FLOAT64:uint = 8;
-
- public static const BOOL:uint = 21;
- public static const COLOR:uint = 22;
- public static const BADDR:uint = 23;
-
- public static const AWDSTRING:uint = 31;
- public static const AWDBYTEARRAY:uint = 32;
-
- public static const VECTOR2x1:uint = 41;
- public static const VECTOR3x1:uint = 42;
- public static const VECTOR4x1:uint = 43;
- public static const MTX3x2:uint = 44;
- public static const MTX3x3:uint = 45;
- public static const MTX4x3:uint = 46;
- public static const MTX4x4:uint = 47;
-
- private var blendModeDic:Vector.<String>;
- private var _depthSizeDic:Vector.<uint>;
-
- /**
- * Creates a new AWDParser object.
- * @param uri The url or id of the data or file to be parsed.
- * @param extra The holder for extra contextual data that the parser might need.
- */
- public function AWD2Parser()
- {
- super(ParserDataFormat.BINARY);
-
- blendModeDic = new Vector.<String>(); // used to translate ints to blendMode-strings
- blendModeDic.push(BlendMode.NORMAL);
- blendModeDic.push(BlendMode.ADD);
- blendModeDic.push(BlendMode.ALPHA);
- blendModeDic.push(BlendMode.DARKEN);
- blendModeDic.push(BlendMode.DIFFERENCE);
- blendModeDic.push(BlendMode.ERASE);
- blendModeDic.push(BlendMode.HARDLIGHT);
- blendModeDic.push(BlendMode.INVERT);
- blendModeDic.push(BlendMode.LAYER);
- blendModeDic.push(BlendMode.LIGHTEN);
- blendModeDic.push(BlendMode.MULTIPLY);
- blendModeDic.push(BlendMode.NORMAL);
- blendModeDic.push(BlendMode.OVERLAY);
- blendModeDic.push(BlendMode.SCREEN);
- blendModeDic.push(BlendMode.SHADER);
- blendModeDic.push(BlendMode.OVERLAY);
-
- _depthSizeDic = new Vector.<uint>(); // used to translate ints to depthSize-values
- _depthSizeDic.push(256);
- _depthSizeDic.push(512);
- _depthSizeDic.push(2048);
- _depthSizeDic.push(1024);
- }
-
- /**
- * Indicates whether or not a given file extension is supported by the parser.
- * @param extension The file extension of a potential file to be parsed.
- * @return Whether or not the given file type is supported.
- */
- public static function supportsType(extension:String):Boolean
- {
- extension = extension.toLowerCase();
- return extension == "awd";
- }
-
- /**
- * Tests whether a data block can be parsed by the parser.
- * @param data The data block to potentially be parsed.
- * @return Whether or not the given data is supported.
- */
- public static function supportsData(data:*):Boolean
- {
- return (ParserUtil.toString(data, 3) == 'AWD');
- }
- /**
- * @inheritDoc
- */
- override arcane function resolveDependency(resourceDependency:ResourceDependency):void
- {
- // this function will be called when Dependency has finished loading.
- // the Assets waiting for this Bitmap, can be Texture or CubeTexture.
- // if the Bitmap is awaited by a CubeTexture, we need to check if its the last Bitmap of the CubeTexture,
- // so we know if we have to finalize the Asset (CubeTexture) or not.
- if (resourceDependency.assets.length == 1) {
- var isCubeTextureArray:Array = resourceDependency.id.split("#");
- var ressourceID:String = isCubeTextureArray[0];
- var asset:TextureProxyBase;
- var thisBitmapTexture:Texture2DBase;
- var block:AWDBlock;
- if (isCubeTextureArray.length == 1) {
- asset = resourceDependency.assets[0] as Texture2DBase;
- if (asset) {
- var mat:TextureMaterial;
- var users:Array;
- block = _blocks[parseInt(resourceDependency.id)];
- block.data = asset; // Store finished asset
- // Reset name of texture to the one defined in the AWD file,
- // as opposed to whatever the image parser came up with.
- asset.resetAssetPath(block.name, null, true);
- block.name = asset.name;
- // Finalize texture asset to dispatch texture event, which was
- // previously suppressed while the dependency was loaded.
- finalizeAsset(asset);
- if (_debug) {
- trace("Successfully loadet Bitmap for texture");
- trace("Parsed CubeTexture: Name = " + block.name);
- }
- }
- }
- if (isCubeTextureArray.length > 1) {
- thisBitmapTexture = resourceDependency.assets[0] as BitmapTexture;
- _cubeTextures[uint(isCubeTextureArray[1])] = BitmapTexture(thisBitmapTexture).bitmapData;
- _texture_users[ressourceID].push(1);
-
- if (_debug)
- trace("Successfully loadet Bitmap " + _texture_users[ressourceID].length + " / 6 for Cubetexture");
- if (_texture_users[ressourceID].length == _cubeTextures.length) {
- asset = new BitmapCubeTexture(_cubeTextures[0], _cubeTextures[1], _cubeTextures[2], _cubeTextures[3], _cubeTextures[4], _cubeTextures[5]);
- block = _blocks[ressourceID];
- block.data = asset; // Store finished asset
- // Reset name of texture to the one defined in the AWD file,
- // as opposed to whatever the image parser came up with.
- asset.resetAssetPath(block.name, null, true);
- block.name = asset.name;
- // Finalize texture asset to dispatch texture event, which was
- // previously suppressed while the dependency was loaded.
- finalizeAsset(asset);
- if (_debug)
- trace("Parsed CubeTexture: Name = " + block.name);
- }
- }
- }
- }
-
- /**
- * @inheritDoc
- */
- override arcane function resolveDependencyFailure(resourceDependency:ResourceDependency):void
- {
- //not used - if a dependcy fails, the awaiting Texture or CubeTexture will never be finalized, and the default-bitmaps will be used.
- // this means, that if one Bitmap of a CubeTexture fails, the CubeTexture will have the DefaultTexture applied for all six Bitmaps.
- }
-
- /**
- * Resolve a dependency name
- *
- * @param resourceDependency The dependency to be resolved.
- */
- arcane override function resolveDependencyName(resourceDependency:ResourceDependency, asset:IAsset):String
- {
- var oldName:String = asset.name;
- if (asset) {
- var block:AWDBlock = _blocks[parseInt(resourceDependency.id)];
- // Reset name of texture to the one defined in the AWD file,
- // as opposed to whatever the image parser came up with.
- asset.resetAssetPath(block.name, null, true);
- }
- var newName:String = asset.name;
- asset.name = oldName;
- return newName;
- }
-
-
- /**
- * @inheritDoc
- */
- protected override function startParsing(frameLimit:Number):void
- {
- super.startParsing(frameLimit);
-
- _texture_users = {};
-
- _byteData = getByteData();
-
- _blocks = new Vector.<AWDBlock>();
- _blocks[0] = new AWDBlock();
- _blocks[0].data = null; // Zero address means null in AWD
-
- _version = []; // will contain 2 int (major-version, minor-version) for awd-version-check
-
- //parse header
- _byteData.endian = Endian.LITTLE_ENDIAN;
-
- // Parse header and decompress body if needed
- parseHeader();
- switch (_compression) {
- case DEFLATE:
- _body = new ByteArray();
- _byteData.readBytes(_body, 0, _byteData.bytesAvailable);
- _body.uncompress();
- break;
- case LZMA:
- _body = new ByteArray();
- _byteData.readBytes(_body, 0, _byteData.bytesAvailable);
- _body.uncompress(COMPRESSIONMODE_LZMA);
- break;
- case UNCOMPRESSED:
- _body = _byteData;
- break;
- }
-
- _body.endian = Endian.LITTLE_ENDIAN;
- }
-
- /**
- * @inheritDoc
- */
- protected override function proceedParsing():Boolean
- {
- while (_body.bytesAvailable > 0 && !parsingPaused && hasTime())
- parseNextBlock();
-
- // Return complete status
- if (_body.bytesAvailable == 0)
- return PARSING_DONE;
- else
- return MORE_TO_PARSE;
- }
-
- private function parseHeader():void
- {
- var flags:uint;
- var body_len:Number;
- _byteData.position = 3; // Skip magic string and parse version
- _version[0] = _byteData.readUnsignedByte();
- _version[1] = _byteData.readUnsignedByte();
-
- flags = _byteData.readUnsignedShort(); // Parse bit flags
- _streaming = bitFlags.test(flags, bitFlags.FLAG1);
- if ((_version[0] == 2) && (_version[1] == 1)) {
- _accuracyMatrix = bitFlags.test(flags, bitFlags.FLAG2);
- _accuracyGeo = bitFlags.test(flags, bitFlags.FLAG3);
- _accuracyProps = bitFlags.test(flags, bitFlags.FLAG4);
- }
- // if we set _accuracyOnBlocks, the precision-values are read from each block-header.
-
- // set storagePrecision types
- _geoNrType = FLOAT32;
- if (_accuracyGeo)
- _geoNrType = FLOAT64;
- _matrixNrType = FLOAT32;
- if (_accuracyMatrix)
- _matrixNrType = FLOAT64;
- _propsNrType = FLOAT32;
- if (_accuracyProps)
- _propsNrType = FLOAT64;
-
- _compression = _byteData.readUnsignedByte(); // compression
-
- if (_debug) {
- trace("Import AWDFile of version = " + _version[0] + " - " + _version[1]);
- trace("Global Settings = Compression = " + _compression + " | Streaming = " + _streaming + " | Matrix-Precision = " + _accuracyMatrix + " | Geometry-Precision = " + _accuracyGeo + " | Properties-Precision = " + _accuracyProps);
- }
-
- // Check file integrity
- body_len = _byteData.readUnsignedInt();
- if (!_streaming && body_len != _byteData.bytesAvailable)
- dieWithError('AWD2 body length does not match header integrity field');
- }
-
- private function parseNextBlock():void
- {
- var block:AWDBlock;
- var assetData:IAsset;
- var isParsed:Boolean;
- var ns:uint, type:uint, flags:uint, len:uint;
- _cur_block_id = _body.readUnsignedInt();
- ns = _body.readUnsignedByte();
- type = _body.readUnsignedByte();
- flags = _body.readUnsignedByte();
- len = _body.readUnsignedInt();
- var blockCompression:Boolean = bitFlags.test(flags, bitFlags.FLAG4);
- var blockCompressionLZMA:Boolean = bitFlags.test(flags, bitFlags.FLAG5);
- if (_accuracyOnBlocks) {
- _accuracyMatrix = bitFlags.test(flags, bitFlags.FLAG1);
- _accuracyGeo = bitFlags.test(flags, bitFlags.FLAG2);
- _accuracyProps = bitFlags.test(flags, bitFlags.FLAG3);
- _geoNrType = FLOAT32;
- if (_accuracyGeo)
- _geoNrType = FLOAT64;
- _matrixNrType = FLOAT32;
- if (_accuracyMatrix)
- _matrixNrType = FLOAT64;
- _propsNrType = FLOAT32;
- if (_accuracyProps)
- _propsNrType = FLOAT64;
- }
-
- var blockEndAll:uint = _body.position + len;
- if (len > _body.bytesAvailable) {
- dieWithError('AWD2 block length is bigger than the bytes that are available!');
- _body.position += _body.bytesAvailable;
- return;
- }
- _newBlockBytes = new ByteArray();
- _body.readBytes(_newBlockBytes, 0, len);
- if (blockCompression) {
- if (blockCompressionLZMA)
- _newBlockBytes.uncompress(COMPRESSIONMODE_LZMA);
- else
- _newBlockBytes.uncompress();
- }
- _newBlockBytes.endian = Endian.LITTLE_ENDIAN;
- _newBlockBytes.position = 0;
- block = new AWDBlock();
- block.len = _newBlockBytes.position + len;
- block.id = _cur_block_id;
-
- var blockEndBlock:uint = _newBlockBytes.position + len;
- if (blockCompression) {
- blockEndBlock = _newBlockBytes.position + _newBlockBytes.length;
- block.len = blockEndBlock;
- }
-
- if (_debug)
- trace("AWDBlock: ID = " + _cur_block_id + " | TypeID = " + type + " | Compression = " + blockCompression + " | Matrix-Precision = " + _accuracyMatrix + " | Geometry-Precision = " + _accuracyGeo + " | Properties-Precision = " + _accuracyProps);
-
- _blocks[_cur_block_id] = block;
- if ((_version[0] == 2) && (_version[1] == 1)) {
- switch (type) {
- case 11:
- parsePrimitves(_cur_block_id);
- isParsed = true;
- break;
- case 31:
- parseSkyBoxInstance(_cur_block_id);
- isParsed = true;
- break;
- case 41:
- parseLight(_cur_block_id);
- isParsed = true;
- break;
- case 42:
- parseCamera(_cur_block_id);
- isParsed = true;
- break;
- case 43:
- parseTextureProjector(_cur_block_id);
- isParsed = true;
- break;
- case 51:
- parseLightPicker(_cur_block_id);
- isParsed = true;
- break;
- case 81:
- parseMaterial_v1(_cur_block_id);
- isParsed = true;
- break;
- case 83:
- parseCubeTexture(_cur_block_id);
- isParsed = true;
- break;
- case 91:
- parseSharedMethodBlock(_cur_block_id);
- isParsed = true;
- break;
- case 92:
- parseShadowMethodBlock(_cur_block_id);
- isParsed = true;
- break;
- case 111:
- parseMeshPoseAnimation(_cur_block_id, true);
- isParsed = true;
- break;
- case 112:
- parseMeshPoseAnimation(_cur_block_id);
- isParsed = true;
- break;
- case 113:
- parseVertexAnimationSet(_cur_block_id);
- isParsed = true;
- break;
- case 122:
- parseAnimatorSet(_cur_block_id);
- isParsed = true;
- break;
- case 253:
- parseCommand(_cur_block_id);
- isParsed = true;
- break;
- }
- }
- if (isParsed == false) {
- switch (type) {
- case 1:
- parseTriangleGeometrieBlock(_cur_block_id);
- break;
- case 22:
- parseContainer(_cur_block_id);
- break;
- case 23:
- parseMeshInstance(_cur_block_id);
- break;
- case 81:
- parseMaterial(_cur_block_id);
- break;
- case 82:
- parseTexture(_cur_block_id);
- break;
- case 101:
- parseSkeleton(_cur_block_id);
- break;
- case 102:
- parseSkeletonPose(_cur_block_id);
- break;
- case 103:
- parseSkeletonAnimation(_cur_block_id);
- break;
- case 121:
- parseUVAnimation(_cur_block_id);
- break;
- case 254:
- parseNameSpace(_cur_block_id);
- break;
- case 255:
- parseMetaData(_cur_block_id);
- break;
- default:
- if (_debug)
- trace("AWDBlock: Unknown BlockType (BlockID = " + _cur_block_id + ") - Skip " + len + " bytes");
- _newBlockBytes.position += len;
- break;
- }
- }
- var msgCnt:uint = 0;
- if (_newBlockBytes.position == blockEndBlock) {
- if (_debug) {
- if (block.errorMessages) {
- while (msgCnt < block.errorMessages.length) {
- trace(" (!) Error: " + block.errorMessages[msgCnt] + " (!)");
- msgCnt++;
- }
- }
- }
- if (_debug)
- trace("\n");
- } else {
- if (_debug) {
- trace(" (!)(!)(!) Error while reading AWDBlock ID " + _cur_block_id + " = skip to next block");
- if (block.errorMessages) {
- while (msgCnt < block.errorMessages.length) {
- trace(" (!) Error: " + block.errorMessages[msgCnt] + " (!)");
- msgCnt++;
- }
- }
- }
- }
-
- _body.position = blockEndAll;
- _newBlockBytes = null;
-
- }
-
- //Block ID = 1
- private function parseTriangleGeometrieBlock(blockID:uint):void
- {
-
- var geom:Geometry = new Geometry();
-
- // Read name and sub count
- var name:String = parseVarStr();
- var num_subs:uint = _newBlockBytes.readUnsignedShort();
-
- // Read optional properties
- var props:AWDProperties = parseProperties({1:_geoNrType, 2:_geoNrType});
- var geoScaleU:Number = props.get(1, 1);
- var geoScaleV:Number = props.get(2, 1);
- var sub_geoms:Vector.<ISubGeometry> = new Vector.<ISubGeometry>;
- // Loop through sub meshes
- var subs_parsed:uint = 0;
- while (subs_parsed < num_subs) {
- var i:uint;
- var sm_len:uint, sm_end:uint;
- var w_indices:Vector.<Number>;
- var weights:Vector.<Number>;
-
- sm_len = _newBlockBytes.readUnsignedInt();
- sm_end = _newBlockBytes.position + sm_len;
-
- // Ignore for now
- var subProps:AWDProperties = parseProperties({1:_geoNrType, 2:_geoNrType});
- // Loop through data streams
- while (_newBlockBytes.position < sm_end) {
- var idx:uint = 0;
- var str_ftype:uint, str_type:uint, str_len:uint, str_end:uint;
-
- // Type, field type, length
- str_type = _newBlockBytes.readUnsignedByte();
- str_ftype = _newBlockBytes.readUnsignedByte();
- str_len = _newBlockBytes.readUnsignedInt();
- str_end = _newBlockBytes.position + str_len;
-
- var x:Number, y:Number, z:Number;
-
- if (str_type == 1) {
- var verts:Vector.<Number> = new Vector.<Number>();
- while (_newBlockBytes.position < str_end) {
- // TODO: Respect stream field type
- x = readNumber(_accuracyGeo);
- y = readNumber(_accuracyGeo);
- z = readNumber(_accuracyGeo);
-
- verts[idx++] = x;
- verts[idx++] = y;
- verts[idx++] = z;
- }
- } else if (str_type == 2) {
- var indices:Vector.<uint> = new Vector.<uint>();
- while (_newBlockBytes.position < str_end) {
- // TODO: Respect stream field type
- indices[idx++] = _newBlockBytes.readUnsignedShort();
- }
- } else if (str_type == 3) {
- var uvs:Vector.<Number> = new Vector.<Number>();
- while (_newBlockBytes.position < str_end)
- uvs[idx++] = readNumber(_accuracyGeo);
- } else if (str_type == 4) {
- var normals:Vector.<Number> = new Vector.<Number>();
- while (_newBlockBytes.position < str_end)
- normals[idx++] = readNumber(_accuracyGeo);
- } else if (str_type == 6) {
- w_indices = new Vector.<Number>();
- while (_newBlockBytes.position < str_end)
- w_indices[idx++] = _newBlockBytes.readUnsignedShort()*3; // TODO: Respect stream field type
- } else if (str_type == 7) {
- weights = new Vector.<Number>();
- while (_newBlockBytes.position < str_end)
- weights[idx++] = readNumber(_accuracyGeo);
- } else
- _newBlockBytes.position = str_end;
- }
- parseUserAttributes(); // Ignore sub-mesh attributes for now
-
- sub_geoms = GeomUtil.fromVectors(verts, indices, uvs, normals, null, weights, w_indices);
-
- var scaleU:Number = subProps.get(1, 1);
- var scaleV:Number = subProps.get(2, 1);
- var setSubUVs:Boolean = false; //this should remain false atm, because in AwayBuilder the uv is only scaled by the geometry
- if ((geoScaleU != scaleU) || (geoScaleV != scaleV)) {
- trace("set sub uvs");
- setSubUVs = true;
- scaleU = geoScaleU/scaleU;
- scaleV = geoScaleV/scaleV;
- }
- for (i = 0; i < sub_geoms.length; i++) {
- if (setSubUVs)
- sub_geoms[i].scaleUV(scaleU, scaleV);
- geom.addSubGeometry(sub_geoms[i]);
- // TODO: Somehow map in-sub to out-sub indices to enable look-up
- // when creating meshes (and their material assignments.)
- }
- subs_parsed++;
- }
- if ((geoScaleU != 1) || (geoScaleV != 1))
- geom.scaleUV(geoScaleU, geoScaleV);
- parseUserAttributes();
- finalizeAsset(geom, name);
- _blocks[blockID].data = geom;
-
- if (_debug)
- trace("Parsed a TriangleGeometry: Name = " + name + "| SubGeometries = " + sub_geoms.length);
-
- }
-
- //Block ID = 11
- private function parsePrimitves(blockID:uint):void
- {
- var name:String;
- var geom:Geometry;
- var primType:uint;
- var subs_parsed:uint;
- var props:AWDProperties;
- var bsm:Matrix3D;
-
- // Read name and sub count
- name = parseVarStr();
- primType = _newBlockBytes.readUnsignedByte();
- props = parseProperties({101:_geoNrType, 102:_geoNrType, 103:_geoNrType, 110:_geoNrType, 111:_geoNrType, 301:UINT16, 302:UINT16, 303:UINT16, 701:BOOL, 702:BOOL, 703:BOOL, 704:BOOL});
-
- var primitveTypes:Array = ["Unsupported Type-ID", "PlaneGeometry", "CubeGeometry", "SphereGeometry", "CylinderGeometry", "ConeGeometry", "CapsuleGeometry", "TorusGeometry"]
- switch (primType) {
- // to do, not all properties are set on all primitives
- case 1:
- geom = new PlaneGeometry(props.get(101, 100), props.get(102, 100), props.get(301, 1), props.get(302, 1), props.get(701, true), props.get(702, false));
- break;
- case 2:
- geom = new CubeGeometry(props.get(101, 100), props.get(102, 100), props.get(103, 100), props.get(301, 1), props.get(302, 1), props.get(303, 1), props.get(701, true));
- break;
- case 3:
- geom = new SphereGeometry(props.get(101, 50), props.get(301, 16), props.get(302, 12), props.get(701, true));
- break;
- case 4:
- geom = new CylinderGeometry(props.get(101, 50), props.get(102, 50), props.get(103, 100), props.get(301, 16), props.get(302, 1), true, true, true); // bool701, bool702, bool703, bool704);
- if (!props.get(701, true))
- CylinderGeometry(geom).topClosed = false;
- if (!props.get(702, true))
- CylinderGeometry(geom).bottomClosed = false;
- if (!props.get(703, true))
- CylinderGeometry(geom).yUp = false;
-
- break;
- case 5:
- geom = new ConeGeometry(props.get(101, 50), props.get(102, 100), props.get(301, 16), props.get(302, 1), props.get(701, true), props.get(702, true));
- break;
- case 6:
- geom = new CapsuleGeometry(props.get(101, 50), props.get(102, 100), props.get(301, 16), props.get(302, 15), props.get(701, true));
- break;
- case 7:
- geom = new TorusGeometry(props.get(101, 50), props.get(102, 50), props.get(301, 16), props.get(302, 8), props.get(701, true));
- break;
- default:
- geom = new Geometry();
- trace("ERROR: UNSUPPORTED PRIMITIVE_TYPE");
- break;
- }
- if ((props.get(110, 1) != 1) || (props.get(111, 1) != 1)) {
- geom.subGeometries;
- geom.scaleUV(props.get(110, 1), props.get(111, 1));
- }
- parseUserAttributes();
- geom.name = name;
- finalizeAsset(geom, name);
- _blocks[blockID].data = geom;
- if (_debug) {
- if ((primType < 0) || (primType > 7))
- primType = 0;
- trace("Parsed a Primivite: Name = " + name + "| type = " + primitveTypes[primType]);
- }
- }
-
- // Block ID = 22
- private function parseContainer(blockID:uint):void
- {
- var name:String;
- var par_id:uint;
- var mtx:Matrix3D;
- var ctr:ObjectContainer3D;
- var parent:ObjectContainer3D;
-
- par_id = _newBlockBytes.readUnsignedInt();
- mtx = parseMatrix3D();
- name = parseVarStr();
- var parentName:String = "Root (TopLevel)";
- ctr = new ObjectContainer3D();
- ctr.transform = mtx;
- var returnedArray:Array = getAssetByID(par_id, [AssetType.CONTAINER, AssetType.LIGHT, AssetType.MESH, AssetType.ENTITY, AssetType.SEGMENT_SET])
- if (returnedArray[0]) {
- ObjectContainer3D(returnedArray[1]).addChild(ctr);
- parentName = ObjectContainer3D(returnedArray[1]).name;
- } else if (par_id > 0)
- _blocks[blockID].addError("Could not find a parent for this ObjectContainer3D");
-
- // in AWD version 2.1 we read the Container properties
- if ((_version[0] == 2) && (_version[1] == 1)) {
- var props:Object = parseProperties({1:_matrixNrType, 2:_matrixNrType, 3:_matrixNrType, 4:UINT8});
- ctr.pivotPoint = new Vector3D(props.get(1, 0), props.get(2, 0), props.get(3, 0));
- }
- // in other versions we do not read the Container properties
- else
- parseProperties(null);
- // the extraProperties should only be set for AWD2.1-Files, but is read for both versions
- ctr.extra = parseUserAttributes();
- finalizeAsset(ctr, name);
- _blocks[blockID].data = ctr;
- if (_debug)
- trace("Parsed a Container: Name = '" + name + "' | Parent-Name = " + parentName);
- }
-
- // Block ID = 23
- private function parseMeshInstance(blockID:uint):void
- {
- var num_materials:uint;
- var materials_parsed:uint;
- var parent:ObjectContainer3D;
-
- var par_id:uint = _newBlockBytes.readUnsignedInt();
- var mtx:Matrix3D = parseMatrix3D();
- var name:String = parseVarStr();
- var parentName:String = "Root (TopLevel)";
- var data_id:uint = _newBlockBytes.readUnsignedInt();
- var geom:Geometry;
- var returnedArrayGeometry:Array = getAssetByID(data_id, [AssetType.GEOMETRY])
- if (returnedArrayGeometry[0])
- geom = returnedArrayGeometry[1] as Geometry;
- else {
- _blocks[blockID].addError("Could not find a Geometry for this Mesh. A empty Geometry is created!");
- geom = new Geometry();
- }
-
- _blocks[blockID].geoID = data_id;
- var materials:Vector.<MaterialBase> = new Vector.<MaterialBase>();
- num_materials = _newBlockBytes.readUnsignedShort();
- var materialNames:Array = new Array();
- materials_parsed = 0;
- var returnedArrayMaterial:Array;
- while (materials_parsed < num_materials) {
- var mat_id:uint;
- mat_id = _newBlockBytes.readUnsignedInt();
- returnedArrayMaterial = getAssetByID(mat_id, [AssetType.MATERIAL])
- if ((!returnedArrayMaterial[0]) && (mat_id > 0))
- _blocks[blockID].addError("Could not find Material Nr " + materials_parsed + " (ID = " + mat_id + " ) for this Mesh");
- materials.push(returnedArrayMaterial[1] as MaterialBase);
- materialNames.push(MaterialBase(returnedArrayMaterial[1]).name);
-
- materials_parsed++;
- }
-
- var mesh:Mesh = new Mesh(geom, null);
- mesh.transform = mtx;
-
- var returnedArrayParent:Array = getAssetByID(par_id, [AssetType.CONTAINER, AssetType.LIGHT, AssetType.MESH, AssetType.ENTITY, AssetType.SEGMENT_SET])
- if (returnedArrayParent[0]) {
- ObjectContainer3D(returnedArrayParent[1]).addChild(mesh);
- parentName = ObjectContainer3D(returnedArrayParent[1]).name;
- } else if (par_id > 0)
- _blocks[blockID].addError("Could not find a parent for this Mesh");
-
- if (materials.length >= 1 && mesh.subMeshes.length == 1)
- mesh.material = materials[0];
- else if (materials.length > 1) {
- var i:uint;
- // Assign each sub-mesh in the mesh a material from the list. If more sub-meshes
- // than materials, repeat the last material for all remaining sub-meshes.
- for (i = 0; i < mesh.subMeshes.length; i++)
- mesh.subMeshes[i].material = materials[Math.min(materials.length - 1, i)];
- }
- if ((_version[0] == 2) && (_version[1] == 1)) {
- var props:Object = parseProperties({1:_matrixNrType, 2:_matrixNrType, 3:_matrixNrType, 4:UINT8, 5:BOOL});
- mesh.pivotPoint = new Vector3D(props.get(1, 0), props.get(2, 0), props.get(3, 0));
- mesh.castsShadows = props.get(5, true);
- } else
- parseProperties(null);
- mesh.extra = parseUserAttributes();
- finalizeAsset(mesh, name);
- _blocks[blockID].data = mesh;
- if (_debug)
- trace("Parsed a Mesh: Name = '" + name + "' | Parent-Name = " + parentName + "| Geometry-Name = " + geom.name + " | SubMeshes = " + mesh.subMeshes.length + " | Mat-Names = " + materialNames.toString());
-
- }
-
- //Block ID 31
- private function parseSkyBoxInstance(blockID:uint):void
- {
- var name:String = parseVarStr();
- var cubeTexAddr:uint = _newBlockBytes.readUnsignedInt();
-
- var returnedArrayCubeTex:Array = getAssetByID(cubeTexAddr, [AssetType.TEXTURE], "CubeTexture");
- if ((!returnedArrayCubeTex[0]) && (cubeTexAddr != 0))
- _blocks[blockID].addError("Could not find the Cubetexture (ID = " + cubeTexAddr + " ) for this SkyBox");
- var asset:SkyBox = new SkyBox(returnedArrayCubeTex[1] as BitmapCubeTexture);
-
- parseProperties(null)
- asset.extra = parseUserAttributes();
- finalizeAsset(asset, name);
- _blocks[blockID].data = asset;
- if (_debug)
- trace("Parsed a SkyBox: Name = '" + name + "' | CubeTexture-Name = " + BitmapCubeTexture(returnedArrayCubeTex[1]).name);
-
- }
-
- //Block ID = 41
- private function parseLight(blockID:uint):void
- {
- var light:LightBase;
- var newShadowMapper:ShadowMapperBase;
- var par_id:uint = _newBlockBytes.readUnsignedInt();
- var mtx:Matrix3D = parseMatrix3D();
- var name:String = parseVarStr();
- var lightType:uint = _newBlockBytes.readUnsignedByte();
- var props:AWDProperties = parseProperties({1:_propsNrType, 2:_propsNrType, 3:COLOR, 4:_propsNrType, 5:_propsNrType, 6:BOOL, 7:COLOR, 8:_propsNrType, 9:UINT8, 10:UINT8, 11:_propsNrType, 12:UINT16, 21:_matrixNrType, 22:_matrixNrType, 23:_matrixNrType});
- var shadowMapperType:uint = props.get(9, 0);
- var parentName:String = "Root (TopLevel)";
- var lightTypes:Array = ["Unsupported LightType", "PointLight", "DirectionalLight"];
- var shadowMapperTypes:Array = ["No ShadowMapper", "DirectionalShadowMapper", "NearDirectionalShadowMapper", "CascadeShadowMapper", "CubeMapShadowMapper"];
- if (lightType == 1) {
- light = new PointLight();
- PointLight(light).radius = props.get(1, 90000);
- PointLight(light).fallOff = props.get(2, 100000);
- if (shadowMapperType > 0) {
- if (shadowMapperType == 4)
- newShadowMapper = new CubeMapShadowMapper();
- }
- light.transform = mtx;
- }
- if (lightType == 2) {
- light = new DirectionalLight(props.get(21, 0), props.get(22, -1), props.get(23, 1));
- if (shadowMapperType > 0) {
- if (shadowMapperType == 1)
- newShadowMapper = new DirectionalShadowMapper();
- if (shadowMapperType == 2)
- newShadowMapper = new NearDirectionalShadowMapper(props.get(11, 0.5));
- if (shadowMapperType == 3)
- newShadowMapper = new CascadeShadowMapper(props.get(12, 3));
- }
- }
- if ((lightType != 2) && (lightType != 1)){
- _blocks[blockID].addError("Unsuported lighttype = "+lightType);
- return
-
- }
- light.color = props.get(3, 0xffffff);
- light.specular = props.get(4, 1.0);
- light.diffuse = props.get(5, 1.0);
- light.ambientColor = props.get(7, 0xffffff);
- light.ambient = props.get(8, 0.0);
- // if a shadowMapper has been created, adjust the depthMapSize if needed, assign to light and set castShadows to true
- if (newShadowMapper) {
- if (newShadowMapper is CubeMapShadowMapper) {
- if (props.get(10, 1) != 1)
- newShadowMapper.depthMapSize = _depthSizeDic[props.get(10, 1)];
- } else {
- if (props.get(10, 2) != 2)
- newShadowMapper.depthMapSize = _depthSizeDic[props.get(10, 2)];
- }
-
- light.shadowMapper = newShadowMapper;
- light.castsShadows = true;
- }
- if (par_id != 0) {
- var returnedArrayParent:Array = getAssetByID(par_id, [AssetType.CONTAINER, AssetType.LIGHT, AssetType.MESH, AssetType.ENTITY, AssetType.SEGMENT_SET])
- if (returnedArrayParent[0]) {
- ObjectContainer3D(returnedArrayParent[1]).addChild(light);
- parentName = ObjectContainer3D(returnedArrayParent[1]).name;
- } else
- _blocks[blockID].addError("Could not find a parent for this Light");
- }
-
- parseUserAttributes();
-
- finalizeAsset(light, name);
-
- _blocks[blockID].data = light;
- if (_debug)
- trace("Parsed a Light: Name = '" + name + "' | Type = " + lightTypes[lightType] + " | Parent-Name = " + parentName + " | ShadowMapper-Type = " + shadowMapperTypes[shadowMapperType]);
-
- }
-
- //Block ID = 43
- private function parseCamera(blockID:uint):void
- {
-
- var par_id:uint = _newBlockBytes.readUnsignedInt();
- var mtx:Matrix3D = parseMatrix3D();
- var name:String = parseVarStr();
- var parentName:String = "Root (TopLevel)";
- var lens:LensBase;
- _newBlockBytes.readUnsignedByte(); //set as active camera
- _newBlockBytes.readShort(); //lengthof lenses - not used yet
- var lenstype:uint = _newBlockBytes.readShort();
- var props:AWDProperties = parseProperties({101:_propsNrType, 102:_propsNrType, 103:_propsNrType, 104:_propsNrType});
- switch (lenstype) {
- case 5001:
- lens = new PerspectiveLens(props.get(101, 60));
- break;
- case 5002:
- lens = new OrthographicLens(props.get(101, 500));
- break;
- case 5003:
- lens = new OrthographicOffCenterLens(props.get(101, -400), props.get(102, 400), props.get(103, -300), props.get(104, 300));
- break;
- default:
- trace("unsupportedLenstype");
- return;
- }
- var camera:Camera3D = new Camera3D(lens);
- camera.transform = mtx;
- var returnedArrayParent:Array = getAssetByID(par_id, [AssetType.CONTAINER, AssetType.LIGHT, AssetType.MESH, AssetType.ENTITY, AssetType.SEGMENT_SET])
- if (returnedArrayParent[0]) {
- ObjectContainer3D(returnedArrayParent[1]).addChild(camera);
- parentName = ObjectContainer3D(returnedArrayParent[1]).name;
- } else if (par_id > 0)
- _blocks[blockID].addError("Could not find a parent for this Camera");
- camera.name = name;
- props = parseProperties({1:_matrixNrType, 2:_matrixNrType, 3:_matrixNrType, 4:UINT8, 101:_propsNrType, 102:_propsNrType});
- camera.pivotPoint = new Vector3D(props.get(1, 0), props.get(2, 0), props.get(3, 0));
- camera.lens.near = props.get(101, 20);
- camera.lens.far = props.get(102, 3000);
- camera.extra = parseUserAttributes();
- finalizeAsset(camera, name);
-
- _blocks[blockID].data = camera
- if (_debug)
- trace("Parsed a Camera: Name = '" + name + "' | Lenstype = " + lens + " | Parent-Name = " + parentName);
-
- }
-
- //Block ID = 43
- private function parseTextureProjector(blockID:uint):void
- {
-
- var par_id:uint = _newBlockBytes.readUnsignedInt();
- var mtx:Matrix3D = parseMatrix3D();
- var name:String = parseVarStr();
- var parentName:String = "Root (TopLevel)";
- var tex_id:uint = _newBlockBytes.readUnsignedInt();
- var returnedArrayGeometry:Array = getAssetByID(tex_id, [AssetType.TEXTURE])
- if ((!returnedArrayGeometry[0]) && (tex_id != 0))
- _blocks[blockID].addError("Could not find the Texture (ID = " + tex_id + " ( for this TextureProjector!");
- var textureProjector:TextureProjector = new TextureProjector(returnedArrayGeometry[1]);
- textureProjector.name = name;
- textureProjector.aspectRatio = _newBlockBytes.readFloat();
- textureProjector.fieldOfView = _newBlockBytes.readFloat();
- textureProjector.transform = mtx;
- var props:AWDProperties = parseProperties({1:_matrixNrType, 2:_matrixNrType, 3:_matrixNrType, 4:UINT8});
- textureProjector.pivotPoint = new Vector3D(props.get(1, 0), props.get(2, 0), props.get(3, 0));
- textureProjector.extra = parseUserAttributes();
- finalizeAsset(textureProjector, name);
-
- _blocks[blockID].data = textureProjector
- if (_debug)
- trace("Parsed a TextureProjector: Name = '" + name + "' | Texture-Name = " + Texture2DBase(returnedArrayGeometry[1]).name + " | Parent-Name = " + parentName);
-
- }
-
- //Block ID = 51
- private function parseLightPicker(blockID:uint):void
- {
- var name:String = parseVarStr();
- var numLights:uint = _newBlockBytes.readUnsignedShort();
- var lightsArray:Array = new Array();
- var k:int = 0;
- var lightID:int = 0;
- var returnedArrayLight:Array;
- var lightsArrayNames:Array = new Array();
- for (k = 0; k < numLights; k++) {
- lightID = _newBlockBytes.readUnsignedInt();
- returnedArrayLight = getAssetByID(lightID, [AssetType.LIGHT])
- if (returnedArrayLight[0]) {
- lightsArray.push(returnedArrayLight[1] as LightBase);
- lightsArrayNames.push(LightBase(returnedArrayLight[1]).name);
- } else
- _blocks[blockID].addError("Could not find a Light Nr " + k + " (ID = " + lightID + " ) for this LightPicker");
- }
- if (lightsArray.length == 0) {
- _blocks[blockID].addError("Could not create this LightPicker, cause no Light was found.");
- parseUserAttributes();
- return; //return without any more parsing for this block
- }
- var lightPick:LightPickerBase = new StaticLightPicker(lightsArray);
- lightPick.name = name;
- parseUserAttributes();
- finalizeAsset(lightPick, name);
-
- _blocks[blockID].data = lightPick
- if (_debug)
- trace("Parsed a StaticLightPicker: Name = '" + name + "' | Texture-Name = " + lightsArrayNames.toString());
- }
-
- //Block ID = 81
- private function parseMaterial(blockID:uint):void
- {
- // TODO: not used
- ////blockLength = block.len;
- var name:String;
- var type:uint;
- var props:AWDProperties;
- var mat:MaterialBase;
- var attributes:Object;
- var finalize:Boolean;
- var num_methods:uint;
- var methods_parsed:uint;
- var returnedArray:Array;
-
- name = parseVarStr();
- type = _newBlockBytes.readUnsignedByte();
- num_methods = _newBlockBytes.readUnsignedByte();
-
- // Read material numerical properties
- // (1=color, 2=bitmap url, 10=alpha, 11=alpha_blending, 12=alpha_threshold, 13=repeat)
- props = parseProperties({1:INT32, 2:BADDR, 10:_propsNrType, 11:BOOL, 12:_propsNrType, 13:BOOL});
-
- methods_parsed = 0;
- while (methods_parsed < num_methods) {
- var method_type:uint;
-
- method_type = _newBlockBytes.readUnsignedShort();
- parseProperties(null);
- parseUserAttributes();
- methods_parsed += 1;
- }
- var debugString:String = "";
- attributes = parseUserAttributes();
- if (type == 1) { // Color material
- debugString += "Parsed a ColorMaterial(SinglePass): Name = '" + name + "' | ";
- var color:uint;
- color = props.get(1, 0xcccccc);
- if (materialMode < 2)
- mat = new ColorMaterial(color, props.get(10, 1.0));
- else
- mat = new ColorMultiPassMaterial(color);
-
- } else if (type == 2) {
- var tex_addr:uint = props.get(2, 0);
- returnedArray = getAssetByID(tex_addr, [AssetType.TEXTURE])
- if ((!returnedArray[0]) && (tex_addr > 0))
- _blocks[blockID].addError("Could not find the DiffsueTexture (ID = " + tex_addr + " ) for this Material");
-
- if (materialMode < 2) {
- mat = new TextureMaterial(returnedArray[1]);
- TextureMaterial(mat).alphaBlending = props.get(11, false);
- TextureMaterial(mat).alpha = props.get(10, 1.0);
- debugString += "Parsed a TextureMaterial(SinglePass): Name = '" + name + "' | Texture-Name = " + mat.name;
- } else {
- mat = new TextureMultiPassMaterial(returnedArray[1]);
- debugString += "Parsed a TextureMaterial(MultipAss): Name = '" + name + "' | Texture-Name = " + mat.name;
- }
- }
-
- mat.extra = attributes;
- if (materialMode < 2)
- SinglePassMaterialBase(mat).alphaThreshold = props.get(12, 0.0);
- else
- MultiPassMaterialBase(mat).alphaThreshold = props.get(12, 0.0);
- mat.repeat = props.get(13, false);
-
- finalizeAsset(mat, name);
-
- _blocks[blockID].data = mat;
- if (_debug)
- trace(debugString);
- }
-
- // Block ID = 81 AWD2.1
- private function parseMaterial_v1(blockID:uint):void
- {
- var mat:MaterialBase;
- var normalTexture:Texture2DBase;
- var specTexture:Texture2DBase;
- var returnedArray:Array;
- var name:String = parseVarStr();
- var type:uint = _newBlockBytes.readUnsignedByte();
- var num_methods:uint = _newBlockBytes.readUnsignedByte();
- var props:AWDProperties = parseProperties({1:UINT32, 2:BADDR, 3:BADDR, 4:UINT8, 5:BOOL, 6:BOOL, 7:BOOL, 8:BOOL, 9:UINT8, 10:_propsNrType, 11:BOOL, 12:_propsNrType, 13:BOOL, 15:_propsNrType, 16:UINT32, 17:BADDR, 18:_propsNrType, 19:_propsNrType, 20:UINT32, 21:BADDR, 22:BADDR});
-
- var spezialType:uint = props.get(4, 0);
- var debugString:String = "";
- if (spezialType >= 2) { //this is no supported material
- _blocks[blockID].addError("Material-spezialType '" + spezialType + "' is not supported, can only be 0:singlePass, 1:MultiPass !");
- return;
- }
- if (materialMode == 1)
- spezialType = 0;
- else if (materialMode == 2)
- spezialType = 1;
- if (spezialType < 2) { //this is SinglePass or MultiPass
- if (type == 1) { // Color material
- var color:uint = color = props.get(1, 0xcccccc);
- if (spezialType == 1) { // MultiPassMaterial
- mat = new ColorMultiPassMaterial(color);
- debugString += "Parsed a ColorMaterial(MultiPass): Name = '" + name + "' | ";
- } else { // SinglePassMaterial
- mat = new ColorMaterial(color, props.get(10, 1.0));
- ColorMaterial(mat).alphaBlending = props.get(11, false);
- debugString += "Parsed a ColorMaterial(SinglePass): Name = '" + name + "' | ";
- }
- } else if (type == 2) { // texture material
-
- var tex_addr:uint = props.get(2, 0);
- returnedArray = getAssetByID(tex_addr, [AssetType.TEXTURE])
- if ((!returnedArray[0]) && (tex_addr > 0))
- _blocks[blockID].addError("Could not find the DiffsueTexture (ID = " + tex_addr + " ) for this TextureMaterial");
- var texture:Texture2DBase = returnedArray[1];
-
- var ambientTexture:Texture2DBase;
- var ambientTex_addr:uint = props.get(17, 0);
- returnedArray = getAssetByID(ambientTex_addr, [AssetType.TEXTURE])
- if ((!returnedArray[0]) && (ambientTex_addr != 0))
- _blocks[blockID].addError("Could not find the AmbientTexture (ID = " + ambientTex_addr + " ) for this TextureMaterial");
- if (returnedArray[0])
- ambientTexture = returnedArray[1]
- if (spezialType == 1) { // MultiPassMaterial
- mat = new TextureMultiPassMaterial(texture);
- debugString += "Parsed a TextureMaterial(MultiPass): Name = '" + name + "' | Texture-Name = " + texture.name;
- if (ambientTexture) {
- TextureMultiPassMaterial(mat).ambientTexture = ambientTexture;
- debugString += " | AmbientTexture-Name = " + ambientTexture.name;
- }
- } else { // SinglePassMaterial
- mat = new TextureMaterial(texture);
- debugString += "Parsed a TextureMaterial(SinglePass): Name = '" + name + "' | Texture-Name = " + texture.name;
- if (ambientTexture) {
- TextureMaterial(mat).ambientTexture = ambientTexture;
- debugString += " | AmbientTexture-Name = " + ambientTexture.name;
- }
- TextureMaterial(mat).alpha = props.get(10, 1.0);
- TextureMaterial(mat).alphaBlending = props.get(11, false);
- }
-
- }
- var normalTex_addr:uint = props.get(3, 0);
- returnedArray = getAssetByID(normalTex_addr, [AssetType.TEXTURE])
- if ((!returnedArray[0]) && (normalTex_addr != 0))
- _blocks[blockID].addError("Could not find the NormalTexture (ID = " + normalTex_addr + " ) for this TextureMaterial");
- if (returnedArray[0]) {
- normalTexture = returnedArray[1];
- debugString += " | NormalTexture-Name = " + normalTexture.name;
- }
-
- var specTex_addr:uint = props.get(21, 0);
- returnedArray = getAssetByID(specTex_addr, [AssetType.TEXTURE])
- if ((!returnedArray[0]) && (specTex_addr != 0))
- _blocks[blockID].addError("Could not find the SpecularTexture (ID = " + specTex_addr + " ) for this TextureMaterial");
- if (returnedArray[0]) {
- specTexture = returnedArray[1];
- debugString += " | SpecularTexture-Name = " + specTexture.name;
- }
- var lightPickerAddr:uint = props.get(22, 0);
- returnedArray = getAssetByID(lightPickerAddr, [AssetType.LIGHT_PICKER])
- if ((!returnedArray[0]) && (lightPickerAddr))
- _blocks[blockID].addError("Could not find the LightPicker (ID = " + lightPickerAddr + " ) for this TextureMaterial");
- else {
- MaterialBase(mat).lightPicker = returnedArray[1] as LightPickerBase;
- //debugString+=" | Lightpicker-Name = "+LightPickerBase(returnedArray[1]).name;
- }
-
- MaterialBase(mat).smooth = props.get(5, true);
- MaterialBase(mat).mipmap = props.get(6, true);
- MaterialBase(mat).bothSides = props.get(7, false);
- MaterialBase(mat).alphaPremultiplied = props.get(8, false);
- MaterialBase(mat).blendMode = blendModeDic[props.get(9, 0)];
- MaterialBase(mat).repeat = props.get(13, false);
-
- if (spezialType == 0) { // this is a SinglePassMaterial
- if (normalTexture)
- SinglePassMaterialBase(mat).normalMap = normalTexture;
- if (specTexture)
- SinglePassMaterialBase(mat).specularMap = specTexture;
- SinglePassMaterialBase(mat).alphaThreshold = props.get(12, 0.0);
- SinglePassMaterialBase(mat).ambient = props.get(15, 1.0);
- SinglePassMaterialBase(mat).ambientColor = props.get(16, 0xffffff);
- SinglePassMaterialBase(mat).specular = props.get(18, 1.0);
- SinglePassMaterialBase(mat).gloss = props.get(19, 50);
- SinglePassMaterialBase(mat).specularColor = props.get(20, 0xffffff);
- }
-
- else { // this is MultiPassMaterial
- if (normalTexture)
- MultiPassMaterialBase(mat).normalMap = normalTexture;
- if (specTexture)
- MultiPassMaterialBase(mat).specularMap = specTexture;
- MultiPassMaterialBase(mat).alphaThreshold = props.get(12, 0.0);
- MultiPassMaterialBase(mat).ambient = props.get(15, 1.0);
- MultiPassMaterialBase(mat).ambientColor = props.get(16, 0xffffff);
- MultiPassMaterialBase(mat).specular = props.get(18, 1.0);
- MultiPassMaterialBase(mat).gloss = props.get(19, 50);
- MultiPassMaterialBase(mat).specularColor = props.get(20, 0xffffff);
- }
-
- var methods_parsed:uint = 0;
- var targetID:uint;
- while (methods_parsed < num_methods) {
- var method_type:uint;
- method_type = _newBlockBytes.readUnsignedShort();
- props = parseProperties({1:BADDR, 2:BADDR, 3:BADDR, 101:_propsNrType, 102:_propsNrType, 103:_propsNrType, 201:UINT32, 202:UINT32, 301:UINT16, 302:UINT16, 401:UINT8, 402:UINT8, 601:COLOR, 602:COLOR, 701:BOOL, 702:BOOL, 801:MTX4x4});
- switch (method_type) {
- case 999: //wrapper-Methods that will load a previous parsed EffektMethod returned
- targetID = props.get(1, 0);
- returnedArray = getAssetByID(targetID, [AssetType.EFFECTS_METHOD]);
- if (!returnedArray[0])
- _blocks[blockID].addError("Could not find the EffectMethod (ID = " + targetID + " ) for this Material");
- else {
- if (spezialType == 0)
- SinglePassMaterialBase(mat).addMethod(returnedArray[1]);
- if (spezialType == 1)
- MultiPassMaterialBase(mat).addMethod(returnedArray[1]);
- debugString += " | EffectMethod-Name = " + EffectMethodBase(returnedArray[1]).name;
- }
- break;
- case 998: //wrapper-Methods that will load a previous parsed ShadowMapMethod
- targetID = props.get(1, 0);
- returnedArray = getAssetByID(targetID, [AssetType.SHADOW_MAP_METHOD]);
- if (!returnedArray[0])
- _blocks[blockID].addError("Could not find the ShadowMethod (ID = " + targetID + " ) for this Material");
- else {
- if (spezialType == 0)
- SinglePassMaterialBase(mat).shadowMethod = returnedArray[1];
- if (spezialType == 1)
- MultiPassMaterialBase(mat).shadowMethod = returnedArray[1];
- debugString += " | ShadowMethod-Name = " + ShadowMapMethodBase(returnedArray[1]).name;
- }
- break;
-
- case 1: //EnvMapAmbientMethod
- targetID = props.get(1, 0);
- returnedArray = getAssetByID(targetID, [AssetType.TEXTURE], "CubeTexture");
- if (!returnedArray[0])
- _blocks[blockID].addError("Could not find the EnvMap (ID = " + targetID + " ) for this EnvMapAmbientMethodMaterial");
- if (spezialType == 0)
- SinglePassMaterialBase(mat).ambientMethod = new EnvMapAmbientMethod(returnedArray[1]);
- if (spezialType == 1)
- MultiPassMaterialBase(mat).ambientMethod = new EnvMapAmbientMethod(returnedArray[1]);
- debugString += " | EnvMapAmbientMethod | EnvMap-Name =" + CubeTextureBase(returnedArray[1]).name;
- break;
-
- case 51: //DepthDiffuseMethod
- if (spezialType == 0)
- SinglePassMaterialBase(mat).diffuseMethod = new DepthDiffuseMethod();
- if (spezialType == 1)
- MultiPassMaterialBase(mat).diffuseMethod = new DepthDiffuseMethod();
- debugString += " | DepthDiffuseMethod";
- break;
- case 52: //GradientDiffuseMethod
- targetID = props.get(1, 0);
- returnedArray = getAssetByID(targetID, [AssetType.TEXTURE]);
- if (!returnedArray[0])
- _blocks[blockID].addError("Could not find the GradientDiffuseTexture (ID = " + targetID + " ) for this GradientDiffuseMethod");
- if (spezialType == 0)
- SinglePassMaterialBase(mat).diffuseMethod = new GradientDiffuseMethod(returnedArray[1]);
- if (spezialType == 1)
- MultiPassMaterialBase(mat).diffuseMethod = new GradientDiffuseMethod(returnedArray[1]);
- debugString += " | GradientDiffuseMethod | GradientDiffuseTexture-Name =" + Texture2DBase(returnedArray[1]).name;
- break;
- case 53: //WrapDiffuseMethod
- if (spezialType == 0)
- SinglePassMaterialBase(mat).diffuseMethod = new WrapDiffuseMethod(props.get(101, 5));
- if (spezialType == 1)
- MultiPassMaterialBase(mat).diffuseMethod = new WrapDiffuseMethod(props.get(101, 5));
- debugString += " | WrapDiffuseMethod";
- break;
- case 54: //LightMapDiffuseMethod
- targetID = props.get(1, 0);
- returnedArray = getAssetByID(targetID, [AssetType.TEXTURE]);
- if (!returnedArray[0])
- _blocks[blockID].addError("Could not find the LightMap (ID = " + targetID + " ) for this LightMapDiffuseMethod");
- if (spezialType == 0)
- SinglePassMaterialBase(mat).diffuseMethod = new LightMapDiffuseMethod(returnedArray[1], blendModeDic[props.get(401, 10)], false,…