cutCylinder function
A cylinder with three loops cut across it and the middle one pulled out.
A cut that went in straight is invisible; a cut that zig-zagged shows the moment the ring it made is moved, because the ring stops being a circle.
Implementation
EditMesh cutCylinder() {
final mesh = const ParametricCylinder(
radiusTop: 0.45,
radiusBottom: 0.45,
height: 1.4,
segments: 20,
).toEditMesh();
var upright = EditMesh.none;
for (
var face = 0;
face < mesh.faceSlotCount && upright == EditMesh.none;
face++
) {
if (mesh.valencyOf(face) != 4) continue;
mesh.forEachHalfEdge(face, (int half) {
final from = mesh.positionOf(mesh.originOf(half));
final to = mesh.positionOf(mesh.originOf(mesh.nextOf(half)));
if ((from.y - to.y).abs() > 0.5) upright = half;
});
}
mesh.beginStep();
final cut = loopCut(
mesh,
Selection.of(ElementLevel.edge, <int>[mesh.edgeOf(upright)]),
cuts: 3,
);
// The middle ring of the three, pushed out so the cuts have a shape.
final middle = <int>[
for (final vertex in cut.selection.ids)
if (mesh.positionOf(vertex).y.abs() < 0.05) vertex,
];
scaleSelection(
mesh,
Selection.of(ElementLevel.vertex, middle),
by: Vector3(1.7, 1, 1.7),
pivot: Vector3.zero(),
);
mesh
..endStep()
..clearJournal();
return mesh;
}