Skip to content

Commit

Permalink
[Animation] - Fixed bug in GorgonAnimationBuilder Build method where …
Browse files Browse the repository at this point in the history
…the last frame of an animation would have a display length of 0 seconds (i.e. it was skipped) when no animation length was passed to the method. The fix was to add a minimum frame length to the total length of the animation. However, this is not ideal in some cases, so passing the Length parameter for the animation is suggested.

[Graphics] - Fixed bug in CreateRenderTarget for GorgonRenderTarget2DView and GorgonRenderTarget3DView where a ReadWrite binding would be ignored.
  • Loading branch information
Tape-Worm committed Oct 31, 2023
1 parent 15894da commit c5dc13b
Show file tree
Hide file tree
Showing 3 changed files with 801 additions and 797 deletions.
26 changes: 15 additions & 11 deletions Gorgon/Gorgon.Animation/GorgonAnimationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,12 @@ public GorgonAnimationBuilder Delete2DTexture(string name)
/// <param name="fps">[Optional] The frames per second for the animation.</param>
/// <param name="length">[Optional] The length of the animation, in seconds.</param>
/// <returns>The object created or updated by this builder.</returns>
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="name"/> parameter is <b>null</b>.</exception>
/// <exception cref="ArgumentEmptyException">Thrown when the <paramref name="name"/> parameter is empty.</exception>
/// <remarks>
/// <para>
/// When the <paramref name="fps"/> parameter is omitted, it will default to 60 frames per second. This parameter is used to adjust the key frame times to fit within the specified frame delays
/// for the frames per second.
/// for the frames per second. If this value is less than 1, the animation will be assumed to be 1 frame per second.
/// </para>
/// <para>
/// When the <paramref name="length"/> parameter is omitted, the length of the animation will be calculated based on the key frame times present in the tracks. This may not be ideal for certain
Expand All @@ -595,6 +597,8 @@ public IGorgonAnimation Build(string name, float fps = 60, float? length = null)

fps = fps.Max(1);

float minFrameTime = 1.0f / fps;

// Function to adjust the key time to fit within the frames per second provided.
float AdjustKeyTime(float keyTime)
{
Expand Down Expand Up @@ -725,17 +729,17 @@ float AdjustKeyTime(float keyTime)
};
}

length ??= _singleTracks.SelectMany(item => item.Value.Keys.Cast<IGorgonKeyFrame>()).DefaultIfEmpty()
.Concat(_vector2Tracks.SelectMany(item => item.Value.Keys).DefaultIfEmpty())
.Concat(_vector3Tracks.SelectMany(item => item.Value.Keys).DefaultIfEmpty())
.Concat(_vector4Tracks.SelectMany(item => item.Value.Keys).DefaultIfEmpty())
.Concat(_quatTracks.SelectMany(item => item.Value.Keys).DefaultIfEmpty())
.Concat(_rectangleTracks.SelectMany(item => item.Value.Keys).DefaultIfEmpty())
.Concat(_colorTracks.SelectMany(item => item.Value.Keys).DefaultIfEmpty())
.Concat(_textureTracks.SelectMany(item => item.Value.Keys).DefaultIfEmpty())
.Max(item => item?.Time ?? 0);
length ??= (_singleTracks.SelectMany(item => item.Value.Keys.Cast<IGorgonKeyFrame>()).DefaultIfEmpty()
.Concat(_vector2Tracks.SelectMany(item => item.Value.Keys).DefaultIfEmpty())
.Concat(_vector3Tracks.SelectMany(item => item.Value.Keys).DefaultIfEmpty())
.Concat(_vector4Tracks.SelectMany(item => item.Value.Keys).DefaultIfEmpty())
.Concat(_quatTracks.SelectMany(item => item.Value.Keys).DefaultIfEmpty())
.Concat(_rectangleTracks.SelectMany(item => item.Value.Keys).DefaultIfEmpty())
.Concat(_colorTracks.SelectMany(item => item.Value.Keys).DefaultIfEmpty())
.Concat(_textureTracks.SelectMany(item => item.Value.Keys).DefaultIfEmpty())
.Max(item => item?.Time ?? 0)) + minFrameTime;

return new AnimationData(name, fps, length.Value.Max(1 / fps))
return new AnimationData(name, fps, length.Value.Max(minFrameTime))
{
SingleTracks = singles,
ColorTracks = color,
Expand Down
Loading

0 comments on commit c5dc13b

Please sign in to comment.