edges static method

dynamic edges(
  1. Float32List g,
  2. TerrainOptions options, [
  3. bool direction = false,
  4. double? distance,
  5. Easing? easing,
  6. TerrainEdges? edges,
])

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

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 edge 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. TerrainOptions edges = {top: true, bottom: true, left: true, right: true} Determines which edges should be affected by this function. Defaults to all edges. If passed, should be an object with top, bottom, left, and right Boolean properties specifying which edges to affect.

Implementation

static edges(Float32List g, TerrainOptions options, [bool direction = false, double? distance, Easing? easing, TerrainEdges? edges]) {
  int numXSegments = distance != null?(distance / (options.xSize / options.xSegments)).floor() : 1;
  int numYSegments = distance != null?(distance / (options.ySize / options.ySegments)).floor() : 1;
  double peak = direction ? options.maxHeight! : options.minHeight!;
  Function max = direction ? math.max : math.min;
  int xl = options.xSegments + 1;
  int yl = options.ySegments + 1;
  int i, j, k1, k2;
  double multiplier;
  easing = easing ?? Easing.easeInOut;
  edges ??= TerrainEdges();

  for (i = 0; i < xl; i++) {
    for (j = 0; j < numYSegments; j++) {
      multiplier = easing.call(1 - j / numYSegments);
      k1 = j*xl + i;
      k2 = (options.ySegments-j)*xl + i;
      if (edges.top) {
        g[k1] = max(g[k1], (peak - g[k1])*multiplier + g[k1]);
      }
      if (edges.bottom) {
        g[k2] = max(g[k2], (peak - g[k2])*multiplier + g[k2]);
      }
    }
  }
  for (i = 0; i < yl; i++) {
    for (j = 0; j < numXSegments; j++) {
      multiplier = easing.call(1 - j / numXSegments);
      k1 = i*xl+j;
      k2 = (options.ySegments-i)*xl + (options.xSegments-j);
      if (edges.left) {
        g[k1] = max(g[k1], (peak - g[k1])*multiplier + g[k1]);
      }
      if (edges.right) {
        g[k2] = max(g[k2], (peak - g[k2])*multiplier + g[k2]);
      }
    }
  }
  clamp(
    g,
    TerrainOptions(
      maxHeight: options.maxHeight,
      minHeight: options.minHeight,
      stretch: true,
    )
  );
}