Ejemplo n.º 1
0
        internal static W3dHierarchyDef Parse(BinaryReader reader, W3dParseContext context)
        {
            return(ParseChunk(reader, context, header =>
            {
                var result = new W3dHierarchyDef();

                ParseChunks(reader, context.CurrentEndPosition, chunkType =>
                {
                    switch (chunkType)
                    {
                    case W3dChunkType.W3D_CHUNK_HIERARCHY_HEADER:
                        result.Header = W3dHierarchy.Parse(reader, context);
                        break;

                    case W3dChunkType.W3D_CHUNK_PIVOTS:
                        result.Pivots = W3dPivots.Parse(reader, context);
                        break;

                    case W3dChunkType.W3D_CHUNK_PIVOT_FIXUPS:
                        result.PivotFixups = W3dPivotFixups.Parse(reader, context);
                        break;

                    default:
                        throw CreateUnknownChunkException(chunkType);
                    }
                });

                return result;
            }));
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }