UpdateDirectionalLightVisualizer function

void UpdateDirectionalLightVisualizer(
  1. MeshData md,
  2. double dim,
  3. double delta,
  4. Vector3 dir,
)

Implementation

void UpdateDirectionalLightVisualizer(
    MeshData md, double dim, double delta, VM.Vector3 dir) {
  if (dir.y == 0.0) {
    return;
  }
  final double d = dim * 0.5;
  final double end = delta * (d / delta).floor();
  final double start = -end;
  final VM.Vector3 dir2y = dir * d / dir.y;
  List<VM.Vector3> points = [];
  for (double x = start; x <= end; x += delta) {
    for (double z = start; z <= end; z += delta) {
      // we have an intersection  point with xz plane, now get the
      // intersection with the top and bottom face of the cube
      points.add(VM.Vector3(x, 0.0, z)..add(dir2y));
      points.add(VM.Vector3(x, 0.0, z)..sub(dir2y));
    }
  }
  for (int i = 0; i < 8; ++i) {
    int x = ((i & 1) == 1) ? 1 : -1;
    int y = ((i & 2) == 2) ? 1 : -1;
    int z = ((i & 4) == 4) ? 1 : -1;
    if (x > 0) {
      points.add(VM.Vector3(x * d, y * d, z * d));
      points.add(VM.Vector3(-x * d, y * d, z * d));
    }
    if (y > 0) {
      points.add(VM.Vector3(x * d, y * d, z * d));
      points.add(VM.Vector3(x * d, -y * d, z * d));
    }
    if (z > 0) {
      points.add(VM.Vector3(x * d, y * d, z * d));
      points.add(VM.Vector3(x * d, y * d, -z * d));
    }
  }

  md.ChangeVertexData(FlattenVector3List(points));
  List<int> faces = List.generate(points.length, (index) => index);
  md.ChangeFaces(faces);
}