curve static method
Generate random terrain using a curve.
Float32List g
The geometry's z-positions to modify with heightmap data.
TerrainOptions options
A map of settings that control how the terrain is constructed and
displayed. Valid values are the same as those for the options parameter
of {@link THREE.Terrain}().
double Function(double,double)? curve
A function that takes an x- and y-coordinate and returns a z-coordinate.
For example, function(x, y) { return math.sin(x*y*math.pi*100); }
generates sine noise, and function() { return math.Random().nextDouble(); } sets the
vertex elevations entirely randomly. The function's parameters (the x- and
y-coordinates) are given as percentages of a phase (i.e. how far across
the terrain in the relevant direction they are).
Implementation
static void curve(Float32List g, TerrainOptions options, double Function(double,double) curve) {
final range = (options.maxHeight! - options.minHeight!) * 0.5,
scalar = options.frequency / (math.min(options.xSegments, options.ySegments) + 1);
for (int i = 0, xl = options.xSegments + 1, yl = options.ySegments + 1; i < xl; i++) {
for (int j = 0; j < yl; j++) {
g[j * xl + i] += curve(i * scalar, j * scalar) * range;
}
}
}