Vixen
02b45cc4
csharp
public static class CurveEvaluation

Sampling a keyed curve. The one implementation of the tangent convention.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Cubic Hermite between neighbours, which is what every animation system in this shape uses and what makes a tangent mean what an artist expects: the slope at the key. Bézier control points are the same curve wearing different numbers, and the conversion is a third of the interval — but slopes are what survive a key being dragged sideways.

⚠ Outside the first and last key the curve holds rather than extrapolating. A cubic extrapolated past its last key runs off to infinity within a second or two, and an animation that was sampled one frame past its end would send whatever it drives into the next county. Clamping is the boring answer and the right one.

Why this is here and not beside either of its callers. Two things sample these curves: the editor's AnimationCurve control, which is mutable and raises events because a person is dragging its keys, and the bake that turns an authored clip into the sampled channels a runtime plays. They cannot share a key type — one is a class with setters and the other is a serialised record — but they must share the arithmetic, because a curve that reads one way in the editor and another in the build is a bug nobody can see until it ships. So the shape is a static function over a span, and both callers project their own keys into it.

⚠ Keys are assumed to be in time order. Both callers sort on edit rather than on read — an editor because it re-sorts when a key is dragged past its neighbour, a bake because the times came out of a SortedSet. Sorting here would turn every sample into an allocation and hide the caller that forgot.

Methods (2)

  • public static float Evaluate(ReadOnlySpan<CurveSample> keys, float time)

    The value at a time.

  • public static (float Outgoing, float Incoming) Slopes(ReadOnlySpan<CurveSample> keys, int index)

    The two slopes that actually govern a segment, after the modes have had their say.

Used by (2)

  • AnimationCurveVixen.Ui.Controls.Advanced
  • AnimationClipAssetVixen.Editor.Assets