public MaterialListSectionData( SectionHeader header, FramedStream stream )
        {
            Section data = new Section( stream );
            MaterialCount = BitConverter.ToUInt32( ( data.Data as DataSectionData ).Value, 0 );
            Materials = new MaterialSectionData[ MaterialCount ];

            for ( int i = 0; i < MaterialCount; ++i )
                Materials[ i ] = new Section( stream ).Data as MaterialSectionData;
        }
        public ClumpSectionData( SectionHeader header, FramedStream stream )
        {
            DataSectionData dat = (DataSectionData) new Section( stream ).Data;
            if ( dat == null )
                return;

            ObjectCount = BitConverter.ToUInt32( dat.Value, 0 );
            var frameList = new Section( stream );
            GeometryList = (GeometryListSectionData) new Section( stream ).Data;
        }
        public TextureDictionarySectionData( SectionHeader header, FramedStream stream )
        {
            SectionHeader dataHeader = new SectionHeader( stream );
            BinaryReader reader = new BinaryReader( stream );

            TextureCount = reader.ReadUInt16();
            Textures = new TextureNativeSectionData[ TextureCount ];
            reader.ReadUInt16(); // Unknown

            for ( int i = 0; i < TextureCount; ++i )
                Textures[ i ] = new Section( stream ).Data as TextureNativeSectionData;
        }
        public MaterialSectionData( SectionHeader header, FramedStream stream )
        {
            SectionHeader dataHeader = new SectionHeader( stream );
            BinaryReader reader = new BinaryReader( stream );

            reader.ReadUInt32(); // Unknown
            Colour = new Color4( reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte() );
            var unk = reader.ReadUInt32(); // Unknown
            TextureCount = reader.ReadUInt32();
            Textures = new TextureSectionData[ TextureCount ];
            reader.ReadSingle(); // Unknown
            reader.ReadSingle(); // Unknown
            reader.ReadSingle(); // Unknown

            for ( int i = 0; i < TextureCount; ++i )
                Textures[ i ] = new Section( stream ).Data as TextureSectionData;
        }
        public TextureDictionary( String name, FramedStream stream )
        {
            Name = name;

            Section sec = new Section( stream );
            TextureDictionarySectionData data = sec.Data as TextureDictionarySectionData;

            myDiffuseTextures = new Dictionary<string, Texture2D>();
            myMaskTextures = new Dictionary<string, Texture2D>();

            foreach ( TextureNativeSectionData tex in data.Textures )
            {
                Texture2D t2d = new Texture2D( tex );
                if ( tex.DiffuseName.Length > 0 && !myDiffuseTextures.ContainsKey( tex.DiffuseName ) )
                    myDiffuseTextures.Add( tex.DiffuseName, t2d );
                if ( tex.AlphaName.Length > 0 && !myMaskTextures.ContainsKey( tex.AlphaName ) )
                    myMaskTextures.Add( tex.AlphaName, t2d );
            }
        }
        public GeometrySectionData( SectionHeader header, FramedStream stream )
        {
            SectionHeader dataHeader = new SectionHeader( stream );
            BinaryReader reader = new BinaryReader( stream );

            Flags = (GeometryFlag) reader.ReadUInt16();
            reader.ReadUInt16(); // Unknown
            FaceCount = reader.ReadUInt32();
            VertexCount = reader.ReadUInt32();
            FrameCount = reader.ReadUInt32();

            if ( dataHeader.Version == 4099 )
            {
                Ambient = reader.ReadSingle();
                Diffuse = reader.ReadSingle();
                Specular = reader.ReadSingle();
            }

            if ( ( Flags & GeometryFlag.Colors ) != 0 )
            {
                Colours = new Color4[ VertexCount ];
                for ( int i = 0; i < VertexCount; ++i )
                {
                    byte r = reader.ReadByte();
                    byte g = reader.ReadByte();
                    byte b = reader.ReadByte();
                    byte a = reader.ReadByte();
                    Colours[ i ] = new Color4( r, g, b, a );
                }
            }

            if ( ( Flags & GeometryFlag.TexCoords ) != 0 )
            {
                TexCoords = new Vector2[ VertexCount ];
                for ( int i = 0; i < VertexCount; ++i )
                    TexCoords[ i ] = reader.ReadVector2();
            }

            Faces = new FaceInfo[ FaceCount ];
            for ( int i = 0; i < FaceCount; ++i )
                Faces[ i ] = new FaceInfo( reader );

            BoundingSphere = new BoundingSphere( reader );

            HasPosition = reader.ReadUInt32();
            HasNormals = reader.ReadUInt32();

            if ( HasPosition > 1 || HasNormals > 1 )
                throw new Exception( "Well there you go" );

            Vertices = new Vector3[ VertexCount ];
            for ( int i = 0; i < VertexCount; ++i )
                Vertices[ i ] = reader.ReadVector3();

            if ( ( Flags & GeometryFlag.Normals ) != 0 )
            {
                Normals = new Vector3[ VertexCount ];
                for ( int i = 0; i < VertexCount; ++i )
                    Normals[ i ] = reader.ReadVector3();
            }

            Materials = ( new Section( stream ).Data as MaterialListSectionData ).Materials;

            SectionHeader extHeader = new SectionHeader( stream );
            MaterialSplitSectionData msplits = new Section( stream ).Data as MaterialSplitSectionData;
            MaterialSplits = msplits.MaterialSplits;
            FaceCount = msplits.FaceCount;
            IndexCount = msplits.IndexCount;

            foreach ( MaterialSplit mat in MaterialSplits )
                mat.Material = Materials[ mat.MaterialIndex ];
        }