private static W3dFile Parse(BinaryReader reader, string filePath) { var context = new W3dParseContext(); context.PushChunk(nameof(W3dFile), reader.BaseStream.Length); var result = new W3dFile { FilePath = filePath }; W3dContainerChunk.ParseChunks(reader, reader.BaseStream.Length, chunkType => { switch (chunkType) { case W3dChunkType.W3D_CHUNK_MESH: result.Chunks.Add(W3dMesh.Parse(reader, context)); break; case W3dChunkType.W3D_CHUNK_BOX: result.Chunks.Add(W3dBox.Parse(reader, context)); break; case W3dChunkType.W3D_CHUNK_HIERARCHY: result.Chunks.Add(W3dHierarchyDef.Parse(reader, context)); break; case W3dChunkType.W3D_CHUNK_HLOD: result.Chunks.Add(W3dHLod.Parse(reader, context)); break; case W3dChunkType.W3D_CHUNK_ANIMATION: result.Chunks.Add(W3dAnimation.Parse(reader, context)); break; case W3dChunkType.W3D_CHUNK_COMPRESSED_ANIMATION: result.Chunks.Add(W3dCompressedAnimation.Parse(reader, context)); break; case W3dChunkType.W3D_CHUNK_EMITTER: result.Chunks.Add(W3dEmitter.Parse(reader, context)); break; default: throw W3dContainerChunk.CreateUnknownChunkException(chunkType); } }); context.PopAsset(); return(result); }
internal static W3dCompressedAnimation Parse(BinaryReader reader, W3dParseContext context) { return(ParseChunk(reader, context, header => { var result = new W3dCompressedAnimation(); ParseChunks(reader, context.CurrentEndPosition, chunkType => { switch (chunkType) { case W3dChunkType.W3D_CHUNK_COMPRESSED_ANIMATION_HEADER: result.Header = W3dCompressedAnimationHeader.Parse(reader, context); break; case W3dChunkType.W3D_CHUNK_COMPRESSED_ANIMATION_CHANNEL: switch (result.Header.Flavor) { case W3dCompressedAnimationFlavor.TimeCoded: result.TimeCodedChannels.Add(W3dTimeCodedAnimationChannel.Parse(reader, context)); break; case W3dCompressedAnimationFlavor.AdaptiveDelta4: result.AdaptiveDeltaChannels.Add(W3dAdaptiveDeltaAnimationChannel.Parse(reader, context, W3dAdaptiveDeltaBitCount.FourBits)); break; default: throw new InvalidDataException(); } break; case W3dChunkType.W3D_CHUNK_COMPRESSED_BIT_CHANNEL: switch (result.Header.Flavor) { case W3dCompressedAnimationFlavor.TimeCoded: result.TimeCodedBitChannels.Add(W3dTimeCodedBitChannel.Parse(reader, context)); break; default: throw new InvalidDataException(); } break; case W3dChunkType.W3D_CHUNK_COMPRESSED_ANIMATION_MOTION_CHANNEL: switch (result.Header.Flavor) { case W3dCompressedAnimationFlavor.TimeCoded: result.MotionChannels.Add(W3dMotionChannel.Parse(reader, context)); break; default: throw new InvalidDataException(); } break; default: throw CreateUnknownChunkException(chunkType); } }); return result; })); }
private static W3dFile Parse(BinaryReader reader, string filePath) { var meshes = new List <W3dMesh>(); var boxes = new List <W3dBox>(); W3dHierarchyDef hierarchy = null; W3dHLod hlod = null; var animations = new List <W3dAnimation>(); var compressedAnimations = new List <W3dCompressedAnimation>(); var emitters = new List <W3dEmitter>(); W3dFile result; if (reader.BaseStream.Length > 0) { result = ParseChunk <W3dFile>(reader, (uint)reader.BaseStream.Length, (x, header) => { switch (header.ChunkType) { case W3dChunkType.W3D_CHUNK_MESH: meshes.Add(W3dMesh.Parse(reader, header.ChunkSize)); break; case W3dChunkType.W3D_CHUNK_BOX: boxes.Add(W3dBox.Parse(reader)); break; case W3dChunkType.W3D_CHUNK_HIERARCHY: if (hierarchy != null) { throw new InvalidDataException(); } hierarchy = W3dHierarchyDef.Parse(reader, header.ChunkSize); break; case W3dChunkType.W3D_CHUNK_HLOD: if (hlod != null) { throw new InvalidDataException(); } hlod = W3dHLod.Parse(reader, header.ChunkSize); break; case W3dChunkType.W3D_CHUNK_ANIMATION: animations.Add(W3dAnimation.Parse(reader, header.ChunkSize)); break; case W3dChunkType.W3D_CHUNK_COMPRESSED_ANIMATION: compressedAnimations.Add(W3dCompressedAnimation.Parse(reader, header.ChunkSize)); break; case W3dChunkType.W3D_CHUNK_EMITTER: emitters.Add(W3dEmitter.Parse(reader, header.ChunkSize)); break; default: throw CreateUnknownChunkException(header); } }); } else { result = new W3dFile(); } result.FilePath = filePath; result.Meshes = meshes; result.Boxes = boxes; result.Hierarchy = hierarchy; result.HLod = hlod; result.Animations = animations; result.CompressedAnimations = compressedAnimations; result.Emitters = emitters; return(result); }