astrochili/defold-operator/operator.bezier
Linear, quadratic and cubic bezier curves through vector or number points, with a uniform position along the curve's length. The Operator camera moves along these curves, and a project can use them for its own paths.
- GitHub: astrochili/defold-operator — pinned to
1.5.3- Pick a release from astrochili/defold-operator releases and add its Source code (zip) URL (or a packaged
.zipasset, if the library ships one) togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as bezier from "operator.bezier"
- Pick a release from astrochili/defold-operator releases and add its Source code (zip) URL (or a packaged
Functions
new(2 overloads)<P extendsVector3|Vector4>(points: P[], samples_count?: number, length_func?: (v: P) => number, lerp_func?: (t: number, a: P, b: P) => P):Bezier<P>(points: number[], samples_count: number | undefined, length_func: (v: number) => number, lerp_func?: (t: number, a: number, b: number) => number):Bezier<number>
position<P>(self:Bezier<P>, time: number): Puniform_position<P>(self:Bezier<P>, time: number): P
new(2 overloads)
<P extends Vector3 | Vector4>(points: P[], samples_count?: number, length_func?: (v: P) => number, lerp_func?: (t: number, a: P, b: P) => P): Bezier<P>Creates a bezier instance from 2 to 4 points: 2 give a straight line, 3 a quadratic curve and 4 a cubic curve. Any other count fails an assert. The default length function is
vmath.length, which rejects numbers, so number points need alength_funcsuch asmath.abs.Parameters
points:P[]— The points, from the start of the curve to its end.samples_count?:number— The number of segmentsuniform_positionmeasures the curve with, a whole number. It defaults to1, and 2 points always use1.length_func?:(v: P) => number— Returns the length of the difference of two points. Defaults tovmath.length.lerp_func?:(t: number, a: P, b: P) => P— Interpolates between two points. Defaults tovmath.lerp.
Returns
Bezier<P>
(points: number[], samples_count: number | undefined, length_func: (v: number) => number, lerp_func?: (t: number, a: number, b: number) => number): Bezier<number>Creates a bezier instance from 2 to 4 number points: 2 give a straight line, 3 a quadratic curve and 4 a cubic curve. Any other count fails an assert. The default length function is
vmath.length, which rejects numbers, so alength_funcsuch asmath.absis required; the default lerp function,vmath.lerp, takes numbers.Parameters
points:number[]— The points, from the start of the curve to its end.samples_count:number | undefined— The number of segmentsuniform_positionmeasures the curve with, a whole number. It defaults to1, and 2 points always use1.length_func:(v: number) => number— Returns the length of the difference of two points.lerp_func?:(t: number, a: number, b: number) => number— Interpolates between two points. Defaults tovmath.lerp.
Returns
Bezier<number>
position<P>(self: Bezier<P>, time: number): P
Returns the classic position along the curve at a progress. time is not clamped,
so a value outside 0 to 1 extrapolates.
Parameters
self:Bezier<P>— The bezier instance, created bynew.time:number— The progress, from0to1.
Returns
P
uniform_position<P>(self: Bezier<P>, time: number): P
Returns the uniform position along the curve: the point at that fraction of the
curve's length. time is clamped between 0 and 1, and the accuracy depends on
the samples_count given to new.
Parameters
self:Bezier<P>— The bezier instance, created bynew.time:number— The progress, from0to1.
Returns
P
Types
Bezier
Bezier<P>
Bezier.position(time: number): P
Returns the classic position along the curve at a progress. time is not clamped,
so a value outside 0 to 1 extrapolates.
Parameters
time:number— The progress, from0to1.
Returns
P
Bezier.uniform_position(time: number): P
Returns the uniform position along the curve: the point at that fraction of the
curve's length. time is clamped between 0 and 1, and the accuracy depends on
the samples_count given to new.
Parameters
time:number— The progress, from0to1.
Returns
P