private float GetWrapFrame(float frame) { var lastFrame = KeyFrames.Last().Frame; if (WrapMode == STLoopMode.Clamp) { if (frame > lastFrame) { return(lastFrame); } else { return(frame); } } else if (WrapMode == STLoopMode.Repeat) { while (frame > lastFrame) { frame -= lastFrame; } return(frame); } return(frame); }
public override float GetFrameValue(float frame, float startFrame = 0) { if (InterpolationType == STInterpoaltionType.Constant) { return(Constant); } if (KeyFrames.Count == 0) { return(0); } if (KeyFrames.Count == 1) { return(KeyFrames[0].Value); } STKeyFrame LK = KeyFrames.First(); STKeyFrame RK = KeyFrames.Last(); float Frame = frame - startFrame; foreach (STKeyFrame keyFrame in KeyFrames) { if (keyFrame.Frame <= Frame) { LK = keyFrame; } if (keyFrame.Frame >= Frame && keyFrame.Frame < RK.Frame) { RK = keyFrame; } } if (LK.Frame != RK.Frame) { float FrameDiff = Frame - LK.Frame; float Weight = FrameDiff / (RK.Frame - LK.Frame); switch (InterpolationType) { case STInterpoaltionType.Constant: return(LK.Value); case STInterpoaltionType.Step: return(LK.Value); case STInterpoaltionType.Linear: return(InterpolationHelper.Lerp(LK.Value, RK.Value, Weight)); case STInterpoaltionType.Bezier: { return(InterpolationHelper.Lerp(LK.Value, RK.Value, Weight)); STBezierKeyFrame bezierKeyLK = (STBezierKeyFrame)LK; STBezierKeyFrame bezierKeyRK = (STBezierKeyFrame)RK; float length = RK.Frame - LK.Frame; return(InterpolationHelper.BezierInterpolate(frame, bezierKeyLK.Frame, bezierKeyRK.Frame, bezierKeyLK.SlopeIn, bezierKeyRK.SlopeOut, bezierKeyLK.Value, bezierKeyRK.Value)); } case STInterpoaltionType.Hermite: { STHermiteKeyFrame hermiteKeyLK = (STHermiteKeyFrame)LK; STHermiteKeyFrame hermiteKeyRK = (STHermiteKeyFrame)RK; float length = RK.Frame - LK.Frame; return(InterpolationHelper.HermiteInterpolate(frame, hermiteKeyLK.Frame, hermiteKeyRK.Frame, hermiteKeyLK.TangentIn, hermiteKeyLK.TangentOut, hermiteKeyLK.Value, hermiteKeyRK.Value)); } } } return(LK.Value); }