Пример #1
0
 public void Save(BinaryWriter Writer)
 {
     Label tHeader = new Label(4);
     tHeader.Content = "FMM";
     tHeader.Save(Writer);
     Writer.Write((UInt32)100);
     Writer.Write((UInt32)_BlockList.Count);
     _Author.Save(Writer);
     _Description.Save(Writer);
     for (int i = 0; i < _BlockList.Count; ++i)
     {
         _BlockList[i].Save(Writer);
     }
 }
Пример #2
0
        public void Load(BinaryReader Reader)
        {
            New();

            try
            {
                // 检查文件头
                Label tHeader = new Label(4);
                tHeader.Load(Reader);
                if (tHeader.Content != "FMM")
                    throw new FormatException("Header check failed.");
                if (Reader.ReadUInt32() != 100)
                    throw new FormatException("Version not support.");
                UInt32 tBlockCount = Reader.ReadUInt32();
                _Author.Load(Reader);
                _Description.Load(Reader);

                // 读取所有块
                Label tBlockHeader = new Label(8);
                for (UInt32 i = 0; i < tBlockCount; ++i)
                {
                    Block tBlock = null;
                    tBlockHeader.Load(Reader);
                    switch (tBlockHeader.Content)
                    {
                        case "VERTEX":
                            tBlock = new VertexBlock();
                            break;
                        case "INDEX":
                            tBlock = new IndexBlock();
                            break;
                        case "SUBSET":
                            tBlock = new SubsetBlock();
                            break;
                        case "MATERIAL":
                            tBlock = new MaterialBlock();
                            break;
                        case "BOUNDBOX":
                            tBlock = new BoundingBoxBlock();
                            break;
                        default:
                            tBlock = new UnknownBlock(tBlockHeader.Content);
                            break;
                    }

                    tBlock.Load(Reader);
                    _BlockList.Add(tBlock);
                }
            }
            catch
            {
                New();

                throw;
            }
        }