Vixen
02b45cc4
csharp
public sealed class Spline

A path through space: control points, cubic segments between them, and an arc length.

Read the guide page for this →

Remarks

One spline, two consumers, and that is why it is here rather than in either of them. [docs/plan/26] wanted one for a camera dolly and declined to invent it, because "it would make it the second spline in the engine the moment anything else needs one"; [docs/plan/31 § T8] is that moment, for roads and rivers that deform a terrain. A curve is arithmetic and both callers already reference this assembly, so it costs no new project reference in either direction.

Cubic Hermite, because it is the form whose control points are on the curve. A Bézier's handles are not points of the path, so an author dragging one is not dragging the road; a B-spline's are not either. Hermite is the same family of curves with the parameterisation an editor wants — and a Catmull-Rom is exactly this with the tangents computed, which is what SmoothTangents does.

⚠ The parameter is not distance, and confusing the two is the classic bug in this type. Evaluate takes a segment-space parameter, where an integer is a control point; a camera moving at a constant parameter rate speeds up through wide-open segments and crawls through tight ones. EvaluateAtDistance is the one that moves at a constant speed, and it costs a table lookup.

Fields and properties (6)

  • public const int SamplesPerSegment

    How many pieces each segment is measured in when building the length table.

  • public ReadOnlySpan<SplinePoint> Points

    The control points, in order.

  • public bool IsClosed

    Whether the last point joins back to the first.

  • public int SegmentCount

    How many cubic segments there are.

  • public float MaxParameter

    The largest parameter Evaluate accepts.

  • public float Length

    How long the curve is, in the units its positions are in.

Methods (8)

  • public Spline(ReadOnlySpan<SplinePoint> controlPoints, bool closed = false)

    Builds a spline through control points.

  • public Vector3 Evaluate(float t)

    Where the curve is at a parameter.

  • public Vector3 Tangent(float t)

    Which way the curve is heading at a parameter.

  • public SplineFrame FrameAt(float t, Vector3 worldUp)

    The full orientation at a parameter: where, which way, and which way is up.

  • public float ParameterAtDistance(float distance)

    The parameter at which the curve has travelled a distance.

  • public Vector3 EvaluateAtDistance(float distance)

    Where the curve is after travelling a distance along it.

  • public float DistanceTo(Vector3 target, out float parameter)

    The point of the curve nearest to a place.

  • public static SplinePoint[] SmoothTangents(ReadOnlySpan<Vector3> positions, bool closed = false, float tension = 0)

    Catmull-Rom tangents for positions, so a path through points can be authored as points.

Used by (12)

  • ISplineSourceVixen.Core.Mathematics
  • SplineAssetVixen.Core.Mathematics
  • SplineAssetTestsVixen.Core.Mathematics.Tests
  • SplineTestsVixen.Core.Mathematics.Tests
  • TerrainSplineVixen.Terrain
  • TerrainSplineTestsVixen.Terrain.Tests
  • TrackedDollyTestsVixen.Engine.Tests
  • TracksVixen.Engine.Tests
  • VirtualCameraSystemVixen.Engine
  • SplineEditVixen.Editor.SceneView
  • SplineOverlayVixen.Editor.SceneView
  • TerrainModuleVixen.Editor.Terrain