public void Load(string filePath, SkeletonEntry skeletonEntry, MotionDatabase motionDatabase) { using (var stream = File.OpenRead(filePath)) Load(stream, skeletonEntry, motionDatabase); if (motionDatabase == null) { return; } string motionSetName = Path.GetFileNameWithoutExtension(filePath); if (motionSetName.StartsWith("mot_", StringComparison.OrdinalIgnoreCase)) { motionSetName = motionSetName.Substring(4); } var motionSetEntry = motionDatabase.GetMotionSet(motionSetName); if (motionSetEntry == null || Motions.Count != motionSetEntry.Motions.Count) { return; } for (int i = 0; i < motionSetEntry.Motions.Count; i++) { Motions[i].Name = motionSetEntry.Motions[i].Name; Motions[i].Id = motionSetEntry.Motions[i].Id; } }
public void Save(string filePath, Skeleton skeleton, MotionDatabase motionDatabase) { using (var stream = File.Create(filePath)) { Save(stream, skeleton, motionDatabase); } }
public void Save(Stream destination, SkeletonEntry skeletonEntry, MotionDatabase motionDatabase, bool leaveOpen = false) { if (skeletonEntry != null && motionDatabase != null) { foreach (var motion in Motions.Where(x => x.HasController)) { motion.GetController().Update(skeletonEntry, motionDatabase); } } Save(destination, leaveOpen); }
public void Save(Stream destination, Skeleton skeleton, MotionDatabase motionDatabase, bool leaveOpen = false) { if (skeleton != null && motionDatabase != null) { foreach (var motion in Motions.Where(x => x.HasBinding)) { motion.Bind().Unbind(skeleton, motionDatabase); } } Save(destination, leaveOpen); }
public void Load(Stream source, SkeletonEntry skeletonEntry, MotionDatabase motionDatabase, bool leaveOpen = false) { Load(source, leaveOpen); if (skeletonEntry == null || motionDatabase == null) { return; } foreach (var motion in Motions) { motion.GetController(skeletonEntry, motionDatabase); } }
public void Load(Stream source, Skeleton skeleton, MotionDatabase motionDatabase, bool leaveOpen = false) { Load(source, leaveOpen); if (skeleton == null || motionDatabase == null) { return; } foreach (var motion in Motions) { motion.Bind(skeleton, motionDatabase); } }
public MotionBinding Bind(Skeleton skeleton = null, MotionDatabase motionDatabase = null) { if (mBinding != null) { return(mBinding); } if (skeleton == null) { throw new ArgumentNullException(nameof(skeleton)); } var binding = new MotionBinding(this); int index = 0; foreach (var boneInfo in BoneInfos) { if (motionDatabase != null && boneInfo.Id >= motionDatabase.BoneNames.Count) { break; } boneInfo.Name = boneInfo.Name ?? motionDatabase?.BoneNames[( int )boneInfo.Id] ?? throw new ArgumentNullException(nameof(motionDatabase)); var bone = skeleton.GetBone(boneInfo.Name); var boneBinding = new BoneBinding { Name = boneInfo.Name }; if (bone != null) { if (bone.Type != BoneType.Rotation) { boneBinding.Position = BindNext(); } if (bone.Type != BoneType.Position) { boneBinding.Rotation = BindNext(); } binding.BoneBindings.Add(boneBinding); } else if (boneInfo.Name.Equals("gblctr", StringComparison.OrdinalIgnoreCase)) { binding.GlobalTransformation.Position = BindNext(); } else if (boneInfo.Name.Equals("kg_ya_ex", StringComparison.OrdinalIgnoreCase)) { binding.GlobalTransformation.Rotation = BindNext(); } KeyBinding BindNext() { return(new KeyBinding { X = KeySets[index++], Y = KeySets[index++], Z = KeySets[index++] }); } } return(mBinding = binding); }
public void Unbind(Skeleton skeleton, MotionDatabase motionDatabase = null) { Parent.KeySets.Clear(); Parent.BoneInfos.Clear(); foreach (var boneBinding in skeleton.MotionBoneNames .Where(x => motionDatabase == null || motionDatabase.BoneNames.Contains(x, StringComparer.OrdinalIgnoreCase)) .Select(x => BoneBindings.Find(y => y.Name.Equals(x, StringComparison.OrdinalIgnoreCase)) ?? new BoneBinding { Name = x }).OrderByDescending(x => x.Name)) { var bone = skeleton.GetBone(boneBinding.Name); if (bone != null) { if (bone.Type != BoneType.Rotation) { UnbindPosition(boneBinding); } if (bone.Type != BoneType.Position) { UnbindRotation(boneBinding); } } AddBone(boneBinding.Name); } AddBone("gblctr"); UnbindPosition(GlobalTransformation); AddBone("kg_ya_ex"); UnbindRotation(GlobalTransformation); Parent.KeySets.Add(new KeySet()); void UnbindPosition(BoneBinding boneBinding) { Parent.KeySets.Add(boneBinding.Position?.X ?? new KeySet()); Parent.KeySets.Add(boneBinding.Position?.Y ?? new KeySet()); Parent.KeySets.Add(boneBinding.Position?.Z ?? new KeySet()); } void UnbindRotation(BoneBinding boneBinding) { Parent.KeySets.Add(boneBinding.Rotation?.X ?? new KeySet()); Parent.KeySets.Add(boneBinding.Rotation?.Y ?? new KeySet()); Parent.KeySets.Add(boneBinding.Rotation?.Z ?? new KeySet()); } void AddBone(string name) { Parent.BoneInfos.Add(new BoneInfo { Name = name, Id = motionDatabase?.BoneNames?.FindIndex( x => x.Equals(name, StringComparison.OrdinalIgnoreCase)) ?? -1, }); } }
private void doRobConvert() { string ac_path = ""; string ft_path = ""; string fs_path = ""; string ct_path = ""; bool ask_user = false; bool skip_robs = false; if (File.Exists("config.txt")) { StreamReader sr = new StreamReader("config.txt"); while (sr.Peek() > -1) { var line = sr.ReadLine(); var lines = line.Split('='); if (lines[0] == "AC") { ac_path = lines[1]; } if (lines[0] == "FT") { ft_path = lines[1]; } if (lines[0] == "FS") { fs_path = lines[1]; } if (lines[0] == "CT") { ct_path = lines[1]; } if (lines[0] == "I_HAVE_CHANGED_THIS") { if (lines[1] == "TRUE") { ask_user = true; } } if (lines[0] == "SKIP_ROBS") { if (lines[1] == "TRUE") { skip_robs = true; } } } sr.Close(); } if ((ask_user) && (!skip_robs)) { Logs.WriteLine("Rob Retarget Start"); string[] filespl = System.IO.Directory.GetFiles(ft_path + @"\rob\", "*.farc", SearchOption.AllDirectories); string[] filesfs = { }; string[] filesct = { }; if (fs_path != "") { filesfs = System.IO.Directory.GetFiles(fs_path + @"\rob\", "*.farc", SearchOption.AllDirectories); } if (ct_path != "") { filesct = System.IO.Directory.GetFiles(ct_path + @"\rob\", "*.farc", SearchOption.AllDirectories); } string[] files = filespl.Concat(filesfs).ToArray().Concat(filesct).ToArray(); var BoneDatabaseFT = new BoneDatabase(); var BoneDatabaseAC = new BoneDatabase(); var MotionDatabaseFT = new MotionDatabase(); var MotionDatabaseAC = new MotionDatabase(); BoneDatabaseFT.Load(ft_path + "\\bone_data.bin"); BoneDatabaseAC.Load(ac_path + "\\bone_data.bin"); using (var farcArchive = BinaryFile.Load <FarcArchive>(ac_path + "\\rob\\mot_db.farc")) using (var entryStream = farcArchive.Open(farcArchive.Entries.First(), EntryStreamMode.MemoryStream)) MotionDatabaseAC.Load(entryStream); using (var farcArchive = BinaryFile.Load <FarcArchive>(ft_path + "\\rob\\mot_db.farc")) using (var entryStream = farcArchive.Open(farcArchive.Entries.First(), EntryStreamMode.MemoryStream)) MotionDatabaseFT.Load(entryStream); var SkeletonEntryAC = BoneDatabaseAC.Skeletons[0]; var SkeletonEntryFT = BoneDatabaseFT.Skeletons[0]; foreach (var filePath in files) { var motionset = new MotionSet(); if (!File.Exists(ac_path + "\\rob\\" + Path.GetFileName(filePath))) { if (!filePath.Contains("db")) { Logs.WriteLine("Processing " + Path.GetFileNameWithoutExtension(filePath)); string farcpath = filePath; using (var farcArchive = BinaryFile.Load <FarcArchive>(farcpath)) using (var entryStream = farcArchive.Open(farcArchive.Entries.First(), EntryStreamMode.MemoryStream)) motionset.Load(entryStream, SkeletonEntryFT, MotionDatabaseFT); { motionset.Save("temp", SkeletonEntryAC, MotionDatabaseAC); //motionset.Dispose(); FarcArchive newfarc = new FarcArchive(); newfarc.Add(Path.GetFileNameWithoutExtension(filePath) + ".bin", "temp"); newfarc.Save(ac_path + "\\rob\\" + Path.GetFileName(filePath)); } } } } } }
public MotionController GetController(SkeletonEntry skeletonEntry = null, MotionDatabase motionDatabase = null) { if (mController != null) { return(mController); } if (skeletonEntry == null) { throw new ArgumentNullException(nameof(skeletonEntry)); } var controller = new MotionController(this); int index = 0; foreach (var boneInfo in BoneInfos) { if (motionDatabase != null && boneInfo.Id >= motionDatabase.BoneNames.Count) { break; } boneInfo.Name = boneInfo.Name ?? motionDatabase?.BoneNames[boneInfo.Id] ?? throw new ArgumentNullException(nameof(motionDatabase)); var boneEntry = skeletonEntry.GetBoneEntry(boneInfo.Name); var keyController = new KeyController { Name = boneInfo.Name }; if (boneEntry != null) { if (boneEntry.Type != BoneType.Rotation) { keyController.Position = new KeySetVector { X = KeySets[index++], Y = KeySets[index++], Z = KeySets[index++], } } ; if (boneEntry.Type != BoneType.Position) { keyController.Rotation = new KeySetVector { X = KeySets[index++], Y = KeySets[index++], Z = KeySets[index++], } } ; } else if (!skeletonEntry.BoneNames2.Contains(boneInfo.Name)) { keyController.Position = new KeySetVector { X = KeySets[index++], Y = KeySets[index++], Z = KeySets[index++], } } ; controller.KeyControllers.Add(keyController); } return(mController = controller); }
public void Update(SkeletonEntry skeletonEntry, MotionDatabase motionDatabase = null) { Parent.KeySets.Clear(); Parent.BoneInfos.Clear(); var keyControllers = skeletonEntry.BoneNames2 .Select(x => { var keyController = KeyControllers .FirstOrDefault(y => y.Name.Equals(x, StringComparison.OrdinalIgnoreCase)); if (keyController == null) { keyController = new KeyController(); } keyController.Name = x; return(keyController); }) .Concat(KeyControllers .Where(x => x.Name.Equals("gblctr", StringComparison.OrdinalIgnoreCase) || x.Name.Equals("kg_ya_ex", StringComparison.OrdinalIgnoreCase)) .OrderBy(x => x.Name)) .Where(x => motionDatabase == null || motionDatabase.BoneNames.Contains(x.Name, StringComparer.OrdinalIgnoreCase)); foreach (var keyController in keyControllers) { var boneEntry = skeletonEntry.GetBoneEntry(keyController.Name); if (boneEntry != null) { if (boneEntry.Type != BoneType.Rotation) { Parent.KeySets.Add(keyController.Position?.X ?? new KeySet()); Parent.KeySets.Add(keyController.Position?.Y ?? new KeySet()); Parent.KeySets.Add(keyController.Position?.Z ?? new KeySet()); } if (boneEntry.Type != BoneType.Position) { Parent.KeySets.Add(keyController.Rotation?.X ?? new KeySet()); Parent.KeySets.Add(keyController.Rotation?.Y ?? new KeySet()); Parent.KeySets.Add(keyController.Rotation?.Z ?? new KeySet()); } } else if (!skeletonEntry.BoneNames2.Contains(keyController.Name)) { Parent.KeySets.Add(keyController.Position?.X ?? new KeySet()); Parent.KeySets.Add(keyController.Position?.Y ?? new KeySet()); Parent.KeySets.Add(keyController.Position?.Z ?? new KeySet()); } Parent.BoneInfos.Add(new BoneInfo { Name = keyController.Name, Id = motionDatabase?.BoneNames?.IndexOf(keyController.Name) ?? -1, }); } Parent.KeySets.Add(new KeySet()); }
public static void Convert(string path, string acpath, string mot_db, divamodgen divamods) { if (Directory.Exists(path + "temp")) { Directory.Delete(path + "temp", true); } if (Directory.Exists(path + "temp2")) { Directory.Delete(path + "temp2", true); } if (Directory.Exists(acpath + "\\rom\\rob_temp")) { Directory.Delete(acpath + "\\rom\\rob_temp", true); } Directory.CreateDirectory(path + "temp"); Directory.CreateDirectory(path + "temp2"); Directory.CreateDirectory(acpath + "\\rom\\rob_temp"); MotionDatabase acmot = new MotionDatabase(); BoneDatabase acbone = new BoneDatabase(); acbone.Load(acpath + "\\rom\\bone_data.bin"); var skeletonEntry = acbone.Skeletons[0]; using (var farcArchive = BinaryFile.Load <FarcArchive>(mot_db)) using (var entryStream = farcArchive.Open(farcArchive.Entries.First(), EntryStreamMode.MemoryStream)) acmot.Load(entryStream); foreach (string file in Directory.EnumerateFiles(path, "mot_pv*.farc", SearchOption.TopDirectoryOnly)) { Tools.Extract(file, path + "temp\\"); //Console.WriteLine("Extracted " + Path.GetFileName(file)); } var maxid = acmot.MotionSets.Max(c => c.Id); var maxid2 = -1; foreach (var i in acmot.MotionSets) { if (i.Id > maxid2) { maxid2 = i.Id; } } foreach (string file in Directory.EnumerateFiles(path + "temp", "*p1_00.mot", SearchOption.AllDirectories)) { Directory.CreateDirectory(path + "temp2\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)); var moti = CombineBone(path, file, path + "temp2\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "_p1.mot"); MotionSet motion = new MotionSet(); if (File.Exists(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin")) { motion.Load(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin"); } motion.Motions.Add(moti); if (!Directory.Exists(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3))) { Directory.CreateDirectory(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)); } motion.Save(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin", skeletonEntry, acmot); maxid++; maxid2++; var check = acmot.MotionSets.Where(c => c.Name == "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)).FirstOrDefault(); if (check == null) { var motset = new MotionSetEntry(); motset.Name = "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3); motset.Id = maxid + 1; acmot.MotionSets.Add(motset); check = acmot.MotionSets.Where(c => c.Name == "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)).First(); } var motentry = new MotionEntry(); motentry.Id = maxid2 + 1; motentry.Name = "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "_P1"; check.Motions.Add(motentry); int pvid = int.Parse(Path.GetFileNameWithoutExtension(file).Substring(2, 3)); var check2 = divamods.Divamods.Where(c => c.pvid == pvid).FirstOrDefault(); if (check2 == null) { divamods.Divamods.Add(new pdaconversion.divamods(pvid)); Logs.WriteLine("Motion: Created new PV at id " + (pvid)); check2 = divamods.Divamods.Where(c => c.pvid == pvid).First(); } Console.WriteLine("Converted " + Path.GetFileName(file)); GC.Collect(); GC.WaitForPendingFinalizers(); } foreach (string file in Directory.EnumerateFiles(path + "temp", "*p2_00.mot", SearchOption.AllDirectories)) { Directory.CreateDirectory(path + "temp2\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)); var moti = CombineBone(path, file, path + "temp2\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "_p2.mot"); MotionSet motion = new MotionSet(); if (File.Exists(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin")) { motion.Load(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin"); } motion.Motions.Add(moti); if (!Directory.Exists(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3))) { Directory.CreateDirectory(acpath + "\\rom\\rob_temp\\" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)); } motion.Save(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin", skeletonEntry, acmot); Console.WriteLine("Converted " + Path.GetFileName(file)); maxid++; maxid2++; var check = acmot.MotionSets.Where(c => c.Name == "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)).FirstOrDefault(); if (check == null) { var motset = new MotionSetEntry(); motset.Name = "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3); motset.Id = maxid; acmot.MotionSets.Add(motset); check = acmot.MotionSets.Where(c => c.Name == "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)).First(); } var motentry = new MotionEntry(); motentry.Id = maxid2; motentry.Name = "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "_P2"; check.Motions.Add(motentry); int pvid = int.Parse(Path.GetFileNameWithoutExtension(file).Substring(2, 3)); var check2 = divamods.Divamods.Where(c => c.pvid == pvid).FirstOrDefault(); if (check2 == null) { divamods.Divamods.Add(new pdaconversion.divamods(pvid)); Logs.WriteLine("Motion: Created new PV at id " + (pvid)); check2 = divamods.Divamods.Where(c => c.pvid == pvid).First(); //check2.duet = true; } check2.duet = true; GC.Collect(); GC.WaitForPendingFinalizers(); } foreach (string file in Directory.EnumerateFiles(path + "temp", "*p3_00.mot", SearchOption.AllDirectories)) { Directory.CreateDirectory(path + "temp2\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)); var moti = CombineBone(path, file, path + "temp2\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "_p3.mot"); MotionSet motion = new MotionSet(); if (File.Exists(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin")) { motion.Load(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin"); } motion.Motions.Add(moti); if (!Directory.Exists(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3))) { Directory.CreateDirectory(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)); } motion.Save(acpath + "\\rom\\rob_temp\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "\\mot_PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + ".bin", skeletonEntry, acmot); Console.WriteLine("Converted " + Path.GetFileName(file)); maxid++; maxid2++; var check = acmot.MotionSets.Where(c => c.Name == "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)).FirstOrDefault(); if (check == null) { var motset = new MotionSetEntry(); motset.Name = "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3); motset.Id = maxid; acmot.MotionSets.Add(motset); check = acmot.MotionSets.Where(c => c.Name == "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3)).First(); } var motentry = new MotionEntry(); motentry.Id = maxid2; motentry.Name = "PV" + Path.GetFileNameWithoutExtension(file).Substring(2, 3) + "_P3"; check.Motions.Add(motentry); GC.Collect(); GC.WaitForPendingFinalizers(); } Directory.CreateDirectory(acpath + "\\rom\\rob_temp\\mot_db"); acmot.Save(acpath + "\\rom\\rob_temp\\mot_db\\mot_db.bin"); Console.WriteLine("Packing farcs..."); Tools.MassPackFolders(acpath + "\\rom\\rob_temp", acpath + "\\rom\\rob\\"); GC.Collect(); GC.WaitForPendingFinalizers(); }