public Section(FramedStream stream)
 {
     stream.PushFrame(12);
     Header = new SectionHeader(stream);
     stream.PopFrame();
     stream.PushFrame(Header.Size);
     Data = SectionData.FromStream(Header, stream);
     stream.PopFrame();
 }
Beispiel #2
0
        public TextureSectionData(SectionHeader header, FramedStream stream)
        {
            SectionHeader dataHeader = new SectionHeader(stream);
            BinaryReader  reader     = new BinaryReader(stream);

            FilterMode = (TextureNativeSectionData.Filter)reader.ReadUInt16();
            var unk = reader.ReadUInt16(); // Unknown

            TextureName = (new Section(stream).Data as StringSectionData).Value;
            MaskName    = (new Section(stream).Data as StringSectionData).Value;
        }
Beispiel #3
0
        public GeometryListSectionData(SectionHeader header, FramedStream stream)
        {
            DataSectionData data = (DataSectionData) new Section(stream).Data;

            GeometryCount = BitConverter.ToUInt32(data.Value, 0);
            Geometry      = new GeometrySectionData[GeometryCount];

            for (int i = 0; i < GeometryCount; ++i)
            {
                Geometry[i] = (GeometrySectionData) new Section(stream).Data;
            }
        }
Beispiel #4
0
        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 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;
            }
        }
Beispiel #6
0
        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;
        }
Beispiel #7
0
        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;
            }
        }
Beispiel #8
0
        public static T FromStream <T>(SectionHeader header, FramedStream stream)
            where T : SectionData
        {
            if (myDataTypes == null)
            {
                FindTypes();
            }

            T data = null;

            if (myDataTypes.ContainsKey(header.Type))
            {
                Type            t    = myDataTypes[header.Type];
                ConstructorInfo cons = t.GetConstructor(new Type[] { typeof(SectionHeader), typeof(FramedStream) });
                if (cons != null)
                {
                    data = (T)cons.Invoke(new object[] { header, stream });
                }
            }
            return(data);
        }
        public MaterialSplitSectionData(SectionHeader header, FramedStream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            TriangleStrip  = reader.ReadUInt32() == 1;
            SplitCount     = reader.ReadUInt32();
            MaterialSplits = new MaterialSplit[SplitCount];
            FaceCount      = reader.ReadUInt32();

            IndexCount = 0;
            for (UInt16 i = 0; i < SplitCount; ++i)
            {
                MaterialSplits[i] = new MaterialSplit(IndexCount, stream);
                IndexCount       += MaterialSplits[i].VertexCount;
            }

            if (FaceCount + SplitCount != IndexCount)
            {
                throw new Exception("Bad model format");
            }
        }
Beispiel #10
0
        public Model(String name, FramedStream stream)
        {
            Name = name;

            List <GeometrySectionData> geos = new List <GeometrySectionData>();

            while (stream.CanRead)
            {
                SectionHeader header = new SectionHeader(stream);
                if (header.Type == SectionType.Clump)
                {
                    ClumpSectionData data = SectionData.FromStream <ClumpSectionData>(header, stream);
                    if (data.GeometryList != null)
                    {
                        geos.AddRange(data.GeometryList.Geometry);
                    }
                }
                break;
            }
            myGeometry = geos.ToArray();

            VertexBuffer = null;
        }
Beispiel #11
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];
            }
        }
Beispiel #12
0
 public DataSectionData(SectionHeader header, FramedStream stream)
 {
     Value = new byte[header.Size];
     stream.Read(Value, 0, (int)header.Size);
 }
 public StringSectionData(SectionHeader header, FramedStream stream)
 {
     Value = UnicodeEncoding.UTF8.GetString(stream.ReadBytes((int)header.Size)).TrimNullChars();
 }
Beispiel #14
0
        public TextureNativeSectionData(SectionHeader header, FramedStream stream)
        {
            SectionHeader dataHeader = new SectionHeader(stream);
            BinaryReader  reader     = new BinaryReader(stream);

            PlatformID  = reader.ReadUInt32();
            FilterFlags = (Filter)reader.ReadUInt16();
            WrapV       = (WrapMode)reader.ReadByte();
            WrapU       = (WrapMode)reader.ReadByte();
            DiffuseName = reader.ReadString(32);
            AlphaName   = reader.ReadString(32);
            Format      = (RasterFormat)reader.ReadUInt32();

            if (PlatformID == 9)
            {
                String dxt = reader.ReadString(4);
                switch (dxt)
                {
                case "DXT1":
                    Compression = CompressionMode.DXT1; break;

                case "DXT3":
                    Compression = CompressionMode.DXT3; break;

                default:
                    Compression = CompressionMode.None; break;
                }
            }
            else
            {
                Alpha = reader.ReadUInt32() == 0x1;
            }

            Width       = reader.ReadUInt16();
            Height      = reader.ReadUInt16();
            BPP         = (byte)(reader.ReadByte() >> 3);
            MipMapCount = reader.ReadByte();
            RasterType  = reader.ReadByte();

            if (RasterType != 0x4)
            {
                throw new Exception("Unexpected RasterType, expected 0x04.");
            }

            if (PlatformID == 9)
            {
                Alpha = (reader.ReadByte() & 0x1) == 0x1;
            }
            else
            {
                Compression = (CompressionMode)reader.ReadByte();
            }

            ImageDataSize = reader.ReadUInt32();
            if ((Format & RasterFormat.ExtMipMap) != 0)
            {
                ImageLevelData = new byte[MipMapCount][];
                for (int i = 0; i < MipMapCount; ++i)
                {
                    ImageLevelData[i] = reader.ReadBytes((int)ImageDataSize >> (2 * i));
                }
            }
            else
            {
                ImageLevelData    = new byte[1][];
                ImageLevelData[0] = reader.ReadBytes((int)ImageDataSize);
            }
        }
Beispiel #15
0
 public static SectionData FromStream(SectionHeader header, FramedStream stream)
 {
     return(FromStream <SectionData>(header, stream));
 }