fromHeightmap static method

void fromHeightmap(
  1. Float32List g,
  2. TerrainOptions options
)

Convert an image-based heightmap into vertex-based height data.

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}().

Implementation

static void fromHeightmap(Float32List g, TerrainOptions options) {
  int rows = options.ySegments + 1;
  int cols = options.xSegments + 1;
  double spread = options.maxHeight! - options.minHeight!;
  final data = options.heightmap!;//context.getImageData(0, 0, canvas.width, canvas.height).data;

  for (int row = 0; row < rows; row++) {
    for (int col = 0; col < cols; col++) {
      int i = row*cols + col;
      int idx = i*4;
      g[i] = (data[idx] + data[idx+1] + data[idx+2]) / 765*spread + (options.minHeight ?? 0);
    }
  }
}