public void ReplaceAnimation(WorkspaceAnimation animation, Animator animator, int id, int overrideIndex, int resampleCount, bool linear, bool EulerFilter, double filterPrecision, string method, int insertPos, bool negateQuaternions, double filterTolerance) { AnimationClip clip = Parser.m_AnimationClips[id].instance; if (overrideIndex >= 0) { AnimatorOverrideController animatorOverride = (AnimatorOverrideController)Parser.file.Components[overrideIndex]; clip = GetOverrideClip(clip, animatorOverride); } var replaceMethod = (ReplaceAnimationMethod)Enum.Parse(typeof(ReplaceAnimationMethod), method); Operations.ReplaceAnimation(animation, animator, clip, resampleCount, linear, EulerFilter, (float)filterPrecision, replaceMethod, insertPos, negateQuaternions, (float)filterTolerance); uint clipNameID = Animator.StringToHash(clip.m_Name); for (int i = 0; i < Parser.m_Controller.m_StateMachineArray.Length; i++) { StateMachineConstant stateMachine = Parser.m_Controller.m_StateMachineArray[i]; for (int j = 0; j < stateMachine.m_StateConstantArray.Count; j++) { StateConstant state = stateMachine.m_StateConstantArray[j]; if (state.m_NameID == clipNameID) { state.m_Speed = 1; i = Parser.m_Controller.m_StateMachineArray.Length; break; } } } Changed = true; }
public static void ReplaceAnimation(WorkspaceAnimation wsAnimation, odfParser parser, int resampleCount, bool linear, ReplaceAnimationMethod replaceMethod, string clip, int insertPos, bool negateQuaternionFlips) { if (parser.AnimSection == null) { Report.ReportLog(Path.GetFileName(parser.ODFPath) + " doesn't have an animation section. Skipping this animation"); return; } if (!(wsAnimation.importedAnimation is ImportedKeyframedAnimation)) { Report.ReportLog("The animation has incompatible keyframes."); return; } Report.ReportLog("Replacing animation ..."); List <KeyValuePair <string, ImportedAnimationKeyframe[]> > newTrackList = FbxUtility.CopyKeyframedAnimation(wsAnimation, resampleCount, linear); List <odfTrack> animationNodeList = odf.FindClip(clip, parser).ChildList; ImportedKeyframedAnimation iAnim = new ImportedKeyframedAnimation(); iAnim.TrackList = new List <ImportedAnimationKeyframedTrack>(animationNodeList.Count); Dictionary <string, ImportedAnimationKeyframedTrack> animationNodeDic = null; if (replaceMethod != ReplaceAnimationMethod.Replace) { animationNodeDic = new Dictionary <string, ImportedAnimationKeyframedTrack>(); foreach (odfTrack animationNode in animationNodeList) { ImportedAnimationKeyframedTrack iTrack = new ImportedAnimationKeyframedTrack(); iTrack.Name = odf.FindFrame(animationNode.BoneFrameId, parser.FrameSection.RootFrame).Name; iTrack.Keyframes = Plugins.ODFConverter.ConvertTrack(animationNode.KeyframeList); animationNodeDic.Add(odf.FindFrame(animationNode.BoneFrameId, parser.FrameSection.RootFrame).Name, iTrack); iAnim.TrackList.Add(iTrack); } } foreach (var newTrack in newTrackList) { ImportedAnimationKeyframe[] keyframes = newTrack.Value; Quaternion q = keyframes[0].Rotation; keyframes[0].Rotation *= -1; /* if (keyframes[0].Rotation.Angle == 0 || q.Angle == 0) * { * Report.ReportLog("track " + newTrack.Key + " r=" + keyframes[0].Rotation.Angle + " q=" + q.Angle); * }*/ } FbxUtility.ReplaceAnimation(replaceMethod, insertPos, newTrackList, iAnim, animationNodeDic, negateQuaternionFlips); animationNodeList.Clear(); foreach (var newTrack in iAnim.TrackList) { ImportedAnimationKeyframe[] keyframes = ((ImportedAnimationKeyframedTrack)newTrack).Keyframes; odfTrack animationNode = new odfTrack(keyframes.Length); odf.CreateUnknowns(animationNode); animationNodeList.Add(animationNode); animationNode.KeyframeList = Plugins.ODFConverter.ConvertTrack(keyframes); animationNode.BoneFrameId = odf.FindFrame(newTrack.Name, parser.FrameSection.RootFrame).Id; } }
public void ReplaceAnimation(WorkspaceAnimation animation, Animator animator, int id, int resampleCount, bool linear, bool EulerFilter, double filterPrecision, string method, int insertPos, bool negateQuaternions, double filterTolerance) { AnimationClip clip = id < 0 ? Parser.m_Animation.instance : Parser.m_Animations[id].instance; var replaceMethod = (ReplaceAnimationMethod)Enum.Parse(typeof(ReplaceAnimationMethod), method); Operations.ReplaceAnimation(animation, animator, clip, resampleCount, linear, EulerFilter, (float)filterPrecision, replaceMethod, insertPos, negateQuaternions, (float)filterTolerance); Changed = true; }
public static void ReplaceAnimation(WorkspaceAnimation wsAnimation, List <ImportedFrame> wsSkeleton, reaParser parser, int resampleCount, bool linear, ReplaceAnimationMethod replaceMethod, int insertPos, bool negateQuaternionFlips) { Report.ReportLog("Replacing animation ..."); List <KeyValuePair <string, ImportedAnimationSampledTrack> > newTrackList = FbxUtility.CopySampledAnimation(wsAnimation, resampleCount, linear); reaANICsection animationNodeList = parser.ANIC; ImportedSampledAnimation iAnim = new ImportedSampledAnimation(); iAnim.TrackList = new List <ImportedAnimationSampledTrack>(animationNodeList.Count); Dictionary <string, ImportedAnimationSampledTrack> animationNodeDic = null; if (replaceMethod != ReplaceAnimationMethod.Replace) { animationNodeDic = new Dictionary <string, ImportedAnimationSampledTrack>(); foreach (reaAnimationTrack animationNode in animationNodeList) { ImportedFrame boneFrame = ImportedHelpers.FindFrame(animationNode.boneFrame, wsSkeleton[0]); bool isTopFrame = boneFrame != null && boneFrame.Parent == wsSkeleton[0]; ImportedAnimationSampledTrack iTrack = Plugins.REMConverter.ConvertTrack(animationNode, isTopFrame); iTrack.Name = animationNode.boneFrame; animationNodeDic.Add(animationNode.boneFrame, iTrack); iAnim.TrackList.Add(iTrack); } } FbxUtility.ReplaceAnimation(replaceMethod, insertPos, newTrackList, iAnim, animationNodeDic, negateQuaternionFlips); animationNodeList.ChildList.Clear(); foreach (var newTrack in iAnim.TrackList) { ImportedFrame boneFrame = ImportedHelpers.FindFrame(newTrack.Name, wsSkeleton[0]); bool isTopFrame = boneFrame != null && boneFrame.Parent == wsSkeleton[0]; reaAnimationTrack animationNode = Plugins.REMConverter.ConvertTrack(newTrack, isTopFrame); animationNodeList.AddChild(animationNode); } }
public void ReplaceAnimation(WorkspaceAnimation animation, List <ImportedFrame> skeleton, int resampleCount, bool linear, string method, int insertPos, bool negateQuaternionFlips) { var replaceMethod = (ReplaceAnimationMethod)Enum.Parse(typeof(ReplaceAnimationMethod), method); ReplaceAnimation(animation, skeleton, Parser, resampleCount, linear, replaceMethod, insertPos, negateQuaternionFlips); }
public void ConvertAnimation(WorkspaceAnimation animation) { animation.SetAnimation(Plugins.REMConverter.ConvertAnimation((ImportedKeyframedAnimation)animation.importedAnimation)); }
private void ProcessDragDropAnimations(TreeNode node) { if (node.Tag is DragSource) { if ((node.Parent != null) && !node.Checked && node.StateImageIndex != (int)CheckState.Indeterminate) { return; } DragSource source = (DragSource)node.Tag; if (source.Type == typeof(WorkspaceAnimation)) { var srcEditor = (ImportedEditor)Gui.Scripting.Variables[source.Variable]; WorkspaceAnimation wsAnimation = srcEditor.Animations[(int)source.Id]; using (var dragOptions = new FormREADragDrop(Editor)) { int resampleCount = -1; if (wsAnimation.importedAnimation is ImportedKeyframedAnimation) { dragOptions.labelAnimationConvertion.Text = "\"" + node.Text + "\"" + dragOptions.labelAnimationConvertion.Text; dragOptions.labelAnimationConvertion.Visible = true; } else if (wsAnimation.importedAnimation is ImportedSampledAnimation) { List <ImportedAnimationSampledTrack> samTrackList = ((ImportedSampledAnimation)wsAnimation.importedAnimation).TrackList; int normalizeLength = samTrackList[0].Scalings.Length; foreach (ImportedAnimationSampledTrack track in samTrackList) { if (track.Scalings.Length != track.Rotations.Length || track.Rotations.Length != track.Translations.Length) { dragOptions.labelNormalizationWarning.Text = "\"" + node.Text + "\"" + dragOptions.labelNormalizationWarning.Text; dragOptions.labelNormalizationWarning.Visible = true; break; } } } dragOptions.numericResample.Value = resampleCount; dragOptions.comboBoxMethod.SelectedIndex = (int)ReplaceAnimationMethod.ReplacePresent; if (dragOptions.ShowDialog() == DialogResult.OK) { if (wsAnimation.importedAnimation is ImportedKeyframedAnimation) { Gui.Scripting.RunScript(EditorVar + ".ConvertAnimation(animation=" + source.Variable + ".Animations[" + (int)source.Id + "])"); FormWorkspace.UpdateAnimationNode(node, wsAnimation); } // repeating only final choices for repeatability of the script List <ImportedAnimationSampledTrack> trackList = ((ImportedSampledAnimation)wsAnimation.importedAnimation).TrackList; for (int i = 0; i < trackList.Count; i++) { ImportedAnimationTrack track = trackList[i]; if (!wsAnimation.isTrackEnabled(track)) { Gui.Scripting.RunScript(source.Variable + ".setTrackEnabled(animationId=" + (int)source.Id + ", id=" + i + ", enabled=false)"); } } Gui.Scripting.RunScript(EditorVar + ".ReplaceAnimation(animation=" + source.Variable + ".Animations[" + (int)source.Id + "], skeleton=" + source.Variable + ".Frames, resampleCount=" + dragOptions.numericResample.Value + ", linear=" + dragOptions.radioButtonInterpolationLinear.Checked + ", method=\"" + dragOptions.comboBoxMethod.SelectedItem + "\", insertPos=" + dragOptions.numericPosition.Value + ", negateQuaternionFlips=" + dragOptions.checkBoxNegateQuaternionFlips.Checked + ")"); UnloadREA(); LoadREA(); } } } } else { foreach (TreeNode child in node.Nodes) { ProcessDragDropAnimations(child); } } }