add zflatup slicer option to restrict flats to those facing up

This commit is contained in:
Stewart Allen 2026-01-01 23:49:12 -05:00
commit fc9b27fcfd
2 changed files with 6 additions and 1 deletions

View file

@ -53,7 +53,7 @@ class OpRough extends CamOp {
}));
if (op.flats) {
let slicer = newSlicer();
let slicer = newSlicer({ zflatup: true });
ops_list.push(new OpArea(state, {
rename: op.rename ?? "flats",
spindle: op.spindle,

View file

@ -101,6 +101,11 @@ export class Slicer {
// use co-flat and co-line detection to adjust slice Z
if (Math.abs(p1.z - p2.z) < epsilon && Math.abs(p2.z - p3.z) < epsilon) {
// detect zFlat faces to avoid slicing directly on them
if (opt.zflatup) {
// filter to up-facing flats (more expensive)
let norm = THREE.computeFaceNormal(p1,p2,p3);
if (norm.z < -0.00001) continue;
}
let zkey = p1.z.toFixed(zDecimal),
area = Math.abs(util.area2(p1, p2, p3)) / 2;
if (!zFlat[zkey]) {