Here’s an optimized version when doing lots of repeated CSG operations on the same object.
An instance of the Wedge class saves the original CSG2 object as well as intermediate results (in case of successive wedges on the same mesh). There’s probably some unnecessary checking going on of “null” results, but it seems to work well. The extra checks were trying to debug an unrelated bug. I have yet to do any performance analysis/optimization.
There is special handling of valid null results. When non-intersecting meshes are intersected, producing a mesh with no vertices, the mesh is disabled. VertexData with no points is uploaded to GPU and produces a warning because I can’t figure out from the CSG2 object whether the result is null before doing csg.toVertexData().
Maybe this is final, unless someone sees a need to make this more formal (or in TypeScript).
One bug found/fiixed. Also made the sliders work for all three axes. For each axis, the centerline of the wedge is on that axis with wedge angles specified as Left Hand Rule (aka counter-clockwise/leftward when looking outward from 0,0,0) around that axis. An angle of zero is facing the “previous” axis.
Note that the axes display disappears if the final result is an empty mesh. It will reappear when the wedge itself does.