Skip to content

Commit

Permalink
value が同一の場合のみフレームを削除する
Browse files Browse the repository at this point in the history
  • Loading branch information
nasshu2916 committed Nov 16, 2024
1 parent 637b999 commit 360bfec
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions Assets/ArtNet/Editor/KeyFrameReducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public static List<KeyFrameData> Reduce(List<KeyFrameData> keyFrameData)
for (var i = 1; i < keyFrameData.Count - 1; i++)
{
var current = keyFrameData[i];
var next = keyFrameData[i + 1];
if (IsOmittedFrame(latest, current, next)) continue;
if (latest.Value == current.Value) continue;

newDmxFrameData.Add(current);
latest = current;
Expand All @@ -25,19 +24,5 @@ public static List<KeyFrameData> Reduce(List<KeyFrameData> keyFrameData)
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;
}
}
}

0 comments on commit 360bfec

Please sign in to comment.