diff --git a/notes.md b/notes.md index 6154592a..e56a12f8 100644 --- a/notes.md +++ b/notes.md @@ -2,8 +2,7 @@ ## 2.3 remaining * cap path ends -* rulers need to follow workspace units -* rough/outline shadow needs to respect flats even when not used as slices +* fix ruler axis name label * onshape mouse mapping option ## 2.4 tenative list diff --git a/src/kiri/slicer2.js b/src/kiri/slicer2.js index 6ce970e9..3f01f0b6 100644 --- a/src/kiri/slicer2.js +++ b/src/kiri/slicer2.js @@ -189,6 +189,7 @@ slice(z, options, index, total, mark) { const opt = this.setOptions(options); + // if Z is supplied as an array, iterate and collect if (Array.isArray(z)) { const mark = UTIL.time(); const rarr = []; @@ -207,6 +208,7 @@ buckets = this.buckets, bucket = buckets.length ? buckets[Math.floor(z * zScale)] : this.points; + // compensate by moving z by "flatoff" on flats if (onflat) { z += flatoff; } diff --git a/src/mode/cam/slice.js b/src/mode/cam/slice.js index 08cc2f1d..f7640e31 100644 --- a/src/mode/cam/slice.js +++ b/src/mode/cam/slice.js @@ -166,10 +166,11 @@ if (procRough) { nextOp(); maxToolDiam = Math.max(maxToolDiam, roughToolDiam); + + let flats = []; let shadow = []; let slices = []; let indices = slicer.interval(roughDown, { down: true, min: zBottom, fit: true }); - // add flats if (proc.camRoughFlat) { let flats = Object.keys(slicer.zFlat) .map(v => parseFloat(v).round(4)) @@ -193,10 +194,20 @@ indices[i] = next + ((prev - next) / 2); } } + } else { + // add flats to shadow + flats = Object.keys(slicer.zFlat) + .map(v => (parseFloat(v) - 0.01).round(5)) + .filter(v => v > 0 && indices.indexOf(v) < 0); + indices = indices.appendAll(flats).sort((a,b) => b-a); } // console.log('indices', ...indices, {zBottom}); slicer.slice(indices, { each: (data, index, total) => { shadow = POLY.union(shadow.appendAll(data.tops), 0.01, true); + if (flats.indexOf(data.z) >= 0) { + // exclude flats injected to complete shadow + return; + } data.shadow = shadow.clone(true); data.slice.camMode = PRO.ROUGH; data.slice.shadow = data.shadow; @@ -295,10 +306,19 @@ let shadow = []; let slices = []; - const indices = slicer.interval(outlineDown, { down: true, min: zBottom, fit: true }); + let indices = slicer.interval(outlineDown, { down: true, min: zBottom, fit: true }); + // add flats to shadow + const flats = Object.keys(slicer.zFlat) + .map(v => (parseFloat(v) - 0.01).round(5)) + .filter(v => v > 0 && indices.indexOf(v) < 0); + 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); + if (flats.indexOf(data.z) >= 0) { + // exclude flats injected to complete shadow + return; + } data.shadow = shadow.clone(true); data.slice.camMode = PRO.OUTLINE; data.slice.shadow = data.shadow; @@ -325,7 +345,7 @@ } slices.forEach(slice => { - let tops = slice.shadow;//.clone(true); + let tops = slice.shadow; let offset = POLY.expand(tops, outlineToolDiam / 2, slice.z); if (!(offset && offset.length)) { return;