From 11225739e5515b481f96e10bd9bba955cf82e770 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 24 Jun 2021 18:15:51 -0400 Subject: [PATCH] start adding threading to SLA --- src/geo/polygons.js | 5 +++++ src/kiri/init.js | 2 +- src/kiri/worker.js | 6 +++--- src/mode/sla/slice.js | 41 +++++++++++++++++++++++++++-------------- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/geo/polygons.js b/src/geo/polygons.js index 5d8304e1..7888ced7 100644 --- a/src/geo/polygons.js +++ b/src/geo/polygons.js @@ -29,6 +29,7 @@ trimTo, expand, expand_lines, + points, route, union, inset, @@ -145,6 +146,10 @@ return output; } + function points(polys) { + return polys.length ? polys.map(p => p.deepLength).reduce((a,v) => a+v) : 0; + } + /** * todo use clipper polytree? * diff --git a/src/kiri/init.js b/src/kiri/init.js index db80f30d..ea27864d 100644 --- a/src/kiri/init.js +++ b/src/kiri/init.js @@ -1643,7 +1643,7 @@ detail: UC.newSelect(LANG.pt_qual_s, {title: LANG.pt_qual_l, action: detailSave}, "detail"), decimate: UC.newBoolean(LANG.pt_deci_s, booleanSave, {title: LANG.pt_deci_l}), healMesh: UC.newBoolean(LANG.pt_heal_s, booleanSave, {title: LANG.pt_heal_l}), - threaded: UC.newBoolean(LANG.pt_thrd_s, booleanSave, {title: LANG.pt_thrd_l, modes:FDM}), + threaded: UC.newBoolean(LANG.pt_thrd_s, booleanSave, {title: LANG.pt_thrd_l, modes:FDM_SLA}), prefadd: UC.checkpoint($('prefs-add')), diff --git a/src/kiri/worker.js b/src/kiri/worker.js index a4e95e5a..f5e0b13d 100644 --- a/src/kiri/worker.js +++ b/src/kiri/worker.js @@ -54,8 +54,8 @@ KIRI.minions = { union: function(polys, minarea) { return new Promise((resolve, reject) => { - if (concurrent < 2 || polys.length * 2 < concurrent) { - resolve(POLY.union(polys, 0, true)); + if (concurrent < 2 || polys.length < concurrent * 2 || POLY.points(polys) < concurrent * 50) { + resolve(POLY.union(polys, minarea, true)); return; } let polyper = Math.ceil(polys.length / concurrent); @@ -65,7 +65,7 @@ KIRI.minions = { let polys = KIRI.codec.decode(data.union); union.appendAll(polys); if (--running === 0) { - resolve(POLY.union(union, 0, true)); + resolve(POLY.union(union, minarea, true)); } }; for (let i=0; i { if (slice.synth) return; FDM.doDiff(slice, 0.000001, true, !process.slaOpenBase); @@ -154,14 +152,22 @@ FDM.projectFlats(slice, solidLayers); FDM.projectBridges(slice, solidLayers); }, "project"); - forSlices(slices, 10, (slice) => { + async function doUnionSolid(slice) { if (slice.synth) return; let traces = POLY.nest(POLY.flatten(slice.topShells())); - let trims = slice.solids || []; - traces.appendAll(trims); - let union = POLY.union(traces, undefined, true); - slice.unioned = POLY.setZ(union, slice.z); - }, "solid"); + if (slice.solids) { + let trims = slice.solids || []; + traces.appendAll(trims); + // slice.unioned = POLY.setZ(POLY.union(traces, undefined, true), slice.z); + slice.unioned = POLY.setZ(await KIRI.minions.union(traces), slice.z); + } else { + slice.unioned = traces; + } + } + let promises = slices.map(slice => doUnionSolid(slice)); + await tracker(promises, (i, t) => { + doupdate(10 / promises.length, "solid"); + }); } else { forSlices(slices, 10, (slice) => { if (slice.synth) return; @@ -181,7 +187,14 @@ }); } doRender(widget); - ondone(); + } + + SLICER.sliceWidget(widget, { + height: height, + add: !process.slaOpenTop, + concurrent: isConcurrent + }, function(slices) { + onSliceDone(slices).then(ondone); }, function(update) { return onupdate(0.0 + update * 0.25); });