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()); }