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

                ParseChunks(reader, context.CurrentEndPosition, chunkType =>
                {
                    switch (chunkType)
                    {
                    case W3dChunkType.W3D_CHUNK_VERTEX_MATERIAL_IDS:
                        result.VertexMaterialIds = W3dUInt32List.Parse(reader, context, chunkType);
                        break;

                    case W3dChunkType.W3D_CHUNK_SHADER_IDS:
                        result.ShaderIds = W3dUInt32List.Parse(reader, context, chunkType);
                        break;

                    case W3dChunkType.W3D_CHUNK_DCG:
                        result.Dcg = W3dRgbaList.Parse(reader, context, chunkType);
                        break;

                    case W3dChunkType.W3D_CHUNK_DIG:
                        result.Dig = W3dRgbaList.Parse(reader, context, chunkType);
                        break;

                    case W3dChunkType.W3D_CHUNK_SCG:
                        result.Scg = W3dRgbaList.Parse(reader, context, chunkType);
                        break;

                    case W3dChunkType.W3D_CHUNK_TEXTURE_STAGE:
                        result.TextureStages.Add(W3dTextureStage.Parse(reader, context));
                        break;

                    case W3dChunkType.W3D_CHUNK_SHADER_MATERIAL_ID:
                        result.ShaderMaterialIds = W3dUInt32List.Parse(reader, context, chunkType);
                        break;

                    // Normally this appears inside W3dTextureStage, but it can also
                    // appear directly under W3dMaterialPass if using shader materials.
                    case W3dChunkType.W3D_CHUNK_STAGE_TEXCOORDS:
                        result.TexCoords = W3dVector2List.Parse(reader, context, chunkType);
                        break;

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

                return result;
            }));
        }
Ejemplo n.º 2
0
        public static W3dMaterialPass Parse(BinaryReader reader, uint chunkSize)
        {
            var textureStages = new List <W3dTextureStage>();

            var r = ParseChunk <W3dMaterialPass>(reader, chunkSize, (result, header) =>
            {
                switch (header.ChunkType)
                {
                case W3dChunkType.W3D_CHUNK_VERTEX_MATERIAL_IDS:
                    result.VertexMaterialIds = new uint[header.ChunkSize / sizeof(uint)];
                    for (var count = 0; count < result.VertexMaterialIds.Length; count++)
                    {
                        result.VertexMaterialIds[count] = reader.ReadUInt32();
                    }
                    break;

                case W3dChunkType.W3D_CHUNK_SHADER_IDS:
                    result.ShaderIds = new uint[header.ChunkSize / sizeof(uint)];
                    for (var count = 0; count < result.ShaderIds.Length; count++)
                    {
                        result.ShaderIds[count] = reader.ReadUInt32();
                    }
                    break;

                case W3dChunkType.W3D_CHUNK_DCG:
                    result.Dcg = new W3dRgba[header.ChunkSize / W3dRgba.SizeInBytes];
                    for (var count = 0; count < result.Dcg.Length; count++)
                    {
                        result.Dcg[count] = W3dRgba.Parse(reader);
                    }
                    break;

                case W3dChunkType.W3D_CHUNK_DIG:
                    result.Dig = new W3dRgba[header.ChunkSize / W3dRgba.SizeInBytes];
                    for (var count = 0; count < result.Dig.Length; count++)
                    {
                        result.Dig[count] = W3dRgba.Parse(reader);
                    }
                    break;

                case W3dChunkType.W3D_CHUNK_SCG:
                    result.Scg = new W3dRgba[header.ChunkSize / W3dRgba.SizeInBytes];
                    for (var count = 0; count < result.Scg.Length; count++)
                    {
                        result.Scg[count] = W3dRgba.Parse(reader);
                    }
                    break;

                case W3dChunkType.W3D_CHUNK_TEXTURE_STAGE:
                    textureStages.Add(W3dTextureStage.Parse(reader, header.ChunkSize));
                    break;

                case W3dChunkType.W3D_CHUNK_SHADER_MATERIAL_ID:
                    if (header.ChunkSize != sizeof(uint))
                    {
                        // TODO: If this is thrown: this is probably an array of IDs?
                        throw new InvalidDataException();
                    }
                    result.ShaderMaterialId = reader.ReadUInt32();
                    break;

                // Normally this appears inside W3dTextureStage, but it can also
                // appear directly under W3dMaterialPass if using shader materials.
                case W3dChunkType.W3D_CHUNK_STAGE_TEXCOORDS:
                    result.TexCoords = new Vector2[header.ChunkSize / (sizeof(float) * 2)];
                    for (var count = 0; count < result.TexCoords.Length; count++)
                    {
                        result.TexCoords[count] = reader.ReadVector2();
                    }
                    break;

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

            r.TextureStages = textureStages;

            return(r);
        }