lathe method

void lathe(
  1. List<(double, double, double, double, double)> profile,
  2. int segments, {
  3. required double aroundLength,
  4. required double profileLength,
})

Sweeps profile round the Y axis in segments steps: a surface of revolution. Each profile point is (distance from the axis, y, the normal's outward part, the normal's y part, distance along the profile); the texture wraps once round (aroundLength metres for ShapeUv.metres) and runs down the profile (by its distance, over profileLength when natural).

Implementation

void lathe(
  List<(double, double, double, double, double)> profile,
  int segments, {
  required double aroundLength,
  required double profileLength,
}) {
  final first = vertexCount;
  final rows = profile.length;
  for (final (r, y, nr, ny, s) in profile) {
    final v = uv.metres ? s : (profileLength > 0 ? s / profileLength : 0.0);
    for (var i = 0; i <= segments; i++) {
      final a = 2 * math.pi * i / segments;
      final c = math.cos(a), sn = math.sin(a);
      final u = i / segments;
      vertex(
        r * c,
        y,
        r * sn,
        nr * c,
        ny,
        nr * sn,
        uv.metres ? u * aroundLength : u,
        v,
      );
    }
  }
  final stride = segments + 1;
  for (var k = 0; k + 1 < rows; k++) {
    for (var i = 0; i < segments; i++) {
      final a = first + k * stride + i;
      final b = a + 1;
      final c = a + stride + 1;
      final d = a + stride;
      quad(a, b, c, d);
    }
  }
}