buildMesh method
Its triangles, textured by uv.
Implementation
@override
ShapeMesh buildMesh([ShapeUv uv = ShapeUv.natural]) {
final r = Primitive3D.size(radius), c = _half;
final n = Primitive3D.count(rings, 1, 32);
final cap = uv.anyway(r * math.pi / 2);
final straight = uv.alongY(c * 2);
final profile = <(double, double, double, double, double)>[];
for (var j = 0; j <= n; j++) {
final t = math.pi / 2 * j / n;
profile.add((
r * math.sin(t),
-c - r * math.cos(t),
math.sin(t),
-math.cos(t),
uv.anyway(r * t),
));
}
for (var j = 0; j <= n; j++) {
final t = math.pi / 2 + math.pi / 2 * j / n;
profile.add((
r * math.sin(t),
c - r * math.cos(t),
math.sin(t),
-math.cos(t),
cap + straight + uv.anyway(r * (t - math.pi / 2)),
));
}
final b = MeshBuilder(uv)
..lathe(
profile,
Primitive3D.count(segments, 3, 128),
aroundLength: uv.around(r),
profileLength: cap * 2 + straight,
);
final mesh = b.build();
return smooth ? mesh : mesh.faceted();
}