Exemple #1
0
        public static H3D Open(Stream Input)
        {
            BinaryDeserializer Deserializer = new BinaryDeserializer(Input, GetSerializationOptions());

            GfxHeader Header = Deserializer.Deserialize <GfxHeader>();
            Gfx       Scene  = Deserializer.Deserialize <Gfx>();

            return(Scene.ToH3D());
        }
Exemple #2
0
        public static Gfx Open(string FileName)
        {
            using (FileStream Input = new FileStream(FileName, FileMode.Open))
            {
                BinaryDeserializer Deserializer = new BinaryDeserializer(Input, GetSerializationOptions());

                GfxHeader Header = Deserializer.Deserialize <GfxHeader>();
                Gfx       Scene  = Deserializer.Deserialize <Gfx>();

                return(Scene);
            }
        }
Exemple #3
0
        public static void Save(string FileName, Gfx Scene)
        {
            using (FileStream FS = new FileStream(FileName, FileMode.Create))
            {
                GfxHeader Header = new GfxHeader();

                BinarySerializer Serializer = new BinarySerializer(FS, GetSerializationOptions());

                Serializer.FileVersion = 0x07010000;

                Section Contents = Serializer.Sections[(uint)H3DSectionId.Contents];

                Contents.Header = Header;

                Section Strings = new Section();
                Section Image   = new Section();

                Image.Header = new GfxSectionHeader("IMAG");

                Serializer.AddSection((uint)GfxSectionId.Strings, Strings, typeof(string));
                Serializer.AddSection((uint)GfxSectionId.Strings, Strings, typeof(GfxStringUtf8));
                Serializer.AddSection((uint)GfxSectionId.Strings, Strings, typeof(GfxStringUtf16LE));
                Serializer.AddSection((uint)GfxSectionId.Strings, Strings, typeof(GfxStringUtf16BE));
                bool WriteImage = Scene.Models.Count > 0 || Scene.Textures.Count > 0;
                if (WriteImage)
                {
                    Serializer.AddSection((uint)GfxSectionId.Image, Image);
                }

                Serializer.Serialize(Scene);

                Header.FileLength = (int)FS.Length;

                Header.SectionsCount = Image.Values.Count > 0 ? 2 : 1;

                Header.Data.Length = Contents.Length + Strings.Length + 8;

                FS.Seek(0, SeekOrigin.Begin);

                Serializer.WriteValue(Header);

                if (WriteImage)
                {
                    FS.Seek(Image.Position - 4, SeekOrigin.Begin);

                    Serializer.Writer.Write(Image.LengthWithHeader);
                }
            }
        }