cubeMinusSphere function
A cube with a sphere cut from one corner of it.
Off-centre on purpose, unlike bsp_test.dart's own fixture. A sphere
cut from dead centre and fully inside the cube — the case that fixture's
own volume tolerance is built to check — leaves the cube's outer surface
untouched, so a boolean that silently did nothing would draw the same
picture as a correct one. Pushing the sphere half out through a corner
carves a real, visible crater into two faces at once, which is what
mesh-47's own row asks a picture to show that a volume number cannot.
Implementation
EditMesh cubeMinusSphere() {
final cube = EditMesh.cuboid(size: Vector3(1.4, 1.4, 1.4));
final sphere = const ParametricSphere(
radius: 0.55,
segments: 24,
rings: 12,
).toEditMesh();
final corner = Vector3(0.7, 0.7, 0.7);
sphere.beginStep();
for (var v = 0; v < sphere.vertexSlotCount; v++) {
if (!sphere.isVertexAlive(v)) continue;
sphere.moveVertex(v, sphere.positionOf(v) + corner);
}
sphere.endStep();
final result = booleanSubtract(cube, sphere);
if (result == null) {
throw StateError('cube minus sphere refused to build a fixture');
}
return result.mesh;
}