refactor synth support widgets to use same output code path as automatic supports

This commit is contained in:
Stewart Allen 2022-10-13 20:31:44 -04:00
commit 6bbb844aa0
5 changed files with 43 additions and 33 deletions

View file

@ -287,6 +287,7 @@ FDM.init = function(kiri, api) {
sw._move(fwp.x, fwp.y, fwp.z); sw._move(fwp.x, fwp.y, fwp.z);
api.widgets.add(sw); api.widgets.add(sw);
sw.track.synth = true; sw.track.synth = true;
sw.track.support = true;
kiri.space.world.add(sw.mesh); kiri.space.world.add(sw.mesh);
} }
}); });

View file

@ -1167,7 +1167,7 @@ function slicePrintPath(print, slice, startPoint, offset, output, opt = {}) {
// use next nearest line strategy // use next nearest line strategy
if (near) if (near)
for (i=0; i<lines.length; i += 2) { for (let i=0; i<lines.length; i += 2) {
t1 = lines[i]; t1 = lines[i];
if (t1.del) { if (t1.del) {
continue; continue;
@ -1363,7 +1363,7 @@ function slicePrintPath(print, slice, startPoint, offset, output, opt = {}) {
} }
if (next.fill) { if (next.fill) {
next.fill.forEach(p => { p.z = z }); next.fill.forEach(p => { p.z = z });
outputFills(next.fill, {fast: true}); outputFills(next.fill, {fast: true, near: true});
} }
} else { } else {
let top = next; let top = next;
@ -1436,7 +1436,7 @@ function slicePrintPath(print, slice, startPoint, offset, output, opt = {}) {
}); });
// produce polishing paths when present // produce polishing paths when present
if (slice.tops.length && slice.tops[0].polish) { if (slice.tops && slice.tops.length && slice.tops[0].polish) {
let {x,y} = slice.tops[0].polish; let {x,y} = slice.tops[0].polish;
if (x) { if (x) {
outputSparse(x, 0, process.polishSpeed); outputSparse(x, 0, process.polishSpeed);

View file

@ -100,6 +100,7 @@ FDM.slice = function(settings, widget, onupdate, ondone) {
{ process, device, controller } = settings, { process, device, controller } = settings,
isBelt = device.bedBelt, isBelt = device.bedBelt,
isSynth = widget.track.synth, isSynth = widget.track.synth,
isSupport = widget.track.support,
isDanger = controller.danger, isDanger = controller.danger,
useAssembly = controller.assembly, useAssembly = controller.assembly,
isConcurrent = controller.threaded && kiri.minions.concurrent, isConcurrent = controller.threaded && kiri.minions.concurrent,
@ -722,28 +723,29 @@ FDM.slice = function(settings, widget, onupdate, ondone) {
} }
} }
} }
} else if (isSynth) { } else if (isSynth && isSupport) {
// fill manual supports differently // convert synth support widgets into support structure
let outline = process.sliceSupportOutline || false; let outline = process.sliceSupportOutline || false;
let promises = isConcurrent ? [] : undefined; let promises = isConcurrent ? [] : undefined;
let resolve = []; let resolve = [];
forSlices(0.5, promises ? 0.6 : 0.7, slice => { forSlices(0.5, promises ? 0.6 : 0.7, slice => {
let params = slice.params || process; let params = slice.params || process;
let density = params.sliceSupportDensity; let density = params.sliceSupportDensity;
if (density) let supports = slice.supports = slice.topShells();
for (let top of slice.tops) { slice.tops = undefined; // remove outline leave only supports
let offset = []; let polys = [];
if (density) {
if (!outline) { if (!outline) {
POLY.expand(top.shells || [], lineWidth, slice.z, offset); POLY.expand(supports, lineWidth, slice.z, polys);
} else { } else {
POLY.expand(top.shells || [], -lineWidth/4, slice.z, offset); POLY.expand(supports, -lineWidth/4, slice.z, polys);
}
} }
fillSupportPolys({ fillSupportPolys({
promises, polys: offset, lineWidth, density, z: slice.z, isBelt, promises, polys, lineWidth, density, z: slice.z, isBelt,
angle: process.sliceSupportFill angle: process.sliceSupportFill
}); });
resolve.push({top, offset}); resolve.push({ slice, polys });
}
}, "infill"); }, "infill");
if (promises) { if (promises) {
await tracker(promises, (i, t) => { await tracker(promises, (i, t) => {
@ -751,14 +753,8 @@ FDM.slice = function(settings, widget, onupdate, ondone) {
}); });
} }
for (let rec of resolve) { for (let rec of resolve) {
let spacing = lineWidth * (1 / supportDensity); let { slice, polys } = rec;
let lines = rec.top.fill_lines = rec.offset.map(o => o.fill).flat().filter(v => v); rec.supports = polys;
// if copying simply's support type, eliminate shells and zig/zag fill lines
if (!outline) {
let newlines = connect_lines(lines, spacing * 2);
rec.top.fill_lines = newlines;
rec.top.shells = [];
}
} }
} }
@ -774,8 +770,12 @@ FDM.slice = function(settings, widget, onupdate, ondone) {
trackupdate(i / t, 0.75, 0.8); trackupdate(i / t, 0.75, 0.8);
}); });
profileEnd(); profileEnd();
}
// fill all supports (auto and manual)
if (!isBelt && supportDensity) {
profileStart("support-fill"); profileStart("support-fill");
promises = false && isConcurrent ? [] : undefined; let promises = false && isConcurrent ? [] : undefined;
forSlices(0.8, promises ? 0.88 : 0.9, slice => { forSlices(0.8, promises ? 0.88 : 0.9, slice => {
doSupportFill({ doSupportFill({
promises, slice, lineWidth, density: supportDensity, promises, slice, lineWidth, density: supportDensity,
@ -802,9 +802,16 @@ FDM.slice = function(settings, widget, onupdate, ondone) {
if (isBelt) { if (isBelt) {
let bounds = base.newBounds(); let bounds = base.newBounds();
for (let top of slices[0].tops) { let slice = slices[0];
if (slice.tops) {
for (let top of slice.tops) {
bounds.merge(top.poly.bounds); bounds.merge(top.poly.bounds);
} }
} else if (slice.supports) {
for (let poly of slice.supports) {
bounds.merge(poly);
}
}
widget.belt.miny = -bounds.miny; widget.belt.miny = -bounds.miny;
widget.belt.midy = (bounds.miny + bounds.maxy) / 2; widget.belt.midy = (bounds.miny + bounds.maxy) / 2;
} }
@ -816,27 +823,28 @@ function connect_lines(lines, maxd = Infinity) {
const newlines = []; const newlines = [];
let op2; let op2;
let eo = 0; let eo = 0;
let idx = 1;
for (let i=0; i<lines.length; i += 2) { for (let i=0; i<lines.length; i += 2) {
let p1 = lines[i]; let p1 = lines[i];
let p2 = lines[i+1]; let p2 = lines[i+1];
p1.index = idx; // swap p1 / p2 dir every other line
p2.index = idx++;
if (eo++ % 2 === 1) { if (eo++ % 2 === 1) {
let t = p1; let t = p1;
p1 = p2; p1 = p2;
p2 = t; p2 = t;
} }
// connect short distances between ends
if (op2 && p1.distTo2D(op2) <= maxd) { if (op2 && p1.distTo2D(op2) <= maxd) {
let op1 = p1.clone(); let op1 = p1.clone();
op1.index = op2.index;
newlines.push(op2); newlines.push(op2);
newlines.push(op1); newlines.push(op1);
} }
newlines.push(p1); newlines.push(p1);
newlines.push(p2); newlines.push(p2);
op2 = p2.clone(); op2 = p2.clone();
op2.index = idx++; }
let idx = 0;
for (let p of newlines) {
p.index = (idx++ / 2) | 0;
} }
return newlines; return newlines;
} }
@ -850,6 +858,7 @@ function doRender(slice, isSynth, params, devel) {
const height = slice.height / 2; const height = slice.height / 2;
const solidWidth = params.sliceFillWidth || 1; const solidWidth = params.sliceFillWidth || 1;
if (slice.tops) // missing for supports
slice.tops.forEach(top => { slice.tops.forEach(top => {
if (isThin) output if (isThin) output
.setLayer('part', { line: 0x333333, check: 0x333333 }) .setLayer('part', { line: 0x333333, check: 0x333333 })

View file

@ -180,7 +180,7 @@ function prepareSlices(callback, scale = 1, offset = 0) {
for (let w of slicing) { for (let w of slicing) {
totalProgress += (track[w.id] || 0); totalProgress += (track[w.id] || 0);
} }
show.progress(offset + (totalProgress / widgets.length) * scale, msg); show.progress(offset + (totalProgress / slicing.length) * scale, msg);
} }
}); });
} }

View file

@ -155,7 +155,7 @@ class Slice {
findClosestPointTo(target) { findClosestPointTo(target) {
let min, find; let min, find;
if (this.tops.length) { if (this.tops && this.tops.length) {
this.tops.forEach(function(top) { this.tops.forEach(function(top) {
find = top.poly.findClosestPointTo(target); find = top.poly.findClosestPointTo(target);
if (!min || find.distance < min.distance) { if (!min || find.distance < min.distance) {