public static AnimationClip ReSample(GameSkeleton skeleton, AnimationClip newAnim, int newFrameCount, float playTime) { var output = newAnim.Clone(); output.DynamicFrames.Clear(); var fraction = 1.0f / (newFrameCount - 1); for (int i = 0; i < newFrameCount; i++) { float t = i * fraction; var keyframe = AnimationSampler.Sample(t, skeleton, new List <AnimationClip> { newAnim }); KeyFrame newKeyFrame = new KeyFrame(); for (int mappingIndex = 0; mappingIndex < output.RotationMappings.Count; mappingIndex++) { var mapping = output.RotationMappings[mappingIndex]; if (mapping.HasValue) { newKeyFrame.Rotation.Add(keyframe.BoneTransforms[mappingIndex].Rotation); } } for (int mappingIndex = 0; mappingIndex < output.TranslationMappings.Count; mappingIndex++) { var mapping = output.TranslationMappings[mappingIndex]; if (mapping.HasValue) { newKeyFrame.Position.Add(keyframe.BoneTransforms[mappingIndex].Translation); } } output.DynamicFrames.Add(newKeyFrame); } output.PlayTimeInSec = playTime;// (output.DynamicFrames.Count() - 1) / 20.0f; return(output); }
void UpdateAnimationFrame() { if (IsEnabled == false) { _currentAnimFrame = null; return; } float sampleT = 0; float animationLengthMs = GetAnimationLengthMs(); if (animationLengthMs != 0) { sampleT = (float)(_timeSinceStart.TotalMilliseconds / animationLengthMs); } _currentAnimFrame = AnimationSampler.Sample(sampleT, _skeleton, _animationClips); if (_skeleton != null) { _skeleton.Update(); } }