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 ];
        }
Exemplo n.º 2
0
        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];
            }
        }