Skip to content

Commit

Permalink
Added "ensure keyframe" utility method for keyframe class
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin113D committed Jan 26, 2024
1 parent 183e845 commit 71cd821
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/SA3D.Modeling/Animation/Keyframes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,48 @@ void Ensure<T>(SortedDictionary<uint, T> keyframes, KeyframeAttributes type, T v
Ensure(Scale, KeyframeAttributes.Scale, node.Scale);
}

/// <summary>
/// Ensures that specified keyframe types have start- and end-frames
/// </summary>
/// <param name="targets">Keyframe types to target.</param>
/// <param name="endFrame">The frame until which keyframes need to exist.</param>
public void EnsureKeyframes(KeyframeAttributes targets, uint endFrame)
{
void Ensure<T>(SortedDictionary<uint, T> keyframes, KeyframeAttributes type, T value)
{
if(!targets.HasFlag(type))
{
return;
}

if(!keyframes.ContainsKey(0))
{
keyframes.Add(0, value);
}

if(keyframes.Keys.Max() < endFrame)
{
keyframes.Add(endFrame, value);
}
}

Ensure(Position, KeyframeAttributes.Position, Vector3.Zero);
Ensure(EulerRotation, KeyframeAttributes.EulerRotation, Vector3.Zero);
Ensure(Scale, KeyframeAttributes.Scale, Vector3.One);
Ensure(Vector, KeyframeAttributes.Vector, default);
Ensure(Vertex, KeyframeAttributes.Vertex, new LabeledArray<Vector3>(0));
Ensure(Normal, KeyframeAttributes.Normal, new LabeledArray<Vector3>(0));
Ensure(Target, KeyframeAttributes.Target, Vector3.Zero);
Ensure(Roll, KeyframeAttributes.Roll, 0);
Ensure(Angle, KeyframeAttributes.Angle, 0);
Ensure(LightColor, KeyframeAttributes.LightColor, default);
Ensure(Intensity, KeyframeAttributes.Intensity, default);
Ensure(Spot, KeyframeAttributes.Spot, default);
Ensure(Point, KeyframeAttributes.Point, default);
Ensure(QuaternionRotation, KeyframeAttributes.QuaternionRotation, Quaternion.Identity);

}


/// <summary>
/// Writes the keyframe set to an endian stack writer.
Expand Down
3 changes: 2 additions & 1 deletion src/SA3D.Modeling/PublicAPI/net7.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SA3D.Modeling.Structs.BAMSFHelper
SA3D.Modeling.Animation.Keyframes.EnsureKeyframes(SA3D.Modeling.Animation.KeyframeAttributes targets, uint endFrame) -> void
SA3D.Modeling.Structs.BAMSFHelper
SA3D.Modeling.Structs.FloatIOType.BAMS16F = 5 -> SA3D.Modeling.Structs.FloatIOType
SA3D.Modeling.Structs.FloatIOType.BAMS32F = 6 -> SA3D.Modeling.Structs.FloatIOType
static readonly SA3D.Modeling.Structs.BAMSFHelper.BAMSF2Deg -> float
Expand Down

0 comments on commit 71cd821

Please sign in to comment.