multiPass static method

void multiPass(
  1. Float32List g,
  2. TerrainOptions options,
  3. List<Passes> passes
)

A utility for generating heightmap functions by additive composition.

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}(). Passes passes Determines which heightmap functions to compose to create a new one. Consists of an array of objects with the following properties:

  • method: Contains something that will be passed around as an options.heightmap (a heightmap-generating function or a heightmap image)
  • amplitude: A multiplier for the heightmap of the pass. Applied before the result of the pass is added to the result of previous passes.
  • frequency: For terrain generation methods that support it (Perlin, Simplex, and Worley) the octave of randomness. This basically controls how big features of the terrain will be (higher frequencies result in smaller features). Often running multiple generation functions with different frequencies and amplitudes results in nice detail.

Implementation

static void multiPass(Float32List g, TerrainOptions options, List<Passes> passes) {
  TerrainOptions clonedOptions = TerrainOptions();
  for (final opt in options.keys) {
    if (options.containsKey(opt)) {
      clonedOptions[opt] = options[opt];
    }
  }
  final range = options.maxHeight! - options.minHeight!;
  for (int i = 0, l = passes.length; i < l; i++) {
      final amp = passes[i].amplitude == null ? 1 : passes[i].amplitude!,
          move = 0.5 * (range - range * amp);
      clonedOptions.maxHeight = options.maxHeight! - move;
      clonedOptions.minHeight = options.minHeight! + move;
      clonedOptions.frequency = passes[i].frequency == null ? options.frequency : passes[i].frequency!;
      passes[i].method?.call(g, clonedOptions);
  }
}