API Reference

Class List

pc.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.

var curve = new pc.Curve([
    [0, 0],
    [0.33, 2],
    [0.66, 2.6],
    [1, 3]
]);

Summary

Properties

length

The number of keys in the curve.

tension

Controls how pc.CURVE_SPLINE tangents are calculated.

type

The curve interpolation scheme.

Methods

add

Add a new key to the curve.

clone

Returns a clone of the specified curve object.

get

Return a specific key.

sort

Sort keys by time.

value

Returns the interpolated value of the curve at specified time.

Details

Constructor

Curve([data])

Creates a new curve.

var curve = new pc.Curve([
    [0, 0],
    [0.33, 2],
    [0.66, 2.6],
    [1, 3]
]);

Parameters

datanumber[]

An array of keys (pairs of numbers with the time first and value second).

Properties

numberlength

The number of keys in the curve. [read only].

numbertension

Controls how pc.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.

numbertype

The curve interpolation scheme. Can be:

Defaults to pc.CURVE_SMOOTHSTEP.

Methods

add(time, value)

Add a new key to the curve.

Parameters

timenumber

Time to add new key.

valuenumber

Value of new key.

Returns

number[]

[time, value] pair.

clone()

Returns a clone of the specified curve object.

Returns

pc.Curve

A clone of the specified curve.

get(index)

Return a specific key.

Parameters

indexnumber

The index of the key to return.

Returns

number[]

The key at the specified index.

sort()

Sort keys by time.

value(time)

Returns the interpolated value of the curve at specified time.

Parameters

timenumber

The time at which to calculate the value.

Returns

number

The interpolated value.