1
0
mirror of synced 2024-12-04 20:08:00 +01:00
Switch-Toolbox/Switch_Toolbox_Library/Animations/AnimationRewrite/STAnimationTrack.cs
KillzXGaming a8e6d104f2 A few improvements.
Panes can now be selected and moved around.
Panes can be resized from corners or edges.
Improved hit detection for panes.
Mouse left click now selects and moves panes. Use middle mouse or hold shift + left mouse to pan/move camera.
More progress on timeline, but currently not functional so currently disabled atm.
Multiple layout animations can be selected and played at once. Goes to the highest amount of frames.
Start to impliment a parts manager. Will allow editing external layout and animation data, and saving back properly.
2019-10-05 13:25:28 -04:00

66 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Toolbox.Library.Animations
{
public class STAnimationTrack
{
public string Name { get; set; }
public STInterpoaltionType InterpolationType { get; set; }
public List<STKeyFrame> KeyFrames = new List<STKeyFrame>();
public bool HasKeys => KeyFrames.Count > 0;
public bool IsKeyed(float frame)
{
var matches = KeyFrames.Where(p => p.Frame == frame);
return matches != null && matches.Count() > 0;
}
//Key frame setup based on
//https://github.com/gdkchan/SPICA/blob/42c4181e198b0fd34f0a567345ee7e75b54cb58b/SPICA/Formats/CtrH3D/Animation/H3DFloatKeyFrameGroup.cs
public float GetFrameValue(float frame, float startFrame = 0)
{
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.Hermite:
return InterpolationHelper.Herp(
LK.Value, RK.Value,
LK.Slope, RK.Slope,
FrameDiff,
Weight);
}
}
return LK.Value;
}
}
}