
Mirror Engine API / Curve
Class: Curve
A curve is a collection of keys (time/value pairs). The shape of the curve is defined by its type that specifies an interpolation scheme for the keys.
Constructors
new Curve()
new Curve(data?: number[]): Curve
Creates a new Curve instance.
Parameters
data?
number
[]
An array of keys (pairs of numbers with the time first and value second).
Returns
Example
const curve = new Curve([
0,
0, // At 0 time, value of 0
0.33,
2, // At 0.33 time, value of 2
0.66,
2.6, // At 0.66 time, value of 2.6
1,
3 // At 1 time, value of 3
])
Properties
keys
keys: number[][] = [];
The keys that define the curve. Each key is an array of two numbers with the time first and the value second.
tension
tension: number = 0.5
Controls how CURVE_SPLINE tangents are calculated. Valid range is between 0 and 1 where 0 results in a non-smooth curve (equivalent to linear interpolation) and 1 results in a very smooth curve. Use 0.5 for a Catmull-Rom spline.
type
type: number = CURVE_SMOOTHSTEP
The curve interpolation scheme. Can be:
Defaults to CURVE_SMOOTHSTEP.
length
Get Signature
get length(): number
Gets the number of keys in the curve.
Returns
number
Methods
add()
add(time: number, value: number): number[]
Adds a new key to the curve.
Parameters
time
number
Time to add new key.
value
number
Value of new key.
Returns
number
[]
The newly created [time, value]
pair.
clone()
clone(): Curve
Returns a clone of the specified curve object.
Returns
A clone of the specified curve.
get()
get(index: number): number[]
Gets the [time, value]
pair at the specified index.
Parameters
index
number
The index of key to return.
Returns
number
[]
The [time, value]
pair at the specified index.
sort()
sort(): void
Sorts keys by time.
Returns
void
value()
value(time: number): number
Returns the interpolated value of the curve at specified time.
Parameters
time
number
The time at which to calculate the value.
Returns
number
The interpolated value.