-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a208564
commit 637b999
Showing
3 changed files
with
47 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace ArtNet.Editor | ||
{ | ||
public static class KeyFrameReducer | ||
{ | ||
public static List<KeyFrameData> Reduce(List<KeyFrameData> keyFrameData) | ||
{ | ||
if (keyFrameData.Count <= 2) return keyFrameData; | ||
|
||
var newDmxFrameData = new List<KeyFrameData> { keyFrameData[0] }; | ||
var latest = keyFrameData[0]; | ||
|
||
for (var i = 1; i < keyFrameData.Count - 1; i++) | ||
{ | ||
var current = keyFrameData[i]; | ||
var next = keyFrameData[i + 1]; | ||
if (IsOmittedFrame(latest, current, next)) continue; | ||
|
||
newDmxFrameData.Add(current); | ||
latest = current; | ||
} | ||
|
||
newDmxFrameData.Add(keyFrameData[^1]); | ||
return newDmxFrameData; | ||
} | ||
|
||
private static bool IsOmittedFrame( | ||
KeyFrameData prev, | ||
KeyFrameData current, | ||
KeyFrameData next, | ||
float tolerance = 0.01f) | ||
{ | ||
var prevDiffValue = current.Value - prev.Value; | ||
var prevDiffTime = current.Time - prev.Time; | ||
var nextDiffValue = next.Value - current.Value; | ||
var nextDiffTime = next.Time - current.Time; | ||
|
||
return Math.Abs(prevDiffValue / prevDiffTime - nextDiffValue / nextDiffTime) <= tolerance; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.