remove legacy cam slice options from fdm slicer. fix sla export

This commit is contained in:
Stewart Allen 2021-06-20 18:38:31 -04:00
commit 24546c8735
4 changed files with 30 additions and 105 deletions

View file

@ -737,6 +737,7 @@
inner.move(offset); inner.move(offset);
} }
} }
return this;
}; };
/** /**
@ -760,6 +761,7 @@
inner.scale(scale, round); inner.scale(scale, round);
} }
} }
return this;
}; };
/** /**

View file

@ -46,11 +46,8 @@
* @param {Function} onupdate callback to report slicing progress * @param {Function} onupdate callback to report slicing progress
*/ */
function slice(points, bounds, options, ondone, onupdate) { function slice(points, bounds, options, ondone, onupdate) {
let topoMode = options.topo, let useFlats = options.flats,
simpleMode = options.simple,
useFlats = options.flats,
swap = options.swapX || options.swapY, swap = options.swapX || options.swapY,
isCam = options.cam,
debug = options.debug, debug = options.debug,
xray = options.xray, xray = options.xray,
ox = 0, ox = 0,
@ -267,29 +264,6 @@
zIndexes.push((zl[i] + zl[i+1]) / 2); zIndexes.push((zl[i] + zl[i+1]) / 2);
zThick.push(zl[i+1] - zl[i]); zThick.push(zl[i+1] - zl[i]);
} }
} else if (isCam) {
// re-divide slice height so that top and
// bottom slices fall exactly on those faces
zInc = (zMax - zMin) / (Math.floor(zMax / zInc) + 1);
for (i = zMin; i < zMax; i += zInc) {
zIndexes.push(i);
}
for (let key in zFlat) {
// todo make threshold for flat detection configurable
if (!zFlat.hasOwnProperty(key) || zFlat[key] < 10){
continue;
}
key = parseFloat(key);
if (!zIndexes.contains(key) && key >= zMin) {
zIndexes.push(key);
}
}
// sort top down
zIndexes.sort(function(a,b) {
return b-a;
});
// copy to store original z
zHeights = zIndexes.slice();
} else if (zIncMin) { } else if (zIncMin) {
// console.log('adaptive slicing', zIncMin, ':', zInc, 'from', zMin, 'to', zMax); // console.log('adaptive slicing', zIncMin, ':', zInc, 'from', zMin, 'to', zMax);
// FDM adaptive slicing // FDM adaptive slicing
@ -360,23 +334,13 @@
if (zFlat[ik]) onFlat = true; if (zFlat[ik]) onFlat = true;
if (zLines[ik]) onLine = true; if (zLines[ik]) onLine = true;
if (!useFlats && (onFlat || onLine)) { if (!useFlats && (onFlat || onLine)) {
zIndexes[i] += isCam ? 0.001 : -0.001; zIndexes[i] -= -0.001;
} }
// slice next layer and add to slices[] array // slice next layer and add to slices[] array
let slice = sliceZ(zIndexes[i], zHeights[i], onFlat, onLine, zThick[i]); let slice = sliceZ(zIndexes[i], zHeights[i], onFlat, onLine, zThick[i]);
// override z in cam in case it was moved for a flat or line
if (isCam && slice) {
slice.z = zHeights[i];
}
onupdate(i / zIndexes.length); onupdate(i / zIndexes.length);
} }
// for cam, bottom as mandatory (hasFlats)
if (isCam && slices.length > 0) {
// slices[0].hasFlats = true;
slices[slices.length-1].hasFlats = true;
}
// connect slices into linked list for island/bridge projections // connect slices into linked list for island/bridge projections
for (i=1; i<slices.length; i++) { for (i=1; i<slices.length; i++) {
slices[i-1].up = slices[i]; slices[i-1].up = slices[i];
@ -478,11 +442,6 @@
return; return;
} }
// annotate slices with cam flats for finishing waterlines
if (onflat && isCam) {
slice.hasFlats = true;
}
// iterate over matching buckets for this z offset // iterate over matching buckets for this z offset
for (let i = 0; i < bucket.length;) { for (let i = 0; i < bucket.length;) {
p1 = bucket[i++]; p1 = bucket[i++];
@ -527,24 +486,28 @@
slice.height = height; slice.height = height;
slice.index = slices.length; slice.index = slices.length;
slice.lines = removeDuplicateLines(lines);
slice.thick = thick; slice.thick = thick;
// for topo slices, we just need the raw lines // de-dup and group lines
if (!topoMode && !simpleMode) { lines = removeDuplicateLines(lines);
slice.groups = connectLines(slice.lines, slice.z); let groups = connectLines(lines, slice.z);
// simplistic healing of bad meshes
if (options.union) { if (options.union) {
slice.groups = POLY.flatten(POLY.union(POLY.nest(slice.groups), null, true), null, true); groups = POLY.flatten(POLY.union(POLY.nest(groups), null, true), null, true);
} }
if ((debug && slice.lines.excessive) || xray) {
if ((debug && lines.excessive) || xray) {
const dash = xray || 3; const dash = xray || 3;
slice.lines.forEach((line, i) => { lines.forEach((line, i) => {
const group = i % dash; const group = i % dash;
const color = [ 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff ][group]; const color = [ 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff ][group];
slice.output().setLayer(`xl-${group}`, color).addLine(line.p1, line.p2); slice.output().setLayer(`xl-${group}`, color).addLine(line.p1, line.p2);
}); });
} }
POLY.nest(slice.groups).forEach((poly, i) => {
// identify and add tops to slice
POLY.nest(groups).forEach((poly, i) => {
slice.addTop(poly); slice.addTop(poly);
if (xray) { if (xray) {
const group = i % (xray || 3); const group = i % (xray || 3);
@ -552,46 +515,9 @@
slice.output().setLayer(`xg-${group}`, color).addPoly(poly); slice.output().setLayer(`xg-${group}`, color).addPoly(poly);
} }
}); });
}
// fixup un-rotates polygons for CAM
if (options.swapX || options.swapY) {
let move = {x:ox, y:oy, z:0};
if (topoMode) {
let lines = slice.lines, llen = lines.length, idx, line;
// shared points causing problems
for (idx=0; idx<llen; idx++) {
line = lines[idx];
line.p1 = line.p1.clone();
line.p2 = line.p2.clone();
}
for (idx=0; idx<llen; idx++) {
line = lines[idx];
if (options.swapX) {
line.p1.swapXZ();
line.p2.swapXZ();
} else {
line.p1.swapYZ();
line.p2.swapYZ();
}
line.p1.move(move);
line.p2.move(move);
}
} else if (simpleMode) {
// fdm polishing mode
slice.groups = connectLines(slice.lines, slice.z);
slice.groups.forEach(poly => {
poly.swap(options.swapX, options.swapY);
poly.move(move);
poly.inner = null;
});
}
}
slices.push(slice); slices.push(slice);
if (!(topoMode || simpleMode)) {
delete slice.lines;
delete slice.groups;
}
return slice; return slice;
} }
} }

View file

@ -439,7 +439,6 @@
sliceFillAngle += 90.0; sliceFillAngle += 90.0;
}, "fill solids"); }, "fill solids");
if (promises) { if (promises) {
console.log({fill_awaiting: promises.length});
await Promise.all(promises); await Promise.all(promises);
} }
} }
@ -470,7 +469,6 @@
lastType = newType; lastType = newType;
}, "infill"); }, "infill");
if (promises) { if (promises) {
console.log({infill_awaiting: promises.length});
await Promise.all(promises); await Promise.all(promises);
} }
} else if (isSynth) { } else if (isSynth) {

View file

@ -485,12 +485,11 @@
function scaleMovePoly(poly) { function scaleMovePoly(poly) {
let points = poly.points; let points = poly.points;
let bounds = poly.bounds = BASE.newBounds(); poly._bounds = undefined;
for (let i=0, il=points.length; i<il; i++) { for (let i=0, il=points.length; i<il; i++) {
let p = points[i]; let p = points[i];
p.y = height - (p.y * scaleY + height2); p.y = height - (p.y * scaleY + height2);
p.x = p.x * scaleX + width2; p.x = p.x * scaleX + width2;
bounds.update(p);
} }
if (poly.inner) { if (poly.inner) {
for (let i=0, ia=poly.inner, il=poly.inner.length; i<il; i++) { for (let i=0, ia=poly.inner, il=poly.inner.length; i<il; i++) {