noise3 method

  1. @override
double noise3(
  1. double x,
  2. double y,
  3. double z
)
override

Implementation

@override
double noise3(double x, double y, double z) {
  int xr = round(x);
  int yr = round(y);
  int zr = round(z);
  double distance = 999999;
  double distance2 = 999999;
  for (int xi = xr - 1; xi <= xr + 1; xi++) {
    for (int yi = yr - 1; yi <= yr + 1; yi++) {
      for (int zi = zr - 1; zi <= zr + 1; zi++) {
        D3 vec = CELL_3D[hash3D(seed, xi, yi, zi) & 255];
        double vecX = xi - x + vec.x;
        double vecY = yi - y + vec.y;
        double vecZ = zi - z + vec.z;
        double newDistance = (vecX.abs() + vecY.abs() + vecZ.abs()) +
            (vecX * vecX + vecY * vecY + vecZ * vecZ);
        distance2 = max(min(distance2, newDistance), distance);
        distance = min(distance, newDistance);
      }
    }
  }

  return distance2 - distance - 1;
}