Vector2 GetXYAtTime(TranslateTimeline timeline, float time) { const int ENTRIES = 3; const int PREV_TIME = -3, PREV_X = -2, PREV_Y = -1; const int X = 1, Y = 2; float x, y; float[] frames = timeline.Frames; if (time < frames[0]) { return(new Vector2(0, 0)); } if (time >= frames[frames.Length - ENTRIES]) { x = frames[frames.Length + PREV_X]; y = frames[frames.Length + PREV_Y]; return(new Vector2(x, y)); } //보간 int frame = Spine.Animation.BinarySearch(frames, time, ENTRIES); float prevX = frames[frame + PREV_X]; float prevY = frames[frame + PREV_Y]; float frameTime = frames[frame]; float percent = timeline.GetCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); x = prevX + (frames[frame + X] - prevX) * percent; y = prevY + (frames[frame + Y] - prevY) * percent; return(new Vector2(x, y)); }
/// <summary>Evaluates the resulting value of a TranslateTimeline at a given time. /// SkeletonData can be accessed from Skeleton.Data or from SkeletonDataAsset.GetSkeletonData. /// If no SkeletonData is given, values are computed relative to setup pose instead of local-absolute.</summary> public static Vector2 Evaluate(this TranslateTimeline timeline, float time, SkeletonData skeletonData = null) { const int PREV_TIME = -3, PREV_X = -2, PREV_Y = -1; const int X = 1, Y = 2; var frames = timeline.frames; if (time < frames[0]) { return(Vector2.zero); } float x, y; if (time >= frames[frames.Length - TranslateTimeline.ENTRIES]) // Time is after last frame. { x = frames[frames.Length + PREV_X]; y = frames[frames.Length + PREV_Y]; } else { // Interpolate between the previous frame and the current frame. int frame = Animation.BinarySearch(frames, time, TranslateTimeline.ENTRIES); x = frames[frame + PREV_X]; y = frames[frame + PREV_Y]; float frameTime = frames[frame]; float percent = timeline.GetCurvePercent(frame / TranslateTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); x += (frames[frame + X] - x) * percent; y += (frames[frame + Y] - y) * percent; } Vector2 xy = new Vector2(x, y); if (skeletonData == null) { return(xy); } else { var boneData = skeletonData.bones.Items[timeline.boneIndex]; return(xy + new Vector2(boneData.x, boneData.y)); } }
/// <summary>Evaluates the resulting value of a TranslateTimeline at a given time. /// SkeletonData can be accessed from Skeleton.Data or from SkeletonDataAsset.GetSkeletonData. /// If no SkeletonData is given, values are computed relative to setup pose instead of local-absolute.</summary> public static Vector2 Evaluate(this TranslateTimeline tt, float time, SkeletonData skeletonData = null) { const int PREV_TIME = -3, PREV_X = -2, PREV_Y = -1; const int X = 1, Y = 2; var frames = tt.Frames; if (time < frames[0]) { return(Vector2.zero); } float x, y; if (time >= frames[frames.Length - TranslateTimeline.ENTRIES]) { // Time is after last frame. x = frames[frames.Length + PREV_X]; y = frames[frames.Length + PREV_Y]; } else { int frame = Animation.BinarySearch(frames, time, TranslateTimeline.ENTRIES); x = frames[frame + PREV_X]; y = frames[frame + PREV_Y]; float frameTime = frames[frame]; float percent = tt.GetCurvePercent(frame / TranslateTimeline.ENTRIES - 1, 1 - (time - frameTime) / (frames[frame + PREV_TIME] - frameTime)); x += (frames[frame + X] - x) * percent; y += (frames[frame + Y] - y) * percent; } Vector2 o = new Vector2(x, y); if (skeletonData == null) { return(o); } else { var boneData = skeletonData.Bones.Items[tt.BoneIndex]; return(o + new Vector2(boneData.X, boneData.Y)); } }