diff --git a/src/geo/polygon.js b/src/geo/polygon.js index 1fa84def..bc87b87b 100644 --- a/src/geo/polygon.js +++ b/src/geo/polygon.js @@ -737,6 +737,7 @@ inner.move(offset); } } + return this; }; /** @@ -760,6 +761,7 @@ inner.scale(scale, round); } } + return this; }; /** diff --git a/src/kiri/slicer.js b/src/kiri/slicer.js index 257bf19e..4868c99c 100644 --- a/src/kiri/slicer.js +++ b/src/kiri/slicer.js @@ -46,11 +46,8 @@ * @param {Function} onupdate callback to report slicing progress */ function slice(points, bounds, options, ondone, onupdate) { - let topoMode = options.topo, - simpleMode = options.simple, - useFlats = options.flats, + let useFlats = options.flats, swap = options.swapX || options.swapY, - isCam = options.cam, debug = options.debug, xray = options.xray, ox = 0, @@ -267,29 +264,6 @@ zIndexes.push((zl[i] + zl[i+1]) / 2); 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) { // console.log('adaptive slicing', zIncMin, ':', zInc, 'from', zMin, 'to', zMax); // FDM adaptive slicing @@ -360,23 +334,13 @@ if (zFlat[ik]) onFlat = true; if (zLines[ik]) onLine = true; if (!useFlats && (onFlat || onLine)) { - zIndexes[i] += isCam ? 0.001 : -0.001; + zIndexes[i] -= -0.001; } // slice next layer and add to slices[] array 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); } - // 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 for (i=1; i { - const group = i % dash; - const color = [ 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff ][group]; - slice.output().setLayer(`xl-${group}`, color).addLine(line.p1, line.p2); - }); - } - POLY.nest(slice.groups).forEach((poly, i) => { - slice.addTop(poly); - if (xray) { - const group = i % (xray || 3); - const color = [ 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff ][group]; - slice.output().setLayer(`xg-${group}`, color).addPoly(poly); - } + // de-dup and group lines + lines = removeDuplicateLines(lines); + let groups = connectLines(lines, slice.z); + + // simplistic healing of bad meshes + if (options.union) { + groups = POLY.flatten(POLY.union(POLY.nest(groups), null, true), null, true); + } + + if ((debug && lines.excessive) || xray) { + const dash = xray || 3; + lines.forEach((line, i) => { + const group = i % dash; + const color = [ 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff ][group]; + slice.output().setLayer(`xl-${group}`, color).addLine(line.p1, line.p2); }); } - // 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 { - poly.swap(options.swapX, options.swapY); - poly.move(move); - poly.inner = null; - }); + // identify and add tops to slice + POLY.nest(groups).forEach((poly, i) => { + slice.addTop(poly); + if (xray) { + const group = i % (xray || 3); + const color = [ 0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff ][group]; + slice.output().setLayer(`xg-${group}`, color).addPoly(poly); } - } + }); + slices.push(slice); - if (!(topoMode || simpleMode)) { - delete slice.lines; - delete slice.groups; - } + return slice; } } diff --git a/src/mode/fdm/slice.js b/src/mode/fdm/slice.js index 41bbbea8..dba8eb8b 100644 --- a/src/mode/fdm/slice.js +++ b/src/mode/fdm/slice.js @@ -439,7 +439,6 @@ sliceFillAngle += 90.0; }, "fill solids"); if (promises) { - console.log({fill_awaiting: promises.length}); await Promise.all(promises); } } @@ -470,7 +469,6 @@ lastType = newType; }, "infill"); if (promises) { - console.log({infill_awaiting: promises.length}); await Promise.all(promises); } } else if (isSynth) { diff --git a/src/mode/sla/export.js b/src/mode/sla/export.js index 2c31462d..61c9df24 100644 --- a/src/mode/sla/export.js +++ b/src/mode/sla/export.js @@ -485,12 +485,11 @@ function scaleMovePoly(poly) { let points = poly.points; - let bounds = poly.bounds = BASE.newBounds(); + poly._bounds = undefined; for (let i=0, il=points.length; i