public MainForm() { InitializeComponent(); vmd = new VocaloidMotionData(); CalculateFPB(); CaluculateLoopTimes(); }
public static void ReverseInterpolation(VocaloidMotionData vmd) { foreach (var pair in vmd.CameraFrames.SelectMany(frame => frame.InterpolationCurves)) { ReverseInterpolation(pair.Value); } }
public VocaloidMotionData CreateLoopMotion(VocaloidMotionData vmd, IntervalCalculator loop, DuplicationCounter counter) { if (loop.Interval is null) { throw new ArgumentNullException("設置間隔が未設定です。"); } var result = new VocaloidMotionData() { Header = vmd.Header, ModelName = vmd.ModelName, }; // nullならここまで到達しない var interval = loop.Interval.Value * counter.Frequency; var count = counter.ElementCount; void CreateAndAddDuplicate <T>(List <T> source, List <T> result) where T : IVocaloidFrame { if (source.Any()) { result.AddRange(Duplicate(source.Select(f => (IVocaloidFrame)f), interval, count).Select(f => (T)f)); } } CreateAndAddDuplicate(vmd.CameraFrames, result.CameraFrames); CreateAndAddDuplicate(vmd.LightFrames, result.LightFrames); CreateAndAddDuplicate(vmd.MorphFrames, result.MorphFrames); CreateAndAddDuplicate(vmd.MotionFrames, result.MotionFrames); CreateAndAddDuplicate(vmd.PropertyFrames, result.PropertyFrames); CreateAndAddDuplicate(vmd.ShadowFrames, result.ShadowFrames); return(result); }
public static void ReverseTime(VocaloidMotionData vmd) { List <IVocaloidFrame> allFrames = vmd.Frames; var maxTime = allFrames.Max(frame => frame.Frame); foreach (var frame in allFrames) { frame.Frame = maxTime - frame.Frame; } }
public string OutputVMD(List <Point> points, int frameLength, string morphName, double startRatio, double endRatio) { string FileName = $"Complemented_{new string(morphName.Where(c => !Path.GetInvalidFileNameChars().Contains(c)).ToArray())}.vmd"; VocaloidMotionData vmd = new VocaloidMotionData(); vmd.ModelName = "Complemented Morphs"; vmd.MorphFrames.AddRange(points.Select(p => new VmdMorphFrameData(morphName, (uint)Math.Round(p.X * frameLength), (float)(p.Y * (endRatio - startRatio) + startRatio)))); using (BinaryWriter writer = new BinaryWriter(new FileStream(FileName, FileMode.OpenOrCreate))) { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); vmd.Write(writer); } return(FileName); }
public void Read(string path) { using (BinaryReader reader = new BinaryReader(new FileStream(path, FileMode.Open))) vmd = new VocaloidMotionData(reader); if (vmd.ModelName == VocaloidMotionData.CAMERA_DATA_NAME) { throw new FormatException(); } FilePath = path; // Articlesにフレームを分類して格納 foreach (var f in vmd.MorphFrames) { MakeArticle(f, FrameType.Morph); } foreach (var f in vmd.MotionFrames) { MakeArticle(f, FrameType.Motion); } }
public void TestCreateLoopMotion() { VocaloidMotionData vmd = new() { ModelName = "Test" }; vmd.MotionFrames.Add(new("test", 0)); vmd.MorphFrames.Add(new("mp", 1)); IntervalCalculator calculator = new(30) { Interval = 10m }; DuplicationCounter counter = new() { Beat = 4, LoopCount = 4, Frequency = 2 }; FrameDuplicator duplicator = new(); VocaloidMotionData loopMotion = duplicator.CreateLoopMotion(vmd, calculator, counter); Assert.AreEqual(2, vmd.Frames.Count()); Assert.AreEqual(counter.ElementCount * 2, loopMotion.Frames.Count()); Assert.AreEqual((uint)0, loopMotion.MotionFrames.ElementAt(0).Frame); Assert.AreEqual((uint)20, loopMotion.MotionFrames.ElementAt(1).Frame); Assert.AreEqual((uint)1, loopMotion.MorphFrames.ElementAt(0).Frame); Assert.AreEqual((uint)21, loopMotion.MorphFrames.ElementAt(1).Frame); } } }
public (Point First, Point Second) ImportFromVMD(VocaloidMotionData vmd, InterpolationItem interpolation, bool isCamera) { VmdCameraFrameData?firstCameraFrame = vmd.CameraFrames.Count > 0 ? vmd.CameraFrames.First() : null; VmdMotionFrameData?firstMotionFrame = vmd.MotionFrames.Count > 0 ? vmd.MotionFrames.First() : null; if (isCamera && firstCameraFrame is null) { throw new ArgumentNullException("VMDからフレームを発見出来ませんでした。"); } if (!isCamera && firstMotionFrame is null) { throw new ArgumentNullException("VMDからフレームを発見出来ませんでした。"); } return(interpolation switch { InterpolationItem.XPosition => isCamera?IPC(firstCameraFrame?.InterpolatePointX) : IPM(firstMotionFrame?.InterpolatePointX), InterpolationItem.YPosition => isCamera?IPC(firstCameraFrame?.InterpolatePointY) : IPM(firstMotionFrame?.InterpolatePointY), InterpolationItem.ZPosition => isCamera?IPC(firstCameraFrame?.InterpolatePointZ) : IPM(firstMotionFrame?.InterpolatePointZ), InterpolationItem.Rotation => isCamera?IPC(firstCameraFrame?.InterpolatePointR) : IPM(firstMotionFrame?.InterpolatePointR), InterpolationItem.Distance => IPC(firstCameraFrame?.InterpolatePointD), InterpolationItem.ViewAngle => IPC(firstCameraFrame?.InterpolatePointA), _ => throw new InvalidOperationException(), });
public VocaloidMotionData CreateLoopMotion(VocaloidMotionData vmd) => FrameDuplicator.CreateLoopMotion(vmd, IntervalCalculator, DuplicationCounter);