// // MotionObjectModel.cs - provides an ObjectModel for manipulating 3D animation data // // Author: // Michael Becker // // Copyright (c) 2013-2020 Mike Becker's Software // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . namespace UniversalEditor.ObjectModels.Multimedia3D.Motion { /// /// Provides an for manipulating 3D animation data. /// public class MotionObjectModel : ObjectModel { /// /// The name(s) of the model(s) which are compatible with this motion data. /// public System.Collections.Specialized.StringCollection CompatibleModelNames { get; } = new System.Collections.Specialized.StringCollection(); public MotionFrame.MotionFrameCollection Frames { get; } = new MotionFrame.MotionFrameCollection(); protected override ObjectModelReference MakeReferenceInternal() { ObjectModelReference omr = base.MakeReferenceInternal(); omr.Title = "Motion capture data"; omr.Path = new string[] { "Multimedia", "3D Multimedia", "Motion Capture Data" }; omr.Description = "Motion capture data that can be used to animate a model in 3D space."; return omr; } public override void Clear() { Frames.Clear(); } public override void CopyTo(ObjectModel destination) { MotionObjectModel clone = (destination as MotionObjectModel); foreach (MotionFrame frame in Frames) { clone.Frames.Add(frame.Clone() as MotionFrame); } } public void ReplaceBoneNames(string FindBoneName, string ReplaceBoneName) { foreach (MotionFrame frame in Frames) { foreach (MotionAction act in frame.Actions) { if (act is MotionBoneRepositionAction) { MotionBoneRepositionAction repos = (act as MotionBoneRepositionAction); if (repos.BoneName == FindBoneName) { repos.BoneName = ReplaceBoneName; } } } } } public void RemoveAllBoneReferences(string FindBoneName) { System.Collections.Generic.List framesToDelete = new System.Collections.Generic.List(); foreach (MotionFrame frame in Frames) { for (int i = 0; i < frame.Actions.Count; i++) { MotionBoneRepositionAction repos = (frame.Actions[i] as MotionBoneRepositionAction); if (repos != null) { if (repos.BoneName == FindBoneName) { frame.Actions.Remove(repos); i--; } } } if (frame.Actions.Count == 0) { framesToDelete.Add(frame); } } foreach (MotionFrame frame in framesToDelete) { Frames.Remove(frame); } } } }