Caching

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 continously 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

Cache Density

This spline parameter determines how many cache points you want to get calculated. Being a percentage the setting ranges from “None” to “Highest”. The default value of 50% is a good compromise between performance and precision most of the time. The real amount of cache points depends also on a global setting called

Max Cache PPU

This global setting (see Max Cache PPU) determines the maximum possible number of cache points per world unit. For example, if you set it to 10 and set the spline's Cache Density to maximum, a spline segment with a length of 20 units will calculate 200 cache points.

You should alter this value depending on your scene scale. If you work large scale (i.e. a world unit doesn't take much space on screen), lower this value. If you work at a small scale, raise this value to allow more cache points per world unit.

Memory vs. Accuracy

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

Caching performance

Curvy uses a sophisticated caching system. If you alter a spline, only the neccessary 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.

Discussion

Enter your comment:
H Y X T T
 
Last modified: 2015/08/15 21:37 by Jake