add wasm option on other calls. disable wasm subtract/diff

This commit is contained in:
Stewart Allen 2021-07-11 20:13:11 -04:00
commit e3e2aeae5c
3 changed files with 24 additions and 13 deletions

View file

@ -1860,7 +1860,6 @@
// m1: src[1].isEqual2D(dst[1]) // m1: src[1].isEqual2D(dst[1])
// }); // });
} }
return null;
} }
return union; return union;
} }

View file

@ -314,7 +314,8 @@
opt.prof.call = (opt.prof.call || 0) + 1; opt.prof.call = (opt.prof.call || 0) + 1;
} }
if (opt.wasm && geo.wasm) { // wasm diff currently doesn't seem to be any faster
if (false && opt.wasm && geo.wasm) {
let oA = outA ? [] : undefined; let oA = outA ? [] : undefined;
let oB = outB ? [] : undefined; let oB = outB ? [] : undefined;
geo.wasm.js.diff(setA, setB, z, oA, oB); geo.wasm.js.diff(setA, setB, z, oA, oB);
@ -377,9 +378,20 @@
* @param {Polygon[]} polys * @param {Polygon[]} polys
* @returns {Polygon[]} * @returns {Polygon[]}
*/ */
function union(polys, minarea, all) { function union(polys, minarea, all, opt = {}) {
if (polys.length < 2) return polys; if (polys.length < 2) return polys;
if (opt.wasm && geo.wasm) {
let min = minarea || 0.01;
// let deepLength = polys.map(p => p.deepLength).reduce((a,v) => a+v);
// if (deepLength < 15000)
try {
return geo.wasm.js.union(polys, polys[0].getZ()).filter(p => p.area() > min);
} catch (e) {
console.log({union_fail: polys, minarea, all, deepLength});
}
}
let out = polys.slice(), i, j, union, uset = []; let out = polys.slice(), i, j, union, uset = [];
outer: for (i=0; i<out.length; i++) { outer: for (i=0; i<out.length; i++) {

View file

@ -448,7 +448,7 @@
if (solidLayers && !vaseMode && !isSynth) { if (solidLayers && !vaseMode && !isSynth) {
profileStart("delta"); profileStart("delta");
forSlices(0.2, 0.34, slice => { forSlices(0.2, 0.34, slice => {
if (slice.index > 0) doDiff(slice, solidMinArea, { wasm: useAssembly }); if (slice.index > 0) doDiff(slice, solidMinArea);
}, "layer deltas"); }, "layer deltas");
profileEnd(); profileEnd();
profileStart("delta-project"); profileStart("delta-project");
@ -1058,7 +1058,7 @@
} }
POLY.subtract(topInner, downInner, bridges, flats, slice.z, minArea, { POLY.subtract(topInner, downInner, bridges, flats, slice.z, minArea, {
wasm: options.wasm wasm: true
}); });
}; };
@ -1104,7 +1104,7 @@
return; return;
} }
let unioned = POLY.union(solids, undefined, true).flat(), let unioned = POLY.union(solids, undefined, true, { wasm: true }).flat(),
isSLA = (spacing === undefined && angle === undefined); isSLA = (spacing === undefined && angle === undefined);
if (solids.length === 0) return false; if (solids.length === 0) return false;
@ -1289,9 +1289,9 @@
pillars.push(BASE.newPolygon().centerRectangle(point, size/2, size/2)); pillars.push(BASE.newPolygon().centerRectangle(point, size/2, size/2));
}); });
supports.appendAll(POLY.union(pillars, null, true)); supports.appendAll(POLY.union(pillars, null, true, { wasm: false }));
// merge pillars and replace with convex hull of outer points (aka smoothing) // merge pillars and replace with convex hull of outer points (aka smoothing)
pillars = POLY.union(pillars, null, true).forEach(function(pillar) { pillars = POLY.union(pillars, null, true, { wasm: false }).forEach(function(pillar) {
supports.push(BASE.newPolygon().createConvexHull(pillar.points)); supports.push(BASE.newPolygon().createConvexHull(pillar.points));
}); });
})(); })();
@ -1318,7 +1318,7 @@
if (supports.length > 10) { if (supports.length > 10) {
supports = await KIRI.minions.union(supports); supports = await KIRI.minions.union(supports);
} else { } else {
supports = POLY.union(supports, null, true); supports = POLY.union(supports, null, true, { wasm: false });
} }
// clip to top polys // clip to top polys
@ -1332,7 +1332,7 @@
// culled = supports; // culled = supports;
// clip supports to shell offsets // clip supports to shell offsets
POLY.subtract(supports, down.topSimples(), trimmed, null, slice.z, minArea); POLY.subtract(supports, down.topSimples(), trimmed, null, slice.z, minArea, { wasm: false });
// set depth hint on support polys for infill density // set depth hint on support polys for infill density
trimmed.forEach(function(trim) { trimmed.forEach(function(trim) {
@ -1364,15 +1364,15 @@
if (!supports) return; if (!supports) return;
// union supports // union supports
supports = POLY.setZ(POLY.union(supports, undefined, true), slice.z); supports = POLY.setZ(POLY.union(supports, undefined, true, { wasm: false }), slice.z);
// clip supports to slice clip offset (or shell if none) // clip supports to slice clip offset (or shell if none)
POLY.subtract(supports, slice.clips, nsB, null, slice.z, min); POLY.subtract(supports, slice.clips, nsB, null, slice.z, min, { wasm: false });
supports = nsB; supports = nsB;
// also trim to lower offsets, if they exist // also trim to lower offsets, if they exist
if (slice.down && slice.down.clips) { if (slice.down && slice.down.clips) {
POLY.subtract(nsB, slice.down.clips, nsC, null, slice.z, min); POLY.subtract(nsB, slice.down.clips, nsC, null, slice.z, min, { wasm: false });
supports = nsC; supports = nsC;
} }