diff --git a/src/SA3D.Modeling/Animation/Keyframes.cs b/src/SA3D.Modeling/Animation/Keyframes.cs index df5e22d..c66ae34 100644 --- a/src/SA3D.Modeling/Animation/Keyframes.cs +++ b/src/SA3D.Modeling/Animation/Keyframes.cs @@ -295,6 +295,48 @@ void Ensure(SortedDictionary keyframes, KeyframeAttributes type, T v Ensure(Scale, KeyframeAttributes.Scale, node.Scale); } + /// + /// Ensures that specified keyframe types have start- and end-frames + /// + /// Keyframe types to target. + /// The frame until which keyframes need to exist. + public void EnsureKeyframes(KeyframeAttributes targets, uint endFrame) + { + void Ensure(SortedDictionary 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(0)); + Ensure(Normal, KeyframeAttributes.Normal, new LabeledArray(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); + + } + /// /// Writes the keyframe set to an endian stack writer. diff --git a/src/SA3D.Modeling/PublicAPI/net7.0/PublicAPI.Unshipped.txt b/src/SA3D.Modeling/PublicAPI/net7.0/PublicAPI.Unshipped.txt index 740d6ef..58cc49f 100644 --- a/src/SA3D.Modeling/PublicAPI/net7.0/PublicAPI.Unshipped.txt +++ b/src/SA3D.Modeling/PublicAPI/net7.0/PublicAPI.Unshipped.txt @@ -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