Skip to Content
defold-typescript libraries
astrochilidefold-operator

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
    1. Pick a release from astrochili/defold-operator releases and add its Source code (zip) URL (or a packaged .zip asset, if the library ships one) to game.project under [project] dependencies, then Fetch Libraries in the Defold editor.
    2. Run bunx @defold-typescript/cli resolve to materialize its types.
    3. Import it under a namespace alias of your choice:
      import * as bezier from "operator.bezier"

Functions

new(2 overloads)

  1. <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 a length_func such as math.abs.

    Parameters

    • points: P[] — The points, from the start of the curve to its end.
    • samples_count?: number — The number of segments uniform_position measures the curve with, a whole number. It defaults to 1, and 2 points always use 1.
    • length_func?: (v: P) => number — Returns the length of the difference of two points. Defaults to vmath.length.
    • lerp_func?: (t: number, a: P, b: P) => P — Interpolates between two points. Defaults to vmath.lerp.

    Returns

    • Bezier<P>
  2. (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 a length_func such as math.abs is 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 segments uniform_position measures the curve with, a whole number. It defaults to 1, and 2 points always use 1.
    • 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 to vmath.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 by new.
  • time: number — The progress, from 0 to 1.

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 by new.
  • time: number — The progress, from 0 to 1.

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, from 0 to 1.

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, from 0 to 1.

Returns

  • P

On this page