The key to achieve the highest possible performance when working with splines is precalculation. In Curvy the following spline data is precomputed:

  • Positions
  • Distances between positions
  • Tangent (Direction) for each position
  • Up Vector (Orientation) for each position

As you remember (perhaps read here again), a spline by nature has no resolution. You enter a F value and get a position in return. But of course the step width should be limited to reasonable values. At some point a lower stepsize makes no sense due float inaccuracy. We've seen spline solutions using doubles, but transforms and visual presentation in Unity are float based, so calculating doubles would produce a precision that can't be visualized.

To sum it up, calculating spline curves is about querying a formula continuously with a given stepsize and retrieving approximated points. Those points connected form the spline you see on screen. The number of sample points a spline uses is calculated automatically based on it's length, but can be influenced by you. In general, sample points (we call them Approximation Points or cache points) are spread at equal distance over a spline segment (in fact the segment length is roughly guessed at calculation time by taking the distance between the two involved Control Points).

Any API methods ending with “Fast” means that cache data is being used by that method

The sample points number for a spline is defined by two parameters:

  • Max Points Per Unit: This defines the number of sample points per world distance unit.
  • Cache Density: This is a value between 1 and 100. The higher the number, the more sample points are per distance unit. When it is equal to 100, the spline will have Max Points Per Unit sample points per unit. For example, if you set Cache Density to 100 and Max Points Per Unit to 8, a spline segment with a length of 20 units will calculate 160 cache points. The Cache Density's default value of 50 is a good compromise between performance and precision most of the time.

In general, having more sample points will result in a higher degree of accuracy. As a downside, precomputing takes longer and more memory is used. You can (but don't necessarily need to) tweak the above two settings if you need more accurate values or a faster calculation. Which values work best for you depends on your setup.

Curvy uses a sophisticated caching system. If you alter a spline, only the necessary values are being recalculated (usually on the next call to Update). On top of that you can enable threading to speed up calculation. Threading comes with a management overhead, so it's most useful for very large splines that are continuously changed.