toArray2D static method

List<Float32List> toArray2D(
  1. Float32List vertices,
  2. TerrainOptions options
)

Get a 2D array of heightmap values from a 1D array of Z-positions.

Float32List vertices A 1D array containing the vertex Z-positions of the geometry representing the terrain. TerrainOptions options A map of settings defining properties of the terrain. The only properties that matter here are xSegments and ySegments, which represent how many vertices wide and deep the terrain plane is, respectively (and therefore also the dimensions of the returned array).

return Float32List A 2D array representing the terrain's heightmap.

Implementation

static List<Float32List> toArray2D(Float32List vertices, TerrainOptions options) {
  List<Float32List> tgt = List.filled(options.xSegments + 1,new Float32List(options.ySegments + 1));
  int xl = options.xSegments + 1,
    yl = options.ySegments + 1,
    i, j;

  for (i = 0; i < xl; i++) {
    for (j = 0; j < yl; j++) {
      tgt[i][j] = vertices[j*xl + i];
    }
  }
  return tgt;
}