radialEdges static method

void radialEdges(
  1. Float32List g,
  2. TerrainOptions options,
  3. dynamic direction,
  4. dynamic distance,
  5. Easing easing,
)

Move the edges of the terrain up or down based on distance from the center.

Useful to make islands or enclosing walls/cliffs.

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}(). bool direction true if the edges should be turned up; false if they should be turned down. double distance The distance from the center at which the edges should begin to be affected by this operation. Easing e = EaseInOut A function that determines how quickly the terrain will transition between its current height and the edge shape as distance to the edge decreases. It does this by interpolating the height of each vertex along a curve. Valid values include THREE.Terrain.Linear, THREE.Terrain.EaseIn, THREE.Terrain.EaseOut, THREE.Terrain.EaseInOut, THREE.Terrain.InEaseOut, and any custom function that accepts a float between 0 and 1 and returns a float between 0 and 1.

Implementation

static void radialEdges(Float32List g, TerrainOptions options, direction, distance, Easing easing) {
  double peak = direction ? options.maxHeight! : options.minHeight!;
  Function max = direction ? math.max : math.min;
  int xl = (options.xSegments + 1);
  int yl = (options.ySegments + 1);
  double xl2 = xl*0.5;
  double yl2 = yl*0.5;
  double xSegmentSize = options.xSize / options.xSegments;
  double ySegmentSize = options.ySize / options.ySegments;
  double edgeRadius = math.min(options.xSize, options.ySize)*0.5 - distance;
  int i, j, k;
  double multiplier;
  double vertexDistance;

  for (i = 0; i < xl; i++) {
    for (j = 0; j < yl2; j++) {
      k = j*xl + i;
      vertexDistance = math.min(edgeRadius, math.sqrt((xl2-i)*xSegmentSize*(xl2-i)*xSegmentSize + (yl2-j)*ySegmentSize*(yl2-j)*ySegmentSize) - distance);
      if (vertexDistance < 0) continue;
      multiplier = easing.call(vertexDistance / edgeRadius);
      g[k] = max(g[k], (peak - g[k])*multiplier + g[k]);
      // Use symmetry to reduce the number of iterations.
      k = (options.ySegments-j)*xl + i;
      g[k] = max(g[k], (peak - g[k])*multiplier + g[k]);
    }
  }
}