converging on a better polish. moving to polys vs lines

This commit is contained in:
Stewart Allen 2020-03-04 17:40:11 -05:00
commit c51887d9ba
4 changed files with 43 additions and 30 deletions

View file

@ -161,9 +161,9 @@ var gs_kiri_fdm = exports;
}, "infill"); }, "infill");
} }
let polish = spro.layerPolishing;
// experimental polishing // experimental polishing
if (spro.layerPolishing) { if (polish) {
console.log({polish:spro.layerPolishing})
let px, py; let px, py;
widget.polish = {}; widget.polish = {};
// compute x polishing slices // compute x polishing slices
@ -197,15 +197,19 @@ console.log({polish:spro.layerPolishing})
px.forEach(p => pa.appendAll(p)); px.forEach(p => pa.appendAll(p));
py.forEach(p => pa.appendAll(p)); py.forEach(p => pa.appendAll(p));
forSlices(1.0, 1.0, slice => { forSlices(1.0, 1.0, slice => {
if (slice.index >= 2) { if (slice.index >= polish) {
let zb = slice.down.down.z; let sd = slice;
for (let i=0; i<polish; i++) {
sd = sd.down;
}
let zb = sd.z;
let zt = slice.z; let zt = slice.z;
let lines = []; let lines = [];
let lastp;
let equal = 0;
let points = 0;
pa.forEach(p => { pa.forEach(p => {
p.forEachSegment((p1, p2) => { p.forEachSegment((p1, p2) => {
// if (Math.abs(p1.z - p2.z) < 0.01) {
// return;
// }
// return when both below // return when both below
if (p1.z < zb && p2.z < zb) { if (p1.z < zb && p2.z < zb) {
return; return;
@ -242,7 +246,7 @@ console.log({polish:spro.layerPolishing})
} }
let slope = BASE.newSlope(p1, p2); let slope = BASE.newSlope(p1, p2);
let angle = Math.abs(slope.angle); let angle = Math.abs(slope.angle);
if (angle < 160 && angle > 20) { if (angle > 20 && angle < 160) {
return; return;
} }
let len = p1.distTo2D(p2); let len = p1.distTo2D(p2);
@ -269,13 +273,19 @@ console.log({polish:spro.layerPolishing})
p1 = BASE.newPoint(p1.x,p1.z,p1.y); p1 = BASE.newPoint(p1.x,p1.z,p1.y);
p2 = BASE.newPoint(p2.x,p2.z,p2.y); p2 = BASE.newPoint(p2.x,p2.z,p2.y);
} }
p1.index = p2.index = 1;
if (lastp && p1.isEqual(lastp)) {
equal++;
}
lines.push(p1); lines.push(p1);
lines.push(p2); lines.push(lastp = p2);
points++;
}); });
}); });
if (lines.length && slice.tops.length) { if (lines.length && slice.tops.length) {
slice.tops[0].polish = lines; slice.tops[0].polish = lines;
} }
console.log(slice.z,equal,points);
} }
}); });
} }
@ -488,10 +498,14 @@ console.log({polish:spro.layerPolishing})
} }
layerout.layer = layer; layerout.layer = layer;
// layerout.height = layerout.height || (layer === 0 ? firstLayerHeight : process.sliceHeight);
// if layer produced output, append to output array
if (layerout.length) output.append(layerout); if (layerout.length) output.append(layerout);
// notify progress
layer++; layer++;
update(layer / maxLayers); update(layer / maxLayers);
// retract after last layer // retract after last layer
if (layer === maxLayers && layerout.length) { if (layer === maxLayers && layerout.length) {
layerout.last().retract = true; layerout.last().retract = true;

View file

@ -613,12 +613,15 @@ var gs_kiri_print = exports;
}); });
} }
function outputFills(lines, bounds, fast) { function outputFills(lines, options) {
var p, p1, p2, dist, len, found, group, mindist, t1, t2, var p, p1, p2, dist, len, found, group, mindist, t1, t2,
marked = 0, marked = 0,
start = 0, start = 0,
skip = false, skip = false,
lastIndex = -1; lastIndex = -1,
opt = options || {},
fast = opt.fast || false,
fill = opt.fill >= 0 ? opt.fill : fillMult;
while (lines && marked < lines.length) { while (lines && marked < lines.length) {
found = false; found = false;
@ -683,7 +686,7 @@ var gs_kiri_print = exports;
// to avoid shaking the printer to death. // to avoid shaking the printer to death.
if (dist <= thinWall && len <= thinWall) { if (dist <= thinWall && len <= thinWall) {
p2 = p1.midPointTo(p2); p2 = p1.midPointTo(p2);
addOutput(preout, p2, fillMult * (dist / thinWall), fillSpeed); addOutput(preout, p2, fill * (dist / thinWall), fillSpeed);
} else { } else {
// retract if dist trigger or crosses a slice top polygon // retract if dist trigger or crosses a slice top polygon
if (dist > retractDist && (zhop || intersectsTop(startPoint, p1))) { if (dist > retractDist && (zhop || intersectsTop(startPoint, p1))) {
@ -697,12 +700,12 @@ var gs_kiri_print = exports;
// bridge ends of fill when they're close together // bridge ends of fill when they're close together
if (dist < thinWall) { if (dist < thinWall) {
addOutput(preout, p1, fillMult, fillSpeed); addOutput(preout, p1, fill, fillSpeed);
} else { } else {
addOutput(preout, p1, 0, moveSpeed); addOutput(preout, p1, 0, moveSpeed);
} }
addOutput(preout, p2, fillMult, fillSpeed); addOutput(preout, p2, fill, fillSpeed);
} }
startPoint = p2; startPoint = p2;
@ -762,7 +765,7 @@ var gs_kiri_print = exports;
outputTraces([next].appendAll(next.inner || [])); outputTraces([next].appendAll(next.inner || []));
if (next.fills) { if (next.fills) {
next.fills.forEach(function(p) { p.z = z }); next.fills.forEach(function(p) { p.z = z });
outputFills(next.fills, next.inner, true); outputFills(next.fills, {fast: true});
} }
} else { } else {
// top object // top object
@ -786,8 +789,8 @@ var gs_kiri_print = exports;
outputTraces([].appendAll(next.innerTraces() || []), bounds); outputTraces([].appendAll(next.innerTraces() || []), bounds);
// then output solid and sparse fill // then output solid and sparse fill
outputFills(next.fill_lines, bounds); outputFills(next.fill_lines);
outputSparse(next.fill_sparse, bounds); outputSparse(next.fill_sparse);
lastTop = next; lastTop = next;
} }
@ -795,6 +798,12 @@ var gs_kiri_print = exports;
return obj instanceof Polygon ? obj : obj.poly; return obj instanceof Polygon ? obj : obj.poly;
}); });
// produce polishing paths when present
if (slice.tops.length) {
let polish = slice.tops[0].polish;
outputFills(polish, {fast: true, fill:0});
}
// offset print points // offset print points
for (i=0; i<preout.length; i++) { for (i=0; i<preout.length; i++) {
preout[i].point = preout[i].point.add(offset); preout[i].point = preout[i].point.add(offset);

View file

@ -636,17 +636,6 @@ var gs_kiri_widget = exports;
if (!cam) slices.forEach(function(s) { s.renderSparseFill() }); if (!cam) slices.forEach(function(s) { s.renderSparseFill() });
// render supports // render supports
if (!cam) slices.forEach(function(s) { s.renderSupport() }); if (!cam) slices.forEach(function(s) { s.renderSupport() });
// render polish (sent in debug mode only)
if (this.polish && false) {
let layer = KIRI.newLayer(this.mesh.newGroup());
this.polish.x.forEach(poly => {
layer.poly(poly, 0xff0000, false, false);
});
this.polish.y.forEach(poly => {
layer.poly(poly, 0x0000ff, false, false);
});
layer.render();
}
}; };
PRO.hideSlices = function() { PRO.hideSlices = function() {

View file

@ -493,7 +493,8 @@ self.kiri.license = exports.LICENSE;
DOC = SELF.document, DOC = SELF.document,
LOC = SELF.location, LOC = SELF.location,
SETUP = parseOpt(LOC.search.substring(1)), SETUP = parseOpt(LOC.search.substring(1)),
LOCAL = LOC.host.indexOf('localhost') === 0, HOST = LOC.host.split(':'),
LOCAL = HOST[0] === 'localhost' || HOST[0] === 'debug',
SECURE = isSecure(LOC.protocol), SECURE = isSecure(LOC.protocol),
// --------------- // ---------------
SDB = MOTO.KV, SDB = MOTO.KV,