From 55ea6825ebf2fc276131794208faf43d086e2908 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sat, 11 Feb 2023 11:10:20 -0500 Subject: [PATCH] fix preview and gcode export for lathe ops --- src/kiri-mode/cam/ops.js | 17 ++++------------- src/kiri-mode/cam/slice.js | 4 ++-- src/kiri-mode/cam/topo4.js | 15 +++++++-------- src/kiri-mode/fdm/slice.js | 2 ++ 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/kiri-mode/cam/ops.js b/src/kiri-mode/cam/ops.js index 0eb31684..7834ae2d 100644 --- a/src/kiri-mode/cam/ops.js +++ b/src/kiri-mode/cam/ops.js @@ -847,7 +847,7 @@ class OpLathe extends CamOp { }, ondone: (slices) => { this.slices = slices; - addSlices(slices); + addSlices(slices, false); } }); } @@ -875,20 +875,11 @@ class OpLathe extends CamOp { continue; } - let polys = [], poly, emit; - slice.camLines.forEach(poly => { - polys.push({ first:poly.first(), last:poly.last(), poly:poly }); - }); - - printPoint = tip2tipEmit(polys, printPoint, (el, point, count) => { - poly = el.poly; - if (poly.last() === point) { - poly.reverse(); - } - poly.forEachPoint((point, pidx) => { + for (let path of slice.camLines) { + path.forEachPoint((point, pidx) => { camOut(point.clone(), pidx > 0, stepover); }, false); - }); + } newLayer(); } diff --git a/src/kiri-mode/cam/slice.js b/src/kiri-mode/cam/slice.js index 22857eaf..6845fa35 100644 --- a/src/kiri-mode/cam/slice.js +++ b/src/kiri-mode/cam/slice.js @@ -165,12 +165,12 @@ CAM.slice = async function(settings, widget, onupdate, ondone) { addPolyIndexing(poly.inner, a); } - function addSlices(slices) { + function addSlices(slices, addIndexing = isIndexed) { if (!Array.isArray(slices)) { slices = [ slices ]; } sliceAll.appendAll(slices); - if (isIndexed && axisIndex !== undefined) { + if (addIndexing && axisIndex !== undefined) { // update slice cam lines to add axis indexing for (let slice of slices.filter(s => s.camLines)) { addPolyIndexing(slice.camLines, -axisIndex); diff --git a/src/kiri-mode/cam/topo4.js b/src/kiri-mode/cam/topo4.js index 60ae3f24..5e76b2fb 100644 --- a/src/kiri-mode/cam/topo4.js +++ b/src/kiri-mode/cam/topo4.js @@ -96,7 +96,7 @@ class Topo4 { let index = 0; let slices = this.slices = []; - let slice = { min: range.min - step, max: range.min + step, index }; + let slice = { min: range.min, max: range.min + step, index }; for (let z = range.min; z < range.max; z += resolution) { if (z > slice.max) { @@ -266,7 +266,7 @@ class Topo4 { const steps = 100; const rota = (360 / steps) * DEG2RAD; const axis = new THREE.Vector3(1, 0, 0); - const rot = new THREE.Matrix4().makeRotationAxis(axis, rota); + const mrot = new THREE.Matrix4().makeRotationAxis(axis, rota); const slices = sliced.map(s => { return { z: s.z, lines: s.shared } }); const paths = []; @@ -276,31 +276,30 @@ class Topo4 { let angle = 0; let count = 0; + // for each step angle, find Z spine heights, produce record while (count++ < steps) { const heights = this.lathePath(slices, tool, paths); recs.push({ angle, heights }); angle -= rota; for (let lines of slices.map(s => s.lines)) { - rotatePoints(lines, rot); + rotatePoints(lines, mrot); } } - console.log({recs}); - for (let rec of recs) { const { angle, heights } = rec; + const degrees = angle * RAD2DEG; const points = heights.toFloat32(); const poly = newPolygon().setOpen().addPoints( - [...points].group(3).map(a => newPoint(a[0], a[1], a[2]).setA(angle)) + [...points].group(3).map(a => newPoint(a[0], a[1], a[2]).setA(degrees)) ); - rotatePoints(points, new THREE.Matrix4().makeRotationAxis(axis, angle)); const top = newPolygon().setOpen().addPoints( [...points].group(3).map(a => newPoint(a[0], a[1], a[2])) ); - const slice = newSlice().addTops([ top ]); + const slice = newSlice();//.addTops([ top ]); slice.camLines = [ poly ]; slice.output() .setLayer("lathe", { line: 0xffff00 }) diff --git a/src/kiri-mode/fdm/slice.js b/src/kiri-mode/fdm/slice.js index 54f1c256..93ede47a 100644 --- a/src/kiri-mode/fdm/slice.js +++ b/src/kiri-mode/fdm/slice.js @@ -1368,6 +1368,8 @@ function doSolidsFill(slice, spacing, angle, minArea, fillQ) { stop.push(solid); } } + // problematic for organic shapes with lots of big and small tops + // the small tops tend to trigger entire layer fills if (stop.length) { let top_area = top.poly.areaDeep(); let stop_area = stop.map(p => p.areaDeep()).reduce((a,v) => a + v);