示例#1
0
        public static void Scale([NotNull] this VmdMotion motion, float scale)
        {
            foreach (var boneFrame in motion.BoneFrames)
            {
                boneFrame.Position *= scale;
            }

            // TODO: Other scales
        }
示例#2
0
        private void WriteLightFrames([NotNull] VmdMotion motion)
        {
            _writer.Write(motion.LightFrames.Length);

            foreach (var frame in motion.LightFrames)
            {
                WriteLightFrame(frame);
            }
        }
示例#3
0
        private void WriteCameraFrames([NotNull] VmdMotion motion)
        {
            _writer.Write(motion.CameraFrames.Count);

            foreach (var frame in motion.CameraFrames)
            {
                WriteCameraFrame(frame);
            }
        }
示例#4
0
 public MotionData(VmdMotion motion)
 {
     FrameCount = motion.FrameCount;
     Rotate     = motion.Rotation;
     Translate  = motion.Position;
     XInterp    = motion.XInterp;
     YInterp    = motion.YInterp;
     ZInterp    = motion.ZInterp;
     RotInterp  = motion.RotInterp;
 }
示例#5
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;
        }
示例#6
0
        public VmdMotion CreateFrom([CanBeNull] CharacterImasMotionAsset bodyMotion, [CanBeNull] Avatar avatar, [CanBeNull] PmxModel mltdPmxModel,
                                    [CanBeNull] CharacterImasMotionAsset cameraMotion,
                                    [CanBeNull] ScenarioObject scenarioObject, int songPosition)
        {
            IReadOnlyList <VmdBoneFrame>   boneFrames;
            IReadOnlyList <VmdCameraFrame> cameraFrames;
            IReadOnlyList <VmdFacialFrame> facialFrames;
            IReadOnlyList <VmdLightFrame>  lightFrames;

            if (ProcessBoneFrames && (bodyMotion != null && avatar != null && mltdPmxModel != null))
            {
                boneFrames = CreateBoneFrames(bodyMotion, avatar, mltdPmxModel);
            }
            else
            {
                boneFrames = EmptyArray.Of <VmdBoneFrame>();
            }

            if (ProcessCameraFrames && cameraMotion != null)
            {
                cameraFrames = CreateCameraFrames(cameraMotion, FixedFov);
            }
            else
            {
                cameraFrames = EmptyArray.Of <VmdCameraFrame>();
            }

            if (ProcessFacialFrames && scenarioObject != null)
            {
                facialFrames = CreateFacialFrames(scenarioObject, songPosition);
            }
            else
            {
                facialFrames = EmptyArray.Of <VmdFacialFrame>();
            }

            if (ProcessLightFrames && scenarioObject != null)
            {
                lightFrames = CreateLightFrames(scenarioObject);
            }
            else
            {
                lightFrames = EmptyArray.Of <VmdLightFrame>();
            }

            const string modelName = "MODEL_00";

            var vmd = new VmdMotion(modelName, boneFrames, facialFrames, cameraFrames, lightFrames, null);

            return(vmd);
        }
示例#7
0
        private void WriteIkFrames([NotNull] VmdMotion motion)
        {
            if (motion.IkFrames == null)
            {
                return;
            }

            _writer.Write(motion.IkFrames.Length);

            foreach (var frame in motion.IkFrames)
            {
                WriteIkFrame(frame);
            }
        }
示例#8
0
        private void WriteMotion([NotNull] VmdMotion motion)
        {
            WriteString($"Vocaloid Motion Data {motion.Version:0000}", 30);

            WriteString(motion.ModelName, 20);

            WriteBoneFrames(motion);
            WriteFacialFrames(motion);
            WriteCameraFrames(motion);
            WriteLightFrames(motion);

            _writer.Write(new byte[4]);

            WriteIkFrames(motion);
        }
示例#9
0
        public void InitializeContents([NotNull] PmxModel pmxModel, [NotNull] VmdMotion vmdMotion)
        {
            _pmxModel  = pmxModel;
            _vmdMotion = vmdMotion;

            foreach (var boneFrame in vmdMotion.BoneFrames)
            {
                if (!_lastBoneFrames.ContainsKey(boneFrame.Name))
                {
                    _lastBoneFrames[boneFrame.Name] = boneFrame;
                }

                List <VmdBoneFrame> cachedBoneFrames;

                if (!_boneFrameCache.ContainsKey(boneFrame.Name))
                {
                    cachedBoneFrames = new List <VmdBoneFrame>();
                    _boneFrameCache[boneFrame.Name] = cachedBoneFrames;
                }
                else
                {
                    cachedBoneFrames = _boneFrameCache[boneFrame.Name];
                }

                cachedBoneFrames.Add(boneFrame);
            }

            _boneFrameNames = _lastBoneFrames.Keys.ToArray();

#if DEBUG
            Debug.Print("VMD bone list:");

            foreach (var boneFrameName in _boneFrameNames)
            {
                Debug.Print(boneFrameName);
            }
#endif
        }
示例#10
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(motion);
            ReadFacialFrames(motion);
            ReadCameraFrames(motion);
            ReadLightFrames(motion);

            // Unknown 2
            _reader.ReadBytes(4);

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

            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);
        }
示例#11
0
        private void WriteMotion([NotNull] VmdMotion motion)
        {
            WriteString($"Vocaloid Motion Data {motion.Version:0000}", 30);

            WriteString(motion.ModelName, 20);

            WriteBoneFrames();
            WriteFacialFrames();
            WriteCameraFrames();
            WriteLightFrames();

            _writer.Write(new byte[4]);

            WriteIkFrames();

            void WriteBoneFrames()
            {
                _writer.Write(motion.BoneFrames.Count);

                foreach (var frame in motion.BoneFrames)
                {
                    WriteBoneFrame(frame);
                }
            }

            void WriteFacialFrames()
            {
                _writer.Write(motion.FacialFrames.Count);

                foreach (var frame in motion.FacialFrames)
                {
                    WriteFacialFrame(frame);
                }
            }

            void WriteCameraFrames()
            {
                _writer.Write(motion.CameraFrames.Count);

                foreach (var frame in motion.CameraFrames)
                {
                    WriteCameraFrame(frame);
                }
            }

            void WriteLightFrames()
            {
                _writer.Write(motion.LightFrames.Count);

                foreach (var frame in motion.LightFrames)
                {
                    WriteLightFrame(frame);
                }
            }

            void WriteIkFrames()
            {
                if (motion.IkFrames == null)
                {
                    return;
                }

                _writer.Write(motion.IkFrames.Count);

                foreach (var frame in motion.IkFrames)
                {
                    WriteIkFrame(frame);
                }
            }
        }
示例#12
0
 public void Write([NotNull] VmdMotion motion)
 {
     WriteMotion(motion);
 }