hill static method

void hill(
  1. Float32List g,
  2. TerrainOptions options, [
  3. InfluenceType feature = InfluenceType.hill,
  4. Function? shape,
])

Generate random terrain using the Hill method.

The basic approach is to repeatedly pick random points on or near the terrain and raise a small hill around those points. Those small hills eventually accumulate into large hills with distinct features.

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}(). InfluenceType feature = InfluenceType.hill A function describing the feature to raise at the randomly chosen points. Typically this is a hill shape so that the accumulated features result in something resembling mountains, but it could be any function that accepts one parameter representing the distance from the feature's origin expressed as a number between -1 and 1 inclusive. Optionally it can accept a second and third parameter, which are the x- and y- distances from the feature's origin, respectively. It should return a number between -1 and 1 representing the height of the feature at the given coordinate. static Influences contains some useful functions for this purpose. Function shape A function that takes an object with x and y properties consisting of uniform random variables from 0 to 1, and returns a number from 0 to 1, typically by transforming it over a distribution. The result affects where small hills are raised thereby affecting the overall shape of the terrain.

Implementation

static void hill(Float32List g, TerrainOptions options, [InfluenceType feature = InfluenceType.hill, Function? shape]) {
    double frequency = options.frequency * 2,
        numFeatures = frequency * frequency * 10,
        heightRange = options.maxHeight! - options.minHeight!,
        minHeight = heightRange / (frequency * frequency),
        maxHeight = heightRange / frequency,
        smallerSideLength = math.min(options.xSize, options.ySize),
        minRadius = smallerSideLength / (frequency * frequency),
        maxRadius = smallerSideLength / frequency;
    feature = feature ;

    Vector2 coords = Vector2.zero();
    for (int i = 0; i < numFeatures; i++) {
        final radius = math.Random().nextDouble() * (maxRadius - minRadius) + minRadius,
            height = math.Random().nextDouble() * (maxHeight - minHeight) + minHeight;
        // double min = 0 - radius,
        //     maxX = options.xSize + radius,
        //     maxY = options.ySize + radius;
        coords.x = math.Random().nextDouble();
        coords.y = math.Random().nextDouble();
        if (shape != null) shape(coords);

        Terrain.influence(
          g,
          options,
          Terrain.influences[feature],
          coords.x,
          coords.y,
          radius,
          height,
          AdditiveBlending,
          Easing.easeInStrong
        );
    }
}