diff --git a/notes.md b/notes.md index d59af98f..41b35fc4 100644 --- a/notes.md +++ b/notes.md @@ -54,6 +54,7 @@ # FDM - BELT +* `B` auto bed resizing leaves the origin in the wrong place at first * `B` ranges don't work with anchors * `B` multiple parts with one angled against origin "floats" in preview * `B` re-add progress calls for all work units diff --git a/src/kiri/main.js b/src/kiri/main.js index 6d65f95e..eec825b6 100644 --- a/src/kiri/main.js +++ b/src/kiri/main.js @@ -2271,10 +2271,11 @@ } } if (isSettings) { + clearWorkspace(); settings = CONF.normalize(data.settings); SDB.setItem('ws-settings', JSON.stringify(settings)); - if (LOCAL) console.log('settings',Object.clone(settings)); restoreSettings(); + if (LOCAL) console.log('settings',Object.clone(settings)); if (isWork) { API.platform.clear(); KIRI.codec.decode(data.work).forEach(widget => { @@ -2416,7 +2417,6 @@ function restoreSettings(save) { let newset = ls2o('ws-settings') || settings; - settings = CONF.normalize(newset); // override camera from settings if (settings.controller.view) { diff --git a/src/kiri/print.js b/src/kiri/print.js index e4e3e094..b55057ad 100644 --- a/src/kiri/print.js +++ b/src/kiri/print.js @@ -566,12 +566,48 @@ return int; } - function outputTraces(poly, extrude) { + function outputTraces(poly, opt = {}) { if (!poly) return; if (Array.isArray(poly)) { - outputOrderClosest(poly, function(next) { - outputTraces(next, extrude); - }, null); + if (opt.sort) { + let polys = poly.slice().sort(function(a,b) { + return (a.perimeter() - b.perimeter()) * opt.sort; + }); + let debug = polys.length > 3; + let last; + while (polys.length) { + let next; + for (let p of polys) { + if (!last) { + next = p; + break; + } + if (opt.sort > 0) { + // in-out + if (last.isInside(p)) { + next = p; + break; + } + } else { + // out-in + if (p.isInside(last)) { + next = p; + break; + } + } + } + if (next) { + last = next; + polys.remove(next); + outputTraces(next, opt); + } else { + last = null; + } + } + } + // outputOrderClosest(poly, function(next) { + // outputTraces(next, opt); + // }, null); } else { let finishShell = poly.depth === 0 && !firstLayer; startPoint = scope.polyPrintPath(poly, startPoint, preout, { @@ -580,7 +616,7 @@ accel: finishShell, wipe: process.outputWipeDistance || 0, coast: firstLayer ? 0 : coastDist, - extrude: pref(extrude, shellMult), + extrude: pref(opt.extrude, shellMult), onfirst: function(firstPoint) { if (startPoint.distTo2D(firstPoint) > retractDist) { retract(); @@ -776,11 +812,11 @@ * the special exception that depth is considered into distance * so that inner polygons are emitted first. * - * @param {Array} array of Polygon or Polygon wrappers - * @param {Function} fn - * @param {Function} fnp convert 'next' object into a Polygon + * @param {Array} array of Polygons or Polygon wrappers (tops) + * @param {Function} fn call to emit next candidate + * @param {Function} fnp convert 'next' object into a Polygon for closeness */ - function outputOrderClosest(array, fn, fnp, newTop) { + function outputOrderClosest(array, fn, fnp) { if (array.length === 1) { return fn(array[0]); } @@ -800,7 +836,6 @@ d: find.distance - (poly.depth * thinWall), }); } - newTop = false; if (order.length === 0) { return; } @@ -848,23 +883,24 @@ shellOrder = -1; } - // top object - let bounds = POLY.flatten(next.shellsAtDepth(0).clone(true)); + // innermost shells + let inner = next.innerShells() || []; // output inner polygons - if (shellOrder === 1) - outputTraces([].appendAll(next.innerShells() || [])); + if (shellOrder === 1) outputTraces(inner); + + outputTraces(next.shells, { sort: shellOrder }); // sort perimeter polygon by length to go out-to-in or in-to-out - (next.shells || []).sort(function(a,b) { - return a.perimeter() > b.perimeter() ? shellOrder : -shellOrder; - }).forEach(function(poly, index) { - outputTraces(poly); - }); + // this causes too much seeking when nesting splits into disconnected areas + // (next.shells || []).sort(function(a,b) { + // return a.perimeter() > b.perimeter() ? shellOrder : -shellOrder; + // }).forEach(function(poly, index) { + // outputTraces(poly); + // }); // output outer polygons - if (shellOrder === -1) - outputTraces([].appendAll(next.innerShells() || [])); + if (shellOrder === -1) outputTraces(inner); // output thin fill outputFills(next.thin_fill, {near: true}); @@ -876,6 +912,7 @@ lastTop = next; } }, function(obj) { + // for tops return obj instanceof Polygon ? obj : obj.poly; }); diff --git a/src/mode/fdm/client.js b/src/mode/fdm/client.js index 9d94cfe2..854a6b4f 100644 --- a/src/mode/fdm/client.js +++ b/src/mode/fdm/client.js @@ -9,8 +9,11 @@ UTIL = BASE.util, FDM = KIRI.driver.FDM, SPACE, API, VIEWS, LANG, PROC, UI, UC, + nextID = Date.now(), p1, p2, iw, - lastMode, lastView, lastPillar, fromPillar, + lastBox, + lastMode, lastView, + lastPillar, fromPillar, isFdmMode = false, addingSupports = false, alert = [], @@ -291,16 +294,16 @@ return; } if (!iw) return; + let { point, dim } = lastBox; p1.y = Math.max(0, p1.y); p2.y = Math.max(0, p2.y); - let hy = (p1.y + p2.y) / 2; - let dh = Math.abs(p1.y - p2.y); + let dh = dim.z; let dw = api.conf.get().process.sliceSupportSize / 2; let ip = iw.track.pos; let wa = api.widgets.annotate(iw.id); let ws = (wa.support = wa.support || []); - let x = p1.x - ip.x, y = -p1.z - ip.y, z = hy, id = Date.now(); - let rec = {x, y, z, dw, dh, id}; + let id = ++nextID; + let rec = {x: point.x - ip.x, y: -point.z - ip.y, z: point.y, dw, dh, id}; if (fromPillar && event && event.shiftKey) { let targets = api.widgets.meshes().append(SPACE.internals().platform); let from = fromPillar, @@ -350,7 +353,7 @@ let mp = (phi.y + plo.y) / 2; let dy = Math.abs(phi.y - plo.y); let dw = api.conf.get().process.sliceSupportSize / 2; - let rec = { rz:angle, x:point.x, y:point.z, z:mp, dw, dh:dy, id: id * 0xffffffffff }; + let rec = { rz:angle, x:point.x, y:point.z, z:mp, dw, dh:dy, id }; ws.push(Object.clone(rec)); fromPillar = addWidgetSupport(iw, rec); } @@ -416,7 +419,6 @@ Object.values(widget.sups || {}).forEach(support => { active.push(support.box); support.box.support = true; - // console.log({support}); }); }); return active; @@ -495,6 +497,8 @@ box.position.y = point.y; box.position.z = point.z; + lastBox = {point, dim}; + const group = opt.group || SPACE.scene group.add(box); box.groupTo = group;