diff --git a/src/geo/polygon.js b/src/geo/polygon.js index a51d576c..28a27a5c 100644 --- a/src/geo/polygon.js +++ b/src/geo/polygon.js @@ -1389,7 +1389,7 @@ * @param {Polygon} poly clipping mask * @returns {?Polygon[]} */ - PRO.mask = function(poly) { + PRO.mask = function(poly, nullOnEquiv) { let fillang = this.fillang && this.area() > poly.area() ? this.fillang : poly.fillang, clib = self.ClipperLib, ctyp = clib.ClipType, @@ -1408,6 +1408,9 @@ poly.forEach(function(p) { p.fillang = fillang; }) + if (nullOnEquiv && poly.length === 1 && poly[0].isEquivalent(this)) { + return null; + } return poly; } else { return null; @@ -1454,7 +1457,7 @@ }); return cuts; } else { - return this; + return null; } }; diff --git a/src/mode/cam/client.js b/src/mode/cam/client.js index 0fb5f89b..20a7ee70 100644 --- a/src/mode/cam/client.js +++ b/src/mode/cam/client.js @@ -240,6 +240,12 @@ layers.setLayer("trace", {line: 0x88aa55}, false).addPoly(poly); stack.addLayers(layers); }); + // for (let [key, val] of Object.entries(widget.sindex)) { + // console.log('sindex', {key, val}); + // let layers = new KIRI.Layers(); + // layers.setLayer("sindex", {line: 0x55aa88}, false).addPolys(val); + // stack.addLayers(layers); + // } widget.adds.appendAll(stack.meshes); }); }); diff --git a/src/mode/cam/driver.js b/src/mode/cam/driver.js index 87767ee6..e7809691 100644 --- a/src/mode/cam/driver.js +++ b/src/mode/cam/driver.js @@ -32,6 +32,7 @@ send("traces", { settings }, output => { KIRI.codec.decode(output).forEach(rec => { widgets[rec.id].traces = rec.traces; + widgets[rec.id].sindex = rec.sindex; }); ondone(true); }); @@ -44,7 +45,8 @@ widgets.forEach(widget => CAM.traces(settings, widget)); send.done(KIRI.codec.encode(widgets.map(widget => {return { id: widget.id, - traces: widget.traces + traces: widget.traces, + sindex: widget.sindex }}))); }; diff --git a/src/mode/cam/slice.js b/src/mode/cam/slice.js index b60c621f..c2fccc12 100644 --- a/src/mode/cam/slice.js +++ b/src/mode/cam/slice.js @@ -147,7 +147,7 @@ tzindex = [ tzindex.pop() ]; } let terrain = slicer.slice(tzindex, { each: (data, index, total) => { - tshadow = POLY.union(tshadow.appendAll(data.tops), 0.01, true); + tshadow = POLY.union(tshadow.slice().appendAll(data.tops), 0.01, true); tslices.push(data.slice); if (false) { const slice = data.slice; @@ -242,7 +242,7 @@ // console.log('indices', ...indices, {zBottom}); slicer.slice(indices, { each: (data, index, total) => { - shadow = POLY.union(shadow.appendAll(data.tops), 0.01, true); + shadow = POLY.union(shadow.slice().appendAll(data.tops), 0.01, true); if (flats.indexOf(data.z) >= 0) { // exclude flats injected to complete shadow return; @@ -373,7 +373,7 @@ indices = indices.appendAll(flats).sort((a,b) => b-a); // console.log('indices', ...indices, {zBottom, slicer}); slicer.slice(indices, { each: (data, index, total) => { - shadow = POLY.union(shadow.appendAll(data.tops), 0.01, true); + shadow = POLY.union(shadow.slice().appendAll(data.tops), 0.01, true); if (flats.indexOf(data.z) >= 0) { // exclude flats injected to complete shadow return; @@ -535,9 +535,19 @@ }) .filter(v => v !== null)))] .sort((a,b) => b - a); + + // create shadow + let sindex = {}; + let shadow = []; + let sindices = indices.map((v,i) => v > 0 ? v : v + 0.005 ); + slicer.slice(sindices, { each: (data, index, total) => { + shadow = POLY.union(shadow.slice().appendAll(data.tops), 0, true); + POLY.setZ(shadow, data.z); + sindex[index] = shadow; + }, flatoff: 0 }); let traces = []; + // find and trim polys (including open) to shadow let oneach = (data, index, total) => { - // create separate slice for each poly (and inner) BASE.polygons.flatten(data.tops,null,true).forEach(poly => { for (let i=0, il=traces.length; i 0) { + let trim = trimto.shift(); + let mask = poly.mask(trim, true); + if (mask) { + trimto.appendAll(mask); + } else { + traces.push(poly); + } + } + if (limit === 1000) { + traces.push(poly); + } + } }); }; let opts = { each: oneach, over: false, flatoff: 0, edges: true, openok: true }; @@ -553,6 +593,7 @@ opts.over = true; slicer.slice(indices, opts); widget.traces = traces; + widget.sindex = sindex; }; // drilling op