/src/away3d/loaders/parsers/AWD2Parser.as
ActionScript | 2525 lines | 2175 code | 222 blank | 128 comment | 451 complexity | 91d69d19eb815a7708649ac5d008dfc6 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
1package away3d.loaders.parsers 2{ 3 import away3d.*; 4 import away3d.animators.*; 5 import away3d.animators.data.*; 6 import away3d.animators.nodes.*; 7 import away3d.cameras.*; 8 import away3d.cameras.lenses.*; 9 import away3d.containers.*; 10 import away3d.core.base.*; 11 import away3d.entities.*; 12 import away3d.library.assets.*; 13 import away3d.lights.*; 14 import away3d.lights.shadowmaps.*; 15 import away3d.loaders.misc.*; 16 import away3d.loaders.parsers.utils.*; 17 import away3d.materials.*; 18 import away3d.materials.lightpickers.*; 19 import away3d.materials.methods.*; 20 import away3d.materials.utils.*; 21 import away3d.primitives.*; 22 import away3d.textures.*; 23 import away3d.tools.utils.*; 24 25 import flash.display.*; 26 import flash.geom.*; 27 import flash.net.*; 28 import flash.utils.*; 29 30 use namespace arcane; 31 32 /** 33 * AWDParser provides a parser for the AWD data type. 34 */ 35 public class AWD2Parser extends ParserBase 36 { 37 //set to "true" to have some traces in the Console 38 private var _debug:Boolean = false; 39 private var _byteData:ByteArray; 40 private var _cur_block_id:uint; 41 private var _blocks:Vector.<AWDBlock>; 42 private var _newBlockBytes:ByteArray; 43 44 private var _version:Array; 45 private var _compression:uint; 46 47 private var _accuracyOnBlocks:Boolean; 48 49 private var _accuracyMatrix:Boolean; 50 private var _accuracyGeo:Boolean; 51 private var _accuracyProps:Boolean; 52 53 private var _matrixNrType:uint; 54 private var _geoNrType:uint; 55 private var _propsNrType:uint; 56 57 private var _streaming:Boolean; 58 59 private var _texture_users:Object; 60 61 private var _body:ByteArray; 62 63 private var _defaultTexture:BitmapTexture; 64 private var _defaultCubeTexture:BitmapCubeTexture; 65 private var _defaultBitmapMaterial:TextureMaterial; 66 private var _cubeTextures:Array; 67 68 public static const COMPRESSIONMODE_LZMA:String = "lzma"; 69 70 public static const UNCOMPRESSED:uint = 0; 71 public static const DEFLATE:uint = 1; 72 public static const LZMA:uint = 2; 73 74 public static const INT8:uint = 1; 75 public static const INT16:uint = 2; 76 public static const INT32:uint = 3; 77 public static const UINT8:uint = 4; 78 public static const UINT16:uint = 5; 79 public static const UINT32:uint = 6; 80 public static const FLOAT32:uint = 7; 81 public static const FLOAT64:uint = 8; 82 83 public static const BOOL:uint = 21; 84 public static const COLOR:uint = 22; 85 public static const BADDR:uint = 23; 86 87 public static const AWDSTRING:uint = 31; 88 public static const AWDBYTEARRAY:uint = 32; 89 90 public static const VECTOR2x1:uint = 41; 91 public static const VECTOR3x1:uint = 42; 92 public static const VECTOR4x1:uint = 43; 93 public static const MTX3x2:uint = 44; 94 public static const MTX3x3:uint = 45; 95 public static const MTX4x3:uint = 46; 96 public static const MTX4x4:uint = 47; 97 98 private var blendModeDic:Vector.<String>; 99 private var _depthSizeDic:Vector.<uint>; 100 101 /** 102 * Creates a new AWDParser object. 103 * @param uri The url or id of the data or file to be parsed. 104 * @param extra The holder for extra contextual data that the parser might need. 105 */ 106 public function AWD2Parser() 107 { 108 super(ParserDataFormat.BINARY); 109 110 blendModeDic = new Vector.<String>(); // used to translate ints to blendMode-strings 111 blendModeDic.push(BlendMode.NORMAL); 112 blendModeDic.push(BlendMode.ADD); 113 blendModeDic.push(BlendMode.ALPHA); 114 blendModeDic.push(BlendMode.DARKEN); 115 blendModeDic.push(BlendMode.DIFFERENCE); 116 blendModeDic.push(BlendMode.ERASE); 117 blendModeDic.push(BlendMode.HARDLIGHT); 118 blendModeDic.push(BlendMode.INVERT); 119 blendModeDic.push(BlendMode.LAYER); 120 blendModeDic.push(BlendMode.LIGHTEN); 121 blendModeDic.push(BlendMode.MULTIPLY); 122 blendModeDic.push(BlendMode.NORMAL); 123 blendModeDic.push(BlendMode.OVERLAY); 124 blendModeDic.push(BlendMode.SCREEN); 125 blendModeDic.push(BlendMode.SHADER); 126 blendModeDic.push(BlendMode.OVERLAY); 127 128 _depthSizeDic = new Vector.<uint>(); // used to translate ints to depthSize-values 129 _depthSizeDic.push(256); 130 _depthSizeDic.push(512); 131 _depthSizeDic.push(2048); 132 _depthSizeDic.push(1024); 133 } 134 135 /** 136 * Indicates whether or not a given file extension is supported by the parser. 137 * @param extension The file extension of a potential file to be parsed. 138 * @return Whether or not the given file type is supported. 139 */ 140 public static function supportsType(extension:String):Boolean 141 { 142 extension = extension.toLowerCase(); 143 return extension == "awd"; 144 } 145 146 /** 147 * Tests whether a data block can be parsed by the parser. 148 * @param data The data block to potentially be parsed. 149 * @return Whether or not the given data is supported. 150 */ 151 public static function supportsData(data:*):Boolean 152 { 153 return (ParserUtil.toString(data, 3) == 'AWD'); 154 } 155 /** 156 * @inheritDoc 157 */ 158 override arcane function resolveDependency(resourceDependency:ResourceDependency):void 159 { 160 // this function will be called when Dependency has finished loading. 161 // the Assets waiting for this Bitmap, can be Texture or CubeTexture. 162 // if the Bitmap is awaited by a CubeTexture, we need to check if its the last Bitmap of the CubeTexture, 163 // so we know if we have to finalize the Asset (CubeTexture) or not. 164 if (resourceDependency.assets.length == 1) { 165 var isCubeTextureArray:Array = resourceDependency.id.split("#"); 166 var ressourceID:String = isCubeTextureArray[0]; 167 var asset:TextureProxyBase; 168 var thisBitmapTexture:Texture2DBase; 169 var block:AWDBlock; 170 if (isCubeTextureArray.length == 1) { 171 asset = resourceDependency.assets[0] as Texture2DBase; 172 if (asset) { 173 var mat:TextureMaterial; 174 var users:Array; 175 block = _blocks[parseInt(resourceDependency.id)]; 176 block.data = asset; // Store finished asset 177 // Reset name of texture to the one defined in the AWD file, 178 // as opposed to whatever the image parser came up with. 179 asset.resetAssetPath(block.name, null, true); 180 block.name = asset.name; 181 // Finalize texture asset to dispatch texture event, which was 182 // previously suppressed while the dependency was loaded. 183 finalizeAsset(asset); 184 if (_debug) { 185 trace("Successfully loadet Bitmap for texture"); 186 trace("Parsed CubeTexture: Name = " + block.name); 187 } 188 } 189 } 190 if (isCubeTextureArray.length > 1) { 191 thisBitmapTexture = resourceDependency.assets[0] as BitmapTexture; 192 _cubeTextures[uint(isCubeTextureArray[1])] = BitmapTexture(thisBitmapTexture).bitmapData; 193 _texture_users[ressourceID].push(1); 194 195 if (_debug) 196 trace("Successfully loadet Bitmap " + _texture_users[ressourceID].length + " / 6 for Cubetexture"); 197 if (_texture_users[ressourceID].length == _cubeTextures.length) { 198 asset = new BitmapCubeTexture(_cubeTextures[0], _cubeTextures[1], _cubeTextures[2], _cubeTextures[3], _cubeTextures[4], _cubeTextures[5]); 199 block = _blocks[ressourceID]; 200 block.data = asset; // Store finished asset 201 // Reset name of texture to the one defined in the AWD file, 202 // as opposed to whatever the image parser came up with. 203 asset.resetAssetPath(block.name, null, true); 204 block.name = asset.name; 205 // Finalize texture asset to dispatch texture event, which was 206 // previously suppressed while the dependency was loaded. 207 finalizeAsset(asset); 208 if (_debug) 209 trace("Parsed CubeTexture: Name = " + block.name); 210 } 211 } 212 } 213 } 214 215 /** 216 * @inheritDoc 217 */ 218 override arcane function resolveDependencyFailure(resourceDependency:ResourceDependency):void 219 { 220 //not used - if a dependcy fails, the awaiting Texture or CubeTexture will never be finalized, and the default-bitmaps will be used. 221 // this means, that if one Bitmap of a CubeTexture fails, the CubeTexture will have the DefaultTexture applied for all six Bitmaps. 222 } 223 224 /** 225 * Resolve a dependency name 226 * 227 * @param resourceDependency The dependency to be resolved. 228 */ 229 arcane override function resolveDependencyName(resourceDependency:ResourceDependency, asset:IAsset):String 230 { 231 var oldName:String = asset.name; 232 if (asset) { 233 var block:AWDBlock = _blocks[parseInt(resourceDependency.id)]; 234 // Reset name of texture to the one defined in the AWD file, 235 // as opposed to whatever the image parser came up with. 236 asset.resetAssetPath(block.name, null, true); 237 } 238 var newName:String = asset.name; 239 asset.name = oldName; 240 return newName; 241 } 242 243 244 /** 245 * @inheritDoc 246 */ 247 protected override function startParsing(frameLimit:Number):void 248 { 249 super.startParsing(frameLimit); 250 251 _texture_users = {}; 252 253 _byteData = getByteData(); 254 255 _blocks = new Vector.<AWDBlock>(); 256 _blocks[0] = new AWDBlock(); 257 _blocks[0].data = null; // Zero address means null in AWD 258 259 _version = []; // will contain 2 int (major-version, minor-version) for awd-version-check 260 261 //parse header 262 _byteData.endian = Endian.LITTLE_ENDIAN; 263 264 // Parse header and decompress body if needed 265 parseHeader(); 266 switch (_compression) { 267 case DEFLATE: 268 _body = new ByteArray(); 269 _byteData.readBytes(_body, 0, _byteData.bytesAvailable); 270 _body.uncompress(); 271 break; 272 case LZMA: 273 _body = new ByteArray(); 274 _byteData.readBytes(_body, 0, _byteData.bytesAvailable); 275 _body.uncompress(COMPRESSIONMODE_LZMA); 276 break; 277 case UNCOMPRESSED: 278 _body = _byteData; 279 break; 280 } 281 282 _body.endian = Endian.LITTLE_ENDIAN; 283 } 284 285 /** 286 * @inheritDoc 287 */ 288 protected override function proceedParsing():Boolean 289 { 290 while (_body.bytesAvailable > 0 && !parsingPaused && hasTime()) 291 parseNextBlock(); 292 293 // Return complete status 294 if (_body.bytesAvailable == 0) 295 return PARSING_DONE; 296 else 297 return MORE_TO_PARSE; 298 } 299 300 private function parseHeader():void 301 { 302 var flags:uint; 303 var body_len:Number; 304 _byteData.position = 3; // Skip magic string and parse version 305 _version[0] = _byteData.readUnsignedByte(); 306 _version[1] = _byteData.readUnsignedByte(); 307 308 flags = _byteData.readUnsignedShort(); // Parse bit flags 309 _streaming = bitFlags.test(flags, bitFlags.FLAG1); 310 if ((_version[0] == 2) && (_version[1] == 1)) { 311 _accuracyMatrix = bitFlags.test(flags, bitFlags.FLAG2); 312 _accuracyGeo = bitFlags.test(flags, bitFlags.FLAG3); 313 _accuracyProps = bitFlags.test(flags, bitFlags.FLAG4); 314 } 315 // if we set _accuracyOnBlocks, the precision-values are read from each block-header. 316 317 // set storagePrecision types 318 _geoNrType = FLOAT32; 319 if (_accuracyGeo) 320 _geoNrType = FLOAT64; 321 _matrixNrType = FLOAT32; 322 if (_accuracyMatrix) 323 _matrixNrType = FLOAT64; 324 _propsNrType = FLOAT32; 325 if (_accuracyProps) 326 _propsNrType = FLOAT64; 327 328 _compression = _byteData.readUnsignedByte(); // compression 329 330 if (_debug) { 331 trace("Import AWDFile of version = " + _version[0] + " - " + _version[1]); 332 trace("Global Settings = Compression = " + _compression + " | Streaming = " + _streaming + " | Matrix-Precision = " + _accuracyMatrix + " | Geometry-Precision = " + _accuracyGeo + " | Properties-Precision = " + _accuracyProps); 333 } 334 335 // Check file integrity 336 body_len = _byteData.readUnsignedInt(); 337 if (!_streaming && body_len != _byteData.bytesAvailable) 338 dieWithError('AWD2 body length does not match header integrity field'); 339 } 340 341 private function parseNextBlock():void 342 { 343 var block:AWDBlock; 344 var assetData:IAsset; 345 var isParsed:Boolean; 346 var ns:uint, type:uint, flags:uint, len:uint; 347 _cur_block_id = _body.readUnsignedInt(); 348 ns = _body.readUnsignedByte(); 349 type = _body.readUnsignedByte(); 350 flags = _body.readUnsignedByte(); 351 len = _body.readUnsignedInt(); 352 var blockCompression:Boolean = bitFlags.test(flags, bitFlags.FLAG4); 353 var blockCompressionLZMA:Boolean = bitFlags.test(flags, bitFlags.FLAG5); 354 if (_accuracyOnBlocks) { 355 _accuracyMatrix = bitFlags.test(flags, bitFlags.FLAG1); 356 _accuracyGeo = bitFlags.test(flags, bitFlags.FLAG2); 357 _accuracyProps = bitFlags.test(flags, bitFlags.FLAG3); 358 _geoNrType = FLOAT32; 359 if (_accuracyGeo) 360 _geoNrType = FLOAT64; 361 _matrixNrType = FLOAT32; 362 if (_accuracyMatrix) 363 _matrixNrType = FLOAT64; 364 _propsNrType = FLOAT32; 365 if (_accuracyProps) 366 _propsNrType = FLOAT64; 367 } 368 369 var blockEndAll:uint = _body.position + len; 370 if (len > _body.bytesAvailable) { 371 dieWithError('AWD2 block length is bigger than the bytes that are available!'); 372 _body.position += _body.bytesAvailable; 373 return; 374 } 375 _newBlockBytes = new ByteArray(); 376 _body.readBytes(_newBlockBytes, 0, len); 377 if (blockCompression) { 378 if (blockCompressionLZMA) 379 _newBlockBytes.uncompress(COMPRESSIONMODE_LZMA); 380 else 381 _newBlockBytes.uncompress(); 382 } 383 _newBlockBytes.endian = Endian.LITTLE_ENDIAN; 384 _newBlockBytes.position = 0; 385 block = new AWDBlock(); 386 block.len = _newBlockBytes.position + len; 387 block.id = _cur_block_id; 388 389 var blockEndBlock:uint = _newBlockBytes.position + len; 390 if (blockCompression) { 391 blockEndBlock = _newBlockBytes.position + _newBlockBytes.length; 392 block.len = blockEndBlock; 393 } 394 395 if (_debug) 396 trace("AWDBlock: ID = " + _cur_block_id + " | TypeID = " + type + " | Compression = " + blockCompression + " | Matrix-Precision = " + _accuracyMatrix + " | Geometry-Precision = " + _accuracyGeo + " | Properties-Precision = " + _accuracyProps); 397 398 _blocks[_cur_block_id] = block; 399 if ((_version[0] == 2) && (_version[1] == 1)) { 400 switch (type) { 401 case 11: 402 parsePrimitves(_cur_block_id); 403 isParsed = true; 404 break; 405 case 31: 406 parseSkyBoxInstance(_cur_block_id); 407 isParsed = true; 408 break; 409 case 41: 410 parseLight(_cur_block_id); 411 isParsed = true; 412 break; 413 case 42: 414 parseCamera(_cur_block_id); 415 isParsed = true; 416 break; 417 case 43: 418 parseTextureProjector(_cur_block_id); 419 isParsed = true; 420 break; 421 case 51: 422 parseLightPicker(_cur_block_id); 423 isParsed = true; 424 break; 425 case 81: 426 parseMaterial_v1(_cur_block_id); 427 isParsed = true; 428 break; 429 case 83: 430 parseCubeTexture(_cur_block_id); 431 isParsed = true; 432 break; 433 case 91: 434 parseSharedMethodBlock(_cur_block_id); 435 isParsed = true; 436 break; 437 case 92: 438 parseShadowMethodBlock(_cur_block_id); 439 isParsed = true; 440 break; 441 case 111: 442 parseMeshPoseAnimation(_cur_block_id, true); 443 isParsed = true; 444 break; 445 case 112: 446 parseMeshPoseAnimation(_cur_block_id); 447 isParsed = true; 448 break; 449 case 113: 450 parseVertexAnimationSet(_cur_block_id); 451 isParsed = true; 452 break; 453 case 122: 454 parseAnimatorSet(_cur_block_id); 455 isParsed = true; 456 break; 457 case 253: 458 parseCommand(_cur_block_id); 459 isParsed = true; 460 break; 461 } 462 } 463 if (isParsed == false) { 464 switch (type) { 465 case 1: 466 parseTriangleGeometrieBlock(_cur_block_id); 467 break; 468 case 22: 469 parseContainer(_cur_block_id); 470 break; 471 case 23: 472 parseMeshInstance(_cur_block_id); 473 break; 474 case 81: 475 parseMaterial(_cur_block_id); 476 break; 477 case 82: 478 parseTexture(_cur_block_id); 479 break; 480 case 101: 481 parseSkeleton(_cur_block_id); 482 break; 483 case 102: 484 parseSkeletonPose(_cur_block_id); 485 break; 486 case 103: 487 parseSkeletonAnimation(_cur_block_id); 488 break; 489 case 121: 490 parseUVAnimation(_cur_block_id); 491 break; 492 case 254: 493 parseNameSpace(_cur_block_id); 494 break; 495 case 255: 496 parseMetaData(_cur_block_id); 497 break; 498 default: 499 if (_debug) 500 trace("AWDBlock: Unknown BlockType (BlockID = " + _cur_block_id + ") - Skip " + len + " bytes"); 501 _newBlockBytes.position += len; 502 break; 503 } 504 } 505 var msgCnt:uint = 0; 506 if (_newBlockBytes.position == blockEndBlock) { 507 if (_debug) { 508 if (block.errorMessages) { 509 while (msgCnt < block.errorMessages.length) { 510 trace(" (!) Error: " + block.errorMessages[msgCnt] + " (!)"); 511 msgCnt++; 512 } 513 } 514 } 515 if (_debug) 516 trace("\n"); 517 } else { 518 if (_debug) { 519 trace(" (!)(!)(!) Error while reading AWDBlock ID " + _cur_block_id + " = skip to next block"); 520 if (block.errorMessages) { 521 while (msgCnt < block.errorMessages.length) { 522 trace(" (!) Error: " + block.errorMessages[msgCnt] + " (!)"); 523 msgCnt++; 524 } 525 } 526 } 527 } 528 529 _body.position = blockEndAll; 530 _newBlockBytes = null; 531 532 } 533 534 //Block ID = 1 535 private function parseTriangleGeometrieBlock(blockID:uint):void 536 { 537 538 var geom:Geometry = new Geometry(); 539 540 // Read name and sub count 541 var name:String = parseVarStr(); 542 var num_subs:uint = _newBlockBytes.readUnsignedShort(); 543 544 // Read optional properties 545 var props:AWDProperties = parseProperties({1:_geoNrType, 2:_geoNrType}); 546 var geoScaleU:Number = props.get(1, 1); 547 var geoScaleV:Number = props.get(2, 1); 548 var sub_geoms:Vector.<ISubGeometry> = new Vector.<ISubGeometry>; 549 // Loop through sub meshes 550 var subs_parsed:uint = 0; 551 while (subs_parsed < num_subs) { 552 var i:uint; 553 var sm_len:uint, sm_end:uint; 554 var w_indices:Vector.<Number>; 555 var weights:Vector.<Number>; 556 557 sm_len = _newBlockBytes.readUnsignedInt(); 558 sm_end = _newBlockBytes.position + sm_len; 559 560 // Ignore for now 561 var subProps:AWDProperties = parseProperties({1:_geoNrType, 2:_geoNrType}); 562 // Loop through data streams 563 while (_newBlockBytes.position < sm_end) { 564 var idx:uint = 0; 565 var str_ftype:uint, str_type:uint, str_len:uint, str_end:uint; 566 567 // Type, field type, length 568 str_type = _newBlockBytes.readUnsignedByte(); 569 str_ftype = _newBlockBytes.readUnsignedByte(); 570 str_len = _newBlockBytes.readUnsignedInt(); 571 str_end = _newBlockBytes.position + str_len; 572 573 var x:Number, y:Number, z:Number; 574 575 if (str_type == 1) { 576 var verts:Vector.<Number> = new Vector.<Number>(); 577 while (_newBlockBytes.position < str_end) { 578 // TODO: Respect stream field type 579 x = readNumber(_accuracyGeo); 580 y = readNumber(_accuracyGeo); 581 z = readNumber(_accuracyGeo); 582 583 verts[idx++] = x; 584 verts[idx++] = y; 585 verts[idx++] = z; 586 } 587 } else if (str_type == 2) { 588 var indices:Vector.<uint> = new Vector.<uint>(); 589 while (_newBlockBytes.position < str_end) { 590 // TODO: Respect stream field type 591 indices[idx++] = _newBlockBytes.readUnsignedShort(); 592 } 593 } else if (str_type == 3) { 594 var uvs:Vector.<Number> = new Vector.<Number>(); 595 while (_newBlockBytes.position < str_end) 596 uvs[idx++] = readNumber(_accuracyGeo); 597 } else if (str_type == 4) { 598 var normals:Vector.<Number> = new Vector.<Number>(); 599 while (_newBlockBytes.position < str_end) 600 normals[idx++] = readNumber(_accuracyGeo); 601 } else if (str_type == 6) { 602 w_indices = new Vector.<Number>(); 603 while (_newBlockBytes.position < str_end) 604 w_indices[idx++] = _newBlockBytes.readUnsignedShort()*3; // TODO: Respect stream field type 605 } else if (str_type == 7) { 606 weights = new Vector.<Number>(); 607 while (_newBlockBytes.position < str_end) 608 weights[idx++] = readNumber(_accuracyGeo); 609 } else 610 _newBlockBytes.position = str_end; 611 } 612 parseUserAttributes(); // Ignore sub-mesh attributes for now 613 614 sub_geoms = GeomUtil.fromVectors(verts, indices, uvs, normals, null, weights, w_indices); 615 616 var scaleU:Number = subProps.get(1, 1); 617 var scaleV:Number = subProps.get(2, 1); 618 var setSubUVs:Boolean = false; //this should remain false atm, because in AwayBuilder the uv is only scaled by the geometry 619 if ((geoScaleU != scaleU) || (geoScaleV != scaleV)) { 620 trace("set sub uvs"); 621 setSubUVs = true; 622 scaleU = geoScaleU/scaleU; 623 scaleV = geoScaleV/scaleV; 624 } 625 for (i = 0; i < sub_geoms.length; i++) { 626 if (setSubUVs) 627 sub_geoms[i].scaleUV(scaleU, scaleV); 628 geom.addSubGeometry(sub_geoms[i]); 629 // TODO: Somehow map in-sub to out-sub indices to enable look-up 630 // when creating meshes (and their material assignments.) 631 } 632 subs_parsed++; 633 } 634 if ((geoScaleU != 1) || (geoScaleV != 1)) 635 geom.scaleUV(geoScaleU, geoScaleV); 636 parseUserAttributes(); 637 finalizeAsset(geom, name); 638 _blocks[blockID].data = geom; 639 640 if (_debug) 641 trace("Parsed a TriangleGeometry: Name = " + name + "| SubGeometries = " + sub_geoms.length); 642 643 } 644 645 //Block ID = 11 646 private function parsePrimitves(blockID:uint):void 647 { 648 var name:String; 649 var geom:Geometry; 650 var primType:uint; 651 var subs_parsed:uint; 652 var props:AWDProperties; 653 var bsm:Matrix3D; 654 655 // Read name and sub count 656 name = parseVarStr(); 657 primType = _newBlockBytes.readUnsignedByte(); 658 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}); 659 660 var primitveTypes:Array = ["Unsupported Type-ID", "PlaneGeometry", "CubeGeometry", "SphereGeometry", "CylinderGeometry", "ConeGeometry", "CapsuleGeometry", "TorusGeometry"] 661 switch (primType) { 662 // to do, not all properties are set on all primitives 663 case 1: 664 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)); 665 break; 666 case 2: 667 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)); 668 break; 669 case 3: 670 geom = new SphereGeometry(props.get(101, 50), props.get(301, 16), props.get(302, 12), props.get(701, true)); 671 break; 672 case 4: 673 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); 674 if (!props.get(701, true)) 675 CylinderGeometry(geom).topClosed = false; 676 if (!props.get(702, true)) 677 CylinderGeometry(geom).bottomClosed = false; 678 if (!props.get(703, true)) 679 CylinderGeometry(geom).yUp = false; 680 681 break; 682 case 5: 683 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)); 684 break; 685 case 6: 686 geom = new CapsuleGeometry(props.get(101, 50), props.get(102, 100), props.get(301, 16), props.get(302, 15), props.get(701, true)); 687 break; 688 case 7: 689 geom = new TorusGeometry(props.get(101, 50), props.get(102, 50), props.get(301, 16), props.get(302, 8), props.get(701, true)); 690 break; 691 default: 692 geom = new Geometry(); 693 trace("ERROR: UNSUPPORTED PRIMITIVE_TYPE"); 694 break; 695 } 696 if ((props.get(110, 1) != 1) || (props.get(111, 1) != 1)) { 697 geom.subGeometries; 698 geom.scaleUV(props.get(110, 1), props.get(111, 1)); 699 } 700 parseUserAttributes(); 701 geom.name = name; 702 finalizeAsset(geom, name); 703 _blocks[blockID].data = geom; 704 if (_debug) { 705 if ((primType < 0) || (primType > 7)) 706 primType = 0; 707 trace("Parsed a Primivite: Name = " + name + "| type = " + primitveTypes[primType]); 708 } 709 } 710 711 // Block ID = 22 712 private function parseContainer(blockID:uint):void 713 { 714 var name:String; 715 var par_id:uint; 716 var mtx:Matrix3D; 717 var ctr:ObjectContainer3D; 718 var parent:ObjectContainer3D; 719 720 par_id = _newBlockBytes.readUnsignedInt(); 721 mtx = parseMatrix3D(); 722 name = parseVarStr(); 723 var parentName:String = "Root (TopLevel)"; 724 ctr = new ObjectContainer3D(); 725 ctr.transform = mtx; 726 var returnedArray:Array = getAssetByID(par_id, [AssetType.CONTAINER, AssetType.LIGHT, AssetType.MESH, AssetType.ENTITY, AssetType.SEGMENT_SET]) 727 if (returnedArray[0]) { 728 ObjectContainer3D(returnedArray[1]).addChild(ctr); 729 parentName = ObjectContainer3D(returnedArray[1]).name; 730 } else if (par_id > 0) 731 _blocks[blockID].addError("Could not find a parent for this ObjectContainer3D"); 732 733 // in AWD version 2.1 we read the Container properties 734 if ((_version[0] == 2) && (_version[1] == 1)) { 735 var props:Object = parseProperties({1:_matrixNrType, 2:_matrixNrType, 3:_matrixNrType, 4:UINT8}); 736 ctr.pivotPoint = new Vector3D(props.get(1, 0), props.get(2, 0), props.get(3, 0)); 737 } 738 // in other versions we do not read the Container properties 739 else 740 parseProperties(null); 741 // the extraProperties should only be set for AWD2.1-Files, but is read for both versions 742 ctr.extra = parseUserAttributes(); 743 finalizeAsset(ctr, name); 744 _blocks[blockID].data = ctr; 745 if (_debug) 746 trace("Parsed a Container: Name = '" + name + "' | Parent-Name = " + parentName); 747 } 748 749 // Block ID = 23 750 private function parseMeshInstance(blockID:uint):void 751 { 752 var num_materials:uint; 753 var materials_parsed:uint; 754 var parent:ObjectContainer3D; 755 756 var par_id:uint = _newBlockBytes.readUnsignedInt(); 757 var mtx:Matrix3D = parseMatrix3D(); 758 var name:String = parseVarStr(); 759 var parentName:String = "Root (TopLevel)"; 760 var data_id:uint = _newBlockBytes.readUnsignedInt(); 761 var geom:Geometry; 762 var returnedArrayGeometry:Array = getAssetByID(data_id, [AssetType.GEOMETRY]) 763 if (returnedArrayGeometry[0]) 764 geom = returnedArrayGeometry[1] as Geometry; 765 else { 766 _blocks[blockID].addError("Could not find a Geometry for this Mesh. A empty Geometry is created!"); 767 geom = new Geometry(); 768 } 769 770 _blocks[blockID].geoID = data_id; 771 var materials:Vector.<MaterialBase> = new Vector.<MaterialBase>(); 772 num_materials = _newBlockBytes.readUnsignedShort(); 773 var materialNames:Array = new Array(); 774 materials_parsed = 0; 775 var returnedArrayMaterial:Array; 776 while (materials_parsed < num_materials) { 777 var mat_id:uint; 778 mat_id = _newBlockBytes.readUnsignedInt(); 779 returnedArrayMaterial = getAssetByID(mat_id, [AssetType.MATERIAL]) 780 if ((!returnedArrayMaterial[0]) && (mat_id > 0)) 781 _blocks[blockID].addError("Could not find Material Nr " + materials_parsed + " (ID = " + mat_id + " ) for this Mesh"); 782 materials.push(returnedArrayMaterial[1] as MaterialBase); 783 materialNames.push(MaterialBase(returnedArrayMaterial[1]).name); 784 785 materials_parsed++; 786 } 787 788 var mesh:Mesh = new Mesh(geom, null); 789 mesh.transform = mtx; 790 791 var returnedArrayParent:Array = getAssetByID(par_id, [AssetType.CONTAINER, AssetType.LIGHT, AssetType.MESH, AssetType.ENTITY, AssetType.SEGMENT_SET]) 792 if (returnedArrayParent[0]) { 793 ObjectContainer3D(returnedArrayParent[1]).addChild(mesh); 794 parentName = ObjectContainer3D(returnedArrayParent[1]).name; 795 } else if (par_id > 0) 796 _blocks[blockID].addError("Could not find a parent for this Mesh"); 797 798 if (materials.length >= 1 && mesh.subMeshes.length == 1) 799 mesh.material = materials[0]; 800 else if (materials.length > 1) { 801 var i:uint; 802 // Assign each sub-mesh in the mesh a material from the list. If more sub-meshes 803 // than materials, repeat the last material for all remaining sub-meshes. 804 for (i = 0; i < mesh.subMeshes.length; i++) 805 mesh.subMeshes[i].material = materials[Math.min(materials.length - 1, i)]; 806 } 807 if ((_version[0] == 2) && (_version[1] == 1)) { 808 var props:Object = parseProperties({1:_matrixNrType, 2:_matrixNrType, 3:_matrixNrType, 4:UINT8, 5:BOOL}); 809 mesh.pivotPoint = new Vector3D(props.get(1, 0), props.get(2, 0), props.get(3, 0)); 810 mesh.castsShadows = props.get(5, true); 811 } else 812 parseProperties(null); 813 mesh.extra = parseUserAttributes(); 814 finalizeAsset(mesh, name); 815 _blocks[blockID].data = mesh; 816 if (_debug) 817 trace("Parsed a Mesh: Name = '" + name + "' | Parent-Name = " + parentName + "| Geometry-Name = " + geom.name + " | SubMeshes = " + mesh.subMeshes.length + " | Mat-Names = " + materialNames.toString()); 818 819 } 820 821 //Block ID 31 822 private function parseSkyBoxInstance(blockID:uint):void 823 { 824 var name:String = parseVarStr(); 825 var cubeTexAddr:uint = _newBlockBytes.readUnsignedInt(); 826 827 var returnedArrayCubeTex:Array = getAssetByID(cubeTexAddr, [AssetType.TEXTURE], "CubeTexture"); 828 if ((!returnedArrayCubeTex[0]) && (cubeTexAddr != 0)) 829 _blocks[blockID].addError("Could not find the Cubetexture (ID = " + cubeTexAddr + " ) for this SkyBox"); 830 var asset:SkyBox = new SkyBox(returnedArrayCubeTex[1] as BitmapCubeTexture); 831 832 parseProperties(null) 833 asset.extra = parseUserAttributes(); 834 finalizeAsset(asset, name); 835 _blocks[blockID].data = asset; 836 if (_debug) 837 trace("Parsed a SkyBox: Name = '" + name + "' | CubeTexture-Name = " + BitmapCubeTexture(returnedArrayCubeTex[1]).name); 838 839 } 840 841 //Block ID = 41 842 private function parseLight(blockID:uint):void 843 { 844 var light:LightBase; 845 var newShadowMapper:ShadowMapperBase; 846 var par_id:uint = _newBlockBytes.readUnsignedInt(); 847 var mtx:Matrix3D = parseMatrix3D(); 848 var name:String = parseVarStr(); 849 var lightType:uint = _newBlockBytes.readUnsignedByte(); 850 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}); 851 var shadowMapperType:uint = props.get(9, 0); 852 var parentName:String = "Root (TopLevel)"; 853 var lightTypes:Array = ["Unsupported LightType", "PointLight", "DirectionalLight"]; 854 var shadowMapperTypes:Array = ["No ShadowMapper", "DirectionalShadowMapper", "NearDirectionalShadowMapper", "CascadeShadowMapper", "CubeMapShadowMapper"]; 855 if (lightType == 1) { 856 light = new PointLight(); 857 PointLight(light).radius = props.get(1, 90000); 858 PointLight(light).fallOff = props.get(2, 100000); 859 if (shadowMapperType > 0) { 860 if (shadowMapperType == 4) 861 newShadowMapper = new CubeMapShadowMapper(); 862 } 863 light.transform = mtx; 864 } 865 if (lightType == 2) { 866 light = new DirectionalLight(props.get(21, 0), props.get(22, -1), props.get(23, 1)); 867 if (shadowMapperType > 0) { 868 if (shadowMapperType == 1) 869 newShadowMapper = new DirectionalShadowMapper(); 870 if (shadowMapperType == 2) 871 newShadowMapper = new NearDirectionalShadowMapper(props.get(11, 0.5)); 872 if (shadowMapperType == 3) 873 newShadowMapper = new CascadeShadowMapper(props.get(12, 3)); 874 } 875 } 876 if ((lightType != 2) && (lightType != 1)){ 877 _blocks[blockID].addError("Unsuported lighttype = "+lightType); 878 return 879 880 } 881 light.color = props.get(3, 0xffffff); 882 light.specular = props.get(4, 1.0); 883 light.diffuse = props.get(5, 1.0); 884 light.ambientColor = props.get(7, 0xffffff); 885 light.ambient = props.get(8, 0.0); 886 // if a shadowMapper has been created, adjust the depthMapSize if needed, assign to light and set castShadows to true 887 if (newShadowMapper) { 888 if (newShadowMapper is CubeMapShadowMapper) { 889 if (props.get(10, 1) != 1) 890 newShadowMapper.depthMapSize = _depthSizeDic[props.get(10, 1)]; 891 } else { 892 if (props.get(10, 2) != 2) 893 newShadowMapper.depthMapSize = _depthSizeDic[props.get(10, 2)]; 894 } 895 896 light.shadowMapper = newShadowMapper; 897 light.castsShadows = true; 898 } 899 if (par_id != 0) { 900 var returnedArrayParent:Array = getAssetByID(par_id, [AssetType.CONTAINER, AssetType.LIGHT, AssetType.MESH, AssetType.ENTITY, AssetType.SEGMENT_SET]) 901 if (returnedArrayParent[0]) { 902 ObjectContainer3D(returnedArrayParent[1]).addChild(light); 903 parentName = ObjectContainer3D(returnedArrayParent[1]).name; 904 } else 905 _blocks[blockID].addError("Could not find a parent for this Light"); 906 } 907 908 parseUserAttributes(); 909 910 finalizeAsset(light, name); 911 912 _blocks[blockID].data = light; 913 if (_debug) 914 trace("Parsed a Light: Name = '" + name + "' | Type = " + lightTypes[lightType] + " | Parent-Name = " + parentName + " | ShadowMapper-Type = " + shadowMapperTypes[shadowMapperType]); 915 916 } 917 918 //Block ID = 43 919 private function parseCamera(blockID:uint):void 920 { 921 922 var par_id:uint = _newBlockBytes.readUnsignedInt(); 923 var mtx:Matrix3D = parseMatrix3D(); 924 var name:String = parseVarStr(); 925 var parentName:String = "Root (TopLevel)"; 926 var lens:LensBase; 927 _newBlockBytes.readUnsignedByte(); //set as active camera 928 _newBlockBytes.readShort(); //lengthof lenses - not used yet 929 var lenstype:uint = _newBlockBytes.readShort(); 930 var props:AWDProperties = parseProperties({101:_propsNrType, 102:_propsNrType, 103:_propsNrType, 104:_propsNrType}); 931 switch (lenstype) { 932 case 5001: 933 lens = new PerspectiveLens(props.get(101, 60)); 934 break; 935 case 5002: 936 lens = new OrthographicLens(props.get(101, 500)); 937 break; 938 case 5003: 939 lens = new OrthographicOffCenterLens(props.get(101, -400), props.get(102, 400), props.get(103, -300), props.get(104, 300)); 940 break; 941 default: 942 trace("unsupportedLenstype"); 943 return; 944 } 945 var camera:Camera3D = new Camera3D(lens); 946 camera.transform = mtx; 947 var returnedArrayParent:Array = getAssetByID(par_id, [AssetType.CONTAINER, AssetType.LIGHT, AssetType.MESH, AssetType.ENTITY, AssetType.SEGMENT_SET]) 948 if (returnedArrayParent[0]) { 949 ObjectContainer3D(returnedArrayParent[1]).addChild(camera); 950 parentName = ObjectContainer3D(returnedArrayParent[1]).name; 951 } else if (par_id > 0) 952 _blocks[blockID].addError("Could not find a parent for this Camera"); 953 camera.name = name; 954 props = parseProperties({1:_matrixNrType, 2:_matrixNrType, 3:_matrixNrType, 4:UINT8, 101:_propsNrType, 102:_propsNrType}); 955 camera.pivotPoint = new Vector3D(props.get(1, 0), props.get(2, 0), props.get(3, 0)); 956 camera.lens.near = props.get(101, 20); 957 camera.lens.far = props.get(102, 3000); 958 camera.extra = parseUserAttributes(); 959 finalizeAsset(camera, name); 960 961 _blocks[blockID].data = camera 962 if (_debug) 963 trace("Parsed a Camera: Name = '" + name + "' | Lenstype = " + lens + " | Parent-Name = " + parentName); 964 965 } 966 967 //Block ID = 43 968 private function parseTextureProjector(blockID:uint):void 969 { 970 971 var par_id:uint = _newBlockBytes.readUnsignedInt(); 972 var mtx:Matrix3D = parseMatrix3D(); 973 var name:String = parseVarStr(); 974 var parentName:String = "Root (TopLevel)"; 975 var tex_id:uint = _newBlockBytes.readUnsignedInt(); 976 var returnedArrayGeometry:Array = getAssetByID(tex_id, [AssetType.TEXTURE]) 977 if ((!returnedArrayGeometry[0]) && (tex_id != 0)) 978 _blocks[blockID].addError("Could not find the Texture (ID = " + tex_id + " ( for this TextureProjector!"); 979 var textureProjector:TextureProjector = new TextureProjector(returnedArrayGeometry[1]); 980 textureProjector.name = name; 981 textureProjector.aspectRatio = _newBlockBytes.readFloat(); 982 textureProjector.fieldOfView = _newBlockBytes.readFloat(); 983 textureProjector.transform = mtx; 984 var props:AWDProperties = parseProperties({1:_matrixNrType, 2:_matrixNrType, 3:_matrixNrType, 4:UINT8}); 985 textureProjector.pivotPoint = new Vector3D(props.get(1, 0), props.get(2, 0), props.get(3, 0)); 986 textureProjector.extra = parseUserAttributes(); 987 finalizeAsset(textureProjector, name); 988 989 _blocks[blockID].data = textureProjector 990 if (_debug) 991 trace("Parsed a TextureProjector: Name = '" + name + "' | Texture-Name = " + Texture2DBase(returnedArrayGeometry[1]).name + " | Parent-Name = " + parentName); 992 993 } 994 995 //Block ID = 51 996 private function parseLightPicker(blockID:uint):void 997 { 998 var name:String = parseVarStr(); 999 var numLights:uint = _newBlockBytes.readUnsignedShort(); 1000 var lightsArray:Array = new Array(); 1001 var k:int = 0; 1002 var lightID:int = 0; 1003 var returnedArrayLight:Array; 1004 var lightsArrayNames:Array = new Array(); 1005 for (k = 0; k < numLights; k++) { 1006 lightID = _newBlockBytes.readUnsignedInt(); 1007 returnedArrayLight = getAssetByID(lightID, [AssetType.LIGHT]) 1008 if (returnedArrayLight[0]) { 1009 lightsArray.push(returnedArrayLight[1] as LightBase); 1010 lightsArrayNames.push(LightBase(returnedArrayLight[1]).name); 1011 } else 1012 _blocks[blockID].addError("Could not find a Light Nr " + k + " (ID = " + lightID + " ) for this LightPicker"); 1013 } 1014 if (lightsArray.length == 0) { 1015 _blocks[blockID].addError("Could not create this LightPicker, cause no Light was found."); 1016 parseUserAttributes(); 1017 return; //return without any more parsing for this block 1018 } 1019 var lightPick:LightPickerBase = new StaticLightPicker(lightsArray); 1020 lightPick.name = name; 1021 parseUserAttributes(); 1022 finalizeAsset(lightPick, name); 1023 1024 _blocks[blockID].data = lightPick 1025 if (_debug) 1026 trace("Parsed a StaticLightPicker: Name = '" + name + "' | Texture-Name = " + lightsArrayNames.toString()); 1027 } 1028 1029 //Block ID = 81 1030 private function parseMaterial(blockID:uint):void 1031 { 1032 // TODO: not used 1033 ////blockLength = block.len; 1034 var name:String; 1035 var type:uint; 1036 var props:AWDProperties; 1037 var mat:MaterialBase; 1038 var attributes:Object; 1039 var finalize:Boolean; 1040 var num_methods:uint; 1041 var methods_parsed:uint; 1042 var returnedArray:Array; 1043 1044 name = parseVarStr(); 1045 type = _newBlockBytes.readUnsignedByte(); 1046 num_methods = _newBlockBytes.readUnsignedByte(); 1047 1048 // Read material numerical properties 1049 // (1=color, 2=bitmap url, 10=alpha, 11=alpha_blending, 12=alpha_threshold, 13=repeat) 1050 props = parseProperties({1:INT32, 2:BADDR, 10:_propsNrType, 11:BOOL, 12:_propsNrType, 13:BOOL}); 1051 1052 methods_parsed = 0; 1053 while (methods_parsed < num_methods) { 1054 var method_type:uint; 1055 1056 method_type = _newBlockBytes.readUnsignedShort(); 1057 parseProperties(null); 1058 parseUserAttributes(); 1059 methods_parsed += 1; 1060 } 1061 var debugString:String = ""; 1062 attributes = parseUserAttributes(); 1063 if (type == 1) { // Color material 1064 debugString += "Parsed a ColorMaterial(SinglePass): Name = '" + name + "' | "; 1065 var color:uint; 1066 color = props.get(1, 0xcccccc); 1067 if (materialMode < 2) 1068 mat = new ColorMaterial(color, props.get(10, 1.0)); 1069 else 1070 mat = new ColorMultiPassMaterial(color); 1071 1072 } else if (type == 2) { 1073 var tex_addr:uint = props.get(2, 0); 1074 returnedArray = getAssetByID(tex_addr, [AssetType.TEXTURE]) 1075 if ((!returnedArray[0]) && (tex_addr > 0)) 1076 _blocks[blockID].addError("Could not find the DiffsueTexture (ID = " + tex_addr + " ) for this Material"); 1077 1078 if (materialMode < 2) { 1079 mat = new TextureMaterial(returnedArray[1]); 1080 TextureMaterial(mat).alphaBlending = props.get(11, false); 1081 TextureMaterial(mat).alpha = props.get(10, 1.0); 1082 debugString += "Parsed a TextureMaterial(SinglePass): Name = '" + name + "' | Texture-Name = " + mat.name; 1083 } else { 1084 mat = new TextureMultiPassMaterial(returnedArray[1]); 1085 debugString += "Parsed a TextureMaterial(MultipAss): Name = '" + name + "' | Texture-Name = " + mat.name; 1086 } 1087 } 1088 1089 mat.extra = attributes; 1090 if (materialMode < 2) 1091 SinglePassMaterialBase(mat).alphaThreshold = props.get(12, 0.0); 1092 else 1093 MultiPassMaterialBase(mat).alphaThreshold = props.get(12, 0.0); 1094 mat.repeat = props.get(13, false); 1095 1096 finalizeAsset(mat, name); 1097 1098 _blocks[blockID].data = mat; 1099 if (_debug) 1100 trace(debugString); 1101 } 1102 1103 // Block ID = 81 AWD2.1 1104 private function parseMaterial_v1(blockID:uint):void 1105 { 1106 var mat:MaterialBase; 1107 var normalTexture:Texture2DBase; 1108 var specTexture:Texture2DBase; 1109 var returnedArray:Array; 1110 var name:String = parseVarStr(); 1111 var type:uint = _newBlockBytes.readUnsignedByte(); 1112 var num_methods:uint = _newBlockBytes.readUnsignedByte(); 1113 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}); 1114 1115 var spezialType:uint = props.get(4, 0); 1116 var debugString:String = ""; 1117 if (spezialType >= 2) { //this is no supported material 1118 _blocks[blockID].addError("Material-spezialType '" + spezialType + "' is not supported, can only be 0:singlePass, 1:MultiPass !"); 1119 return; 1120 } 1121 if (materialMode == 1) 1122 spezialType = 0; 1123 else if (materialMode == 2) 1124 spezialType = 1; 1125 if (spezialType < 2) { //this is SinglePass or MultiPass 1126 if (type == 1) { // Color material 1127 var color:uint = color = props.get(1, 0xcccccc); 1128 if (spezialType == 1) { // MultiPassMaterial 1129 mat = new ColorMultiPassMaterial(color); 1130 debugString += "Parsed a ColorMaterial(MultiPass): Name = '" + name + "' | "; 1131 } else { // SinglePassMaterial 1132 mat = new ColorMaterial(color, props.get(10, 1.0)); 1133 ColorMaterial(mat).alphaBlending = props.get(11, false); 1134 debugString += "Parsed a ColorMaterial(SinglePass): Name = '" + name + "' | "; 1135 } 1136 } else if (type == 2) { // texture material 1137 1138 var tex_addr:uint = props.get(2, 0); 1139 returnedArray = getAssetByID(tex_addr, [AssetType.TEXTURE]) 1140 if ((!returnedArray[0]) && (tex_addr > 0)) 1141 _blocks[blockID].addError("Could not find the DiffsueTexture (ID = " + tex_addr + " ) for this TextureMaterial"); 1142 var texture:Texture2DBase = returnedArray[1]; 1143 1144 var ambientTexture:Texture2DBase; 1145 var ambientTex_addr:uint = props.get(17, 0); 1146 returnedArray = getAssetByID(ambientTex_addr, [AssetType.TEXTURE]) 1147 if ((!returnedArray[0]) && (ambientTex_addr != 0)) 1148 _blocks[blockID].addError("Could not find the AmbientTexture (ID = " + ambientTex_addr + " ) for this TextureMaterial"); 1149 if (returnedArray[0]) 1150 ambientTexture = returnedArray[1] 1151 if (spezialType == 1) { // MultiPassMaterial 1152 mat = new TextureMultiPassMaterial(texture); 1153 debugString += "Parsed a TextureMaterial(MultiPass): Name = '" + name + "' | Texture-Name = " + texture.name; 1154 if (ambientTexture) { 1155 TextureMultiPassMaterial(mat).ambientTexture = ambientTexture; 1156 debugString += " | AmbientTexture-Name = " + ambientTexture.name; 1157 } 1158 } else { // SinglePassMaterial 1159 mat = new TextureMaterial(texture); 1160 debugString += "Parsed a TextureMaterial(SinglePass): Name = '" + name + "' | Texture-Name = " + texture.name; 1161 if (ambientTexture) { 1162 TextureMaterial(mat).ambientTexture = ambientTexture; 1163 debugString += " | AmbientTexture-Name = " + ambientTexture.name; 1164 } 1165 TextureMaterial(mat).alpha = props.get(10, 1.0); 1166 TextureMaterial(mat).alphaBlending = props.get(11, false); 1167 } 1168 1169 } 1170 var normalTex_addr:uint = props.get(3, 0); 1171 returnedArray = getAssetByID(normalTex_addr, [AssetType.TEXTURE]) 1172 if ((!returnedArray[0]) && (normalTex_addr != 0)) 1173 _blocks[blockID].addError("Could not find the NormalTexture (ID = " + normalTex_addr + " ) for this TextureMaterial"); 1174 if (returnedArray[0]) { 1175 normalTexture = returnedArray[1]; 1176 debugString += " | NormalTexture-Name = " + normalTexture.name; 1177 } 1178 1179 var specTex_addr:uint = props.get(21, 0); 1180 returnedArray = getAssetByID(specTex_addr, [AssetType.TEXTURE]) 1181 if ((!returnedArray[0]) && (specTex_addr != 0)) 1182 _blocks[blockID].addError("Could not find the SpecularTexture (ID = " + specTex_addr + " ) for this TextureMaterial"); 1183 if (returnedArray[0]) { 1184 specTexture = returnedArray[1]; 1185 debugString += " | SpecularTexture-Name = " + specTexture.name; 1186 } 1187 var lightPickerAddr:uint = props.get(22, 0); 1188 returnedArray = getAssetByID(lightPickerAddr, [AssetType.LIGHT_PICKER]) 1189 if ((!returnedArray[0]) && (lightPickerAddr)) 1190 _blocks[blockID].addError("Could not find the LightPicker (ID = " + lightPickerAddr + " ) for this TextureMaterial"); 1191 else { 1192 MaterialBase(mat).lightPicker = returnedArray[1] as LightPickerBase; 1193 //debugString+=" | Lightpicker-Name = "+LightPickerBase(returnedArray[1]).name; 1194 } 1195 1196 MaterialBase(mat).smooth = props.get(5, true); 1197 MaterialBase(mat).mipmap = props.get(6, true); 1198 MaterialBase(mat).bothSides = props.get(7, false); 1199 MaterialBase(mat).alphaPremultiplied = props.get(8, false); 1200 MaterialBase(mat).blendMode = blendModeDic[props.get(9, 0)]; 1201 MaterialBase(mat).repeat = props.get(13, false); 1202 1203 if (spezialType == 0) { // this is a SinglePassMaterial 1204 if (normalTexture) 1205 SinglePassMaterialBase(mat).normalMap = normalTexture; 1206 if (specTexture) 1207 SinglePassMaterialBase(mat).specularMap = specTexture; 1208 SinglePassMaterialBase(mat).alphaThreshold = props.get(12, 0.0); 1209 SinglePassMaterialBase(mat).ambient = props.get(15, 1.0); 1210 SinglePassMaterialBase(mat).ambientColor = props.get(16, 0xffffff); 1211 SinglePassMaterialBase(mat).specular = props.get(18, 1.0); 1212 SinglePassMaterialBase(mat).gloss = props.get(19, 50); 1213 SinglePassMaterialBase(mat).specularColor = props.get(20, 0xffffff); 1214 } 1215 1216 else { // this is MultiPassMaterial 1217 if (normalTexture) 1218 MultiPassMaterialBase(mat).normalMap = normalTexture; 1219 if (specTexture) 1220 MultiPassMaterialBase(mat).specularMap = specTexture; 1221 MultiPassMaterialBase(mat).alphaThreshold = props.get(12, 0.0); 1222 MultiPassMaterialBase(mat).ambient = props.get(15, 1.0); 1223 MultiPassMaterialBase(mat).ambientColor = props.get(16, 0xffffff); 1224 MultiPassMaterialBase(mat).specular = props.get(18, 1.0); 1225 MultiPassMaterialBase(mat).gloss = props.get(19, 50); 1226 MultiPassMaterialBase(mat).specularColor = props.get(20, 0xffffff); 1227 } 1228 1229 var methods_parsed:uint = 0; 1230 var targetID:uint; 1231 while (methods_parsed < num_methods) { 1232 var method_type:uint; 1233 method_type = _newBlockBytes.readUnsignedShort(); 1234 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}); 1235 switch (method_type) { 1236 case 999: //wrapper-Methods that will load a previous parsed EffektMethod returned 1237 targetID = props.get(1, 0); 1238 returnedArray = getAssetByID(targetID, [AssetType.EFFECTS_METHOD]); 1239 if (!returnedArray[0]) 1240 _blocks[blockID].addError("Could not find the EffectMethod (ID = " + targetID + " ) for this Material"); 1241 else { 1242 if (spezialType == 0) 1243 SinglePassMaterialBase(mat).addMethod(returnedArray[1]); 1244 if (spezialType == 1) 1245 MultiPassMaterialBase(mat).addMethod(returnedArray[1]); 1246 debugString += " | EffectMethod-Name = " + EffectMethodBase(returnedArray[1]).name; 1247 } 1248 break; 1249 case 998: //wrapper-Methods that will load a previous parsed ShadowMapMethod 1250 targetID = props.get(1, 0); 1251 returnedArray = getAssetByID(targetID, [AssetType.SHADOW_MAP_METHOD]); 1252 if (!returnedArray[0]) 1253 _blocks[blockID].addError("Could not find the ShadowMethod (ID = " + targetID + " ) for this Material"); 1254 else { 1255 if (spezialType == 0) 1256 SinglePassMaterialBase(mat).shadowMethod = returnedArray[1]; 1257 if (spezialType == 1) 1258 MultiPassMaterialBase(mat).shadowMethod = returnedArray[1]; 1259 debugString += " | ShadowMethod-Name = " + ShadowMapMethodBase(returnedArray[1]).name; 1260 } 1261 break; 1262 1263 case 1: //EnvMapAmbientMethod 1264 targetID = props.get(1, 0); 1265 returnedArray = getAssetByID(targetID, [AssetType.TEXTURE], "CubeTexture"); 1266 if (!returnedArray[0]) 1267 _blocks[blockID].addError("Could not find the EnvMap (ID = " + targetID + " ) for this EnvMapAmbientMethodMaterial"); 1268 if (spezialType == 0) 1269 SinglePassMaterialBase(mat).ambientMethod = new EnvMapAmbientMethod(returnedArray[1]); 1270 if (spezialType == 1) 1271 MultiPassMaterialBase(mat).ambientMethod = new EnvMapAmbientMethod(returnedArray[1]); 1272 debugString += " | EnvMapAmbientMethod | EnvMap-Name =" + CubeTextureBase(returnedArray[1]).name; 1273 break; 1274 1275 case 51: //DepthDiffuseMethod 1276 if (spezialType == 0) 1277 SinglePassMaterialBase(mat).diffuseMethod = new DepthDiffuseMethod(); 1278 if (spezialType == 1) 1279 MultiPassMaterialBase(mat).diffuseMethod = new DepthDiffuseMethod(); 1280 debugString += " | DepthDiffuseMethod"; 1281 break; 1282 case 52: //GradientDiffuseMethod 1283 targetID = props.get(1, 0); 1284 returnedArray = getAssetByID(targetID, [AssetType.TEXTURE]); 1285 if (!returnedArray[0]) 1286 _blocks[blockID].addError("Could not find the GradientDiffuseTexture (ID = " + targetID + " ) for this GradientDiffuseMethod"); 1287 if (spezialType == 0) 1288 SinglePassMaterialBase(mat).diffuseMethod = new GradientDiffuseMethod(returnedArray[1]); 1289 if (spezialType == 1) 1290 MultiPassMaterialBase(mat).diffuseMethod = new GradientDiffuseMethod(returnedArray[1]); 1291 debugString += " | GradientDiffuseMethod | GradientDiffuseTexture-Name =" + Texture2DBase(returnedArray[1]).name; 1292 break; 1293 case 53: //WrapDiffuseMethod 1294 if (spezialType == 0) 1295 SinglePassMaterialBase(mat).diffuseMethod = new WrapDiffuseMethod(props.get(101, 5)); 1296 if (spezialType == 1) 1297 MultiPassMaterialBase(mat).diffuseMethod = new WrapDiffuseMethod(props.get(101, 5)); 1298 debugString += " | WrapDiffuseMethod"; 1299 break; 1300 case 54: //LightMapDiffuseMethod 1301 targetID = props.get(1, 0); 1302 returnedArray = getAssetByID(targetID, [AssetType.TEXTURE]); 1303 if (!returnedArray[0]) 1304 _blocks[blockID].addError("Could not find the LightMap (ID = " + targetID + " ) for this LightMapDiffuseMethod"); 1305 if (spezialType == 0) 1306 SinglePassMaterialBase(mat).diffuseMethod = new LightMapDiffuseMethod(returnedArray[1], blendModeDic[props.get(401, 10)], false,…
Large files files are truncated, but you can click here to view the full file