Esempio n. 1
0
        public static MvdDocument Parse(Stream stream)
        {
            var rt             = new MvdDocument();
            var systemEncoding = Encoding.GetEncoding(932);

            // leave open
            var br     = new BinaryReader(stream);
            var header = ReadMvdString(br, 30, systemEncoding);

            if (header != DisplayName)
            {
                throw new InvalidOperationException("invalid format");
            }

            rt.Version = br.ReadSingle();

            if (rt.Version >= 2)
            {
                throw new NotSupportedException("specified format version not supported");
            }

            switch (br.ReadByte())
            {
            case 0:
                rt.Encoding = Encoding.Unicode;

                break;

            case 1:
            default:
                rt.Encoding = Encoding.UTF8;

                break;
            }

            rt.ObjectName = rt.Encoding.GetString(br.ReadSizedBuffer());
            br.ReadSizedBuffer();               // objectNameSize2 / objectName2
            rt.KeyFps = br.ReadSingle();
            br.ReadSizedBuffer();               // reservedSize / reserved

            while (br.GetRemainingLength() > 1)
            {
                var section = MvdSection.Parse(rt, br);

                if (section == null)
                {
                    break;
                }

                rt.Sections.Add(section);
            }

            return(rt);
        }
Esempio n. 2
0
        public static MvdSection Parse(MvdDocument document, BinaryReader br)
        {
            var        tag = (MvdTag)br.ReadByte();
            MvdSection rt  = null;

            switch (tag)
            {
            case MvdTag.NameList:
                rt = new MvdNameList();

                break;

            case MvdTag.Bone:
                rt = new MvdBoneData();

                break;

            case MvdTag.Morph:
                rt = new MvdMorphData();

                break;

            case MvdTag.ModelProperty:
                rt = new MvdModelPropertyData();

                break;

            case MvdTag.AccessoryProperty:
                rt = new MvdAccessoryPropertyData();

                break;

            case MvdTag.EffectProperty:
                rt = new MvdEffectPropertyData();

                break;

            case MvdTag.Camera:
                rt = new MvdCameraData();

                break;

            case MvdTag.Light:
                rt = new MvdLightData();

                break;

            case MvdTag.Project:
                rt = new MvdProjectData();

                break;

            case MvdTag.Eof:
                return(null);
            }

            rt.MinorType   = br.ReadByte();
            rt.RawKey      = br.ReadInt32();
            rt.RawItemSize = br.ReadInt32();
            rt.RawCount    = br.ReadInt32();

            using (var exr = br.CreateSizedBufferReader())
                rt.ReadExtensionRegion(document, exr);

            rt.Read(document, br);

            return(rt);
        }