Skip to main content

Function: buildTerrainCurve()

buildTerrainCurve(controlPoints, samplesPerSegment): TerrainCurvePoint[]

Defined in: rendering/terrain/terrain-curve.ts:56

Builds a smooth curve through controlPoints, using a Catmull-Rom spline (converted to an equivalent sequence of cubic Beziers, one per segment, via the standard Bn = Pn +/- (Pn+1 - Pn-1) / 6 tangent construction) so the curve passes exactly through every control point with a continuous tangent, rather than a straight-line polyline between them. Densely sampling that curve turns a handful of sparse control points into a long, natural-looking silhouette suitable for both a TerrainShape's collision points and a matching render mesh (see createTerrainMesh) - the same points can drive both, so what's drawn always matches what's touched.

Parameters

controlPoints

readonly Vector2[]

The sparse anchor points the curve passes through, ordered by strictly increasing x. Must contain at least 2 points.

samplesPerSegment

number

How many points to sample along each segment between two consecutive control points.

Returns

TerrainCurvePoint[]

A dense polyline approximating the smooth curve, with each point's cumulative arc length from the start.

Throws

An error if fewer than 2 control points are provided.