fix preview and gcode export for lathe ops

This commit is contained in:
Stewart Allen 2023-02-11 11:10:20 -05:00
commit 55ea6825eb
4 changed files with 15 additions and 23 deletions

View file

@ -847,7 +847,7 @@ class OpLathe extends CamOp {
}, },
ondone: (slices) => { ondone: (slices) => {
this.slices = slices; this.slices = slices;
addSlices(slices); addSlices(slices, false);
} }
}); });
} }
@ -875,20 +875,11 @@ class OpLathe extends CamOp {
continue; continue;
} }
let polys = [], poly, emit; for (let path of slice.camLines) {
slice.camLines.forEach(poly => { path.forEachPoint((point, pidx) => {
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) => {
camOut(point.clone(), pidx > 0, stepover); camOut(point.clone(), pidx > 0, stepover);
}, false); }, false);
}); }
newLayer(); newLayer();
} }

View file

@ -165,12 +165,12 @@ CAM.slice = async function(settings, widget, onupdate, ondone) {
addPolyIndexing(poly.inner, a); addPolyIndexing(poly.inner, a);
} }
function addSlices(slices) { function addSlices(slices, addIndexing = isIndexed) {
if (!Array.isArray(slices)) { if (!Array.isArray(slices)) {
slices = [ slices ]; slices = [ slices ];
} }
sliceAll.appendAll(slices); sliceAll.appendAll(slices);
if (isIndexed && axisIndex !== undefined) { if (addIndexing && axisIndex !== undefined) {
// update slice cam lines to add axis indexing // update slice cam lines to add axis indexing
for (let slice of slices.filter(s => s.camLines)) { for (let slice of slices.filter(s => s.camLines)) {
addPolyIndexing(slice.camLines, -axisIndex); addPolyIndexing(slice.camLines, -axisIndex);

View file

@ -96,7 +96,7 @@ class Topo4 {
let index = 0; let index = 0;
let slices = this.slices = []; 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) { for (let z = range.min; z < range.max; z += resolution) {
if (z > slice.max) { if (z > slice.max) {
@ -266,7 +266,7 @@ class Topo4 {
const steps = 100; const steps = 100;
const rota = (360 / steps) * DEG2RAD; const rota = (360 / steps) * DEG2RAD;
const axis = new THREE.Vector3(1, 0, 0); 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 slices = sliced.map(s => { return { z: s.z, lines: s.shared } });
const paths = []; const paths = [];
@ -276,31 +276,30 @@ class Topo4 {
let angle = 0; let angle = 0;
let count = 0; let count = 0;
// for each step angle, find Z spine heights, produce record
while (count++ < steps) { while (count++ < steps) {
const heights = this.lathePath(slices, tool, paths); const heights = this.lathePath(slices, tool, paths);
recs.push({ angle, heights }); recs.push({ angle, heights });
angle -= rota; angle -= rota;
for (let lines of slices.map(s => s.lines)) { for (let lines of slices.map(s => s.lines)) {
rotatePoints(lines, rot); rotatePoints(lines, mrot);
} }
} }
console.log({recs});
for (let rec of recs) { for (let rec of recs) {
const { angle, heights } = rec; const { angle, heights } = rec;
const degrees = angle * RAD2DEG;
const points = heights.toFloat32(); const points = heights.toFloat32();
const poly = newPolygon().setOpen().addPoints( 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)); rotatePoints(points, new THREE.Matrix4().makeRotationAxis(axis, angle));
const top = newPolygon().setOpen().addPoints( const top = newPolygon().setOpen().addPoints(
[...points].group(3).map(a => newPoint(a[0], a[1], a[2])) [...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.camLines = [ poly ];
slice.output() slice.output()
.setLayer("lathe", { line: 0xffff00 }) .setLayer("lathe", { line: 0xffff00 })

View file

@ -1368,6 +1368,8 @@ function doSolidsFill(slice, spacing, angle, minArea, fillQ) {
stop.push(solid); 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) { if (stop.length) {
let top_area = top.poly.areaDeep(); let top_area = top.poly.areaDeep();
let stop_area = stop.map(p => p.areaDeep()).reduce((a,v) => a + v); let stop_area = stop.map(p => p.areaDeep()).reduce((a,v) => a + v);