Exemplo n.º 1
0
        private void ReadIKFrames([NotNull] VmdMotion motion)
        {
            var frameCount = _reader.ReadInt32();
            var frames     = new VmdIKFrame[frameCount];

            for (var i = 0; i < frameCount; ++i)
            {
                frames[i] = ReadIKFrame();
            }

            motion.IKFrames = frames;
        }
Exemplo n.º 2
0
        private VmdIKFrame ReadIKFrame()
        {
            var frame = new VmdIKFrame();

            frame.FrameIndex = _reader.ReadInt32();
            frame.Visible    = _reader.ReadBoolean();

            var ikCount = _reader.ReadInt32();
            var iks     = new IKControl[ikCount];

            for (var i = 0; i < ikCount; ++i)
            {
                iks[i] = ReadIKControl();
            }

            frame.IKControls = iks;

            return(frame);
        }
Exemplo n.º 3
0
        private VmdMotion ReadMotion()
        {
            var signature = ReadString(20);

            if (signature != "Vocaloid Motion Data")
            {
                throw new FormatException("VMD signature is not found.");
            }

            var motion = new VmdMotion();

            var formatVersionString = ReadString(10);

            motion.Version   = Convert.ToInt32(formatVersionString);
            motion.ModelName = ReadString(20);

            ReadBoneFrames();
            ReadFacialFrames();
            ReadCameraFrames();
            ReadLightFrames();

            // Unknown 2
            _reader.ReadBytes(4);

            if (_reader.BaseStream.Position != _reader.BaseStream.Length)
            {
                ReadIKFrames();
            }

            if (_reader.BaseStream.Position != _reader.BaseStream.Length)
            {
                throw new FormatException("The VMD file may contain other data that this reader does not recognize.");
            }

            return(motion);

            void ReadBoneFrames()
            {
                var frameCount = _reader.ReadInt32();
                var frames     = new VmdBoneFrame[frameCount];

                for (var i = 0; i < frameCount; ++i)
                {
                    frames[i] = ReadBoneFrame();
                }

                motion.BoneFrames = frames;
            }

            void ReadFacialFrames()
            {
                var frameCount = _reader.ReadInt32();
                var frames     = new VmdFacialFrame[frameCount];

                for (var i = 0; i < frameCount; ++i)
                {
                    frames[i] = ReadFacialFrame();
                }

                motion.FacialFrames = frames;
            }

            void ReadCameraFrames()
            {
                var frameCount = _reader.ReadInt32();
                var frames     = new VmdCameraFrame[frameCount];

                for (var i = 0; i < frameCount; ++i)
                {
                    frames[i] = ReadCameraFrame();
                }

                motion.CameraFrames = frames;
            }

            void ReadLightFrames()
            {
                var frameCount = _reader.ReadInt32();
                var frames     = new VmdLightFrame[frameCount];

                for (var i = 0; i < frameCount; ++i)
                {
                    frames[i] = ReadLightFrame();
                }

                motion.LightFrames = frames;
            }

            void ReadIKFrames()
            {
                var frameCount = _reader.ReadInt32();
                var frames     = new VmdIKFrame[frameCount];

                for (var i = 0; i < frameCount; ++i)
                {
                    frames[i] = ReadIKFrame();
                }

                motion.IKFrames = frames;
            }
        }