Curves
From TargetWiki
Targetware makes use of curves in a number of situations, including key frame animation, some particle affectors, physics, and more.
Contents |
File Format
A curve defined in a standard Targetware configuration file. Often, rather than being in a separate file, this is embedded in a table in a .graphics or .particles file.
At the top level, the curve contains the following entries:
- pre_behavior = string. This specifies how the curve should behave when an input value less than its lowest input point is passed to it.
- post_behaviour = string. This specifies how the curve should behave when an input value greater than its highest input point is passed to it.
- input = table. This is a table of numbers. The number of values in this table is the number of points in the curve.
- output = table. This is a table of numbers. The number of values in this table is the number of points in the curve. For curves with multi-dimensional output, each number can be replaced with a table of numbers. Each point must have the same number of output dimensions.
- in_tangent = table. This is an optional table of tables, with each sub-table containing 2 numbers for each output dimension. These values define the inbound tangent (that is, the left-side tangent) of the curve as it reaches this point. If a curve has an in_tangent table, it must also have an out_tangent table.
- out_tangent = table. This is formatted exactly like the in_tangent table, but the values define the outbound tangent (that is, the right-side tangent) of the curve as it goes away from this point.
- interpolation = string or table. This is either a single string indicating how the entire curve should be interpolated, or a table containing an interpolation method for each point in the curve.
An example is:
curve_0 =
{
pre_behaviour = "cycle"
post_behaviour = "cycle"
input = { 0.58333301544189453 }
output = { 0 }
in_tangent =
{
{ 0.58333301544189453, 0 }
}
out_tangent =
{
{ 0.58333301544189453, 0 }
}
interpolation = "bezier"
}
Points
The input and output tables, both optional tangent tables, and the optional interpolation table, must all have the same number of entries. Taken together, the values from each of those tables at a given index represent a single point on the curve.
Behaviour
Pre- and post-behaviour are defined with one of the following strings:
- constant. The curve returns the output value of the minimum or maximum point when an input value outside its range is passed to it.
- gradient. The curve returns an output value linearly interpolated based on the first or last two points of the curve.
- cycle. The input value is wrapped around when it's outside the curve's input range.
- oscillate. The input value runs is wrapped like a cycling curve, but runs backwards and forwards rather than starting over from the beginning of the curve.
- cycle_relative. This behaves like cycle, but if the first and last output values aren't the same, the difference between the two is added (when past the input range) or subtracted (when before the input range) for every cycle.
Interpolation
The output value a curve returns when the input value is between two points is determined by either the interpolation method of the curve or, if separate interpolation methods for each point are used, the interpolation method of the point immediately to the left of the input value.
Interpolation methods are defined with one of the following strings:
- step. The output value is the same as the output value of the point before the input value. The output value only changes when the next point is reached. No tangents are required for step interpolation.
- linear. The output value is linearly interpolated between the two points. No tangents are required for linear interpolation.
- bezier. The output value is interpolated on a bezier curve defined by the previous point's output value and outbound tangent and the next point's output value and inbound tangent. Tangents are required for bezier interpolation.
