fix restore from .km preserving widget annotations. fix trace ordering for tops that split down. fix support z span

This commit is contained in:
Stewart Allen 2021-02-18 22:47:52 -05:00
commit 125f9cb16b
4 changed files with 72 additions and 30 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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;
});

View file

@ -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;