detect 'flats' at the start and end of z-curved regions

This commit is contained in:
Stewart Allen 2020-02-18 22:24:05 -05:00
commit 56fc8afe52
2 changed files with 41 additions and 18 deletions

View file

@ -138,22 +138,24 @@ var gs_kiri_slicer = exports;
countZ(p2.z); countZ(p2.z);
countZ(p3.z); countZ(p3.z);
} }
// detect zLines // detect zLines (curved region tops/bottoms)
// if (p1.z === p2.z && p1.z > bounds.min.z) { if (options.cam) {
// let zkey = p1.z.toFixed(5); if (p1.z === p2.z && p1.z > bounds.min.z) {
// let zval = zLines[zkey]; let zkey = p1.z.toFixed(5);
// zLines[zkey] = (zval || 0) + 1; let zval = zLines[zkey];
// } zLines[zkey] = (zval || 0) + 1;
// if (p2.z === p3.z && p2.z > bounds.min.z) { }
// let zkey = p2.z.toFixed(5); if (p2.z === p3.z && p2.z > bounds.min.z) {
// let zval = zLines[zkey]; let zkey = p2.z.toFixed(5);
// zLines[zkey] = (zval || 0) + 1; let zval = zLines[zkey];
// } zLines[zkey] = (zval || 0) + 1;
// if (p3.z === p1.z && p3.z > bounds.min.z) { }
// let zkey = p3.z.toFixed(5); if (p3.z === p1.z && p3.z > bounds.min.z) {
// let zval = zLines[zkey]; let zkey = p3.z.toFixed(5);
// zLines[zkey] = (zval || 0) + 1; let zval = zLines[zkey];
// } zLines[zkey] = (zval || 0) + 1;
}
}
// auto-detect flats for cam faces and to avoid slicing directly on flats // auto-detect flats for cam faces and to avoid slicing directly on flats
if (p1.z === p2.z && p2.z === p3.z && p1.z > bounds.min.z) { if (p1.z === p2.z && p2.z === p3.z && p1.z > bounds.min.z) {
var zkey = p1.z.toFixed(5), var zkey = p1.z.toFixed(5),
@ -166,6 +168,26 @@ var gs_kiri_slicer = exports;
} }
} }
let zlk, zlv;
// detect zLines bottoms and translate to zFlats
Object.entries(zLines)
.map(v => [v[0], v[1], parseFloat(v[0])])
.sort((a,b) => {
return a[2] - b[2]
})
.forEach(zl => {
if (zlk) {
if (zlv != zl[1]) {
zFlat[zlk] = zlv;
zlv = zl[1];
}
zlk = zl[0];
} else {
zlk = zl[0];
zlv = zl[1];
}
});
/** bucket polygons into z-bounded groups */ /** bucket polygons into z-bounded groups */
var bucketCount = Math.max(1, Math.ceil(zMax / (zSum / points.length)) - 1); var bucketCount = Math.max(1, Math.ceil(zMax / (zSum / points.length)) - 1);
@ -221,7 +243,8 @@ var gs_kiri_slicer = exports;
for (key in zFlat) { for (key in zFlat) {
// todo make threshold for flat detection configurable // todo make threshold for flat detection configurable
if (!zFlat.hasOwnProperty(key) || zFlat[key] < 10) continue; if (!zFlat.hasOwnProperty(key) || zFlat[key] < 10) continue;
if (!zIndexes.contains(key) && key >= zMin) zIndexes.push(parseFloat(key)); key = parseFloat(key);
if (!zIndexes.contains(key) && key >= zMin) zIndexes.push(key);
} }
// sort top down // sort top down
zIndexes.sort(function(a,b) { zIndexes.sort(function(a,b) {

View file

@ -1,7 +1,7 @@
var exports = { var exports = {
COPYRIGHT:"Copyright (C) 2014-2019 Stewart Allen <sa@grid.space> - All Rights Reserved", COPYRIGHT:"Copyright (C) 2014-2019 Stewart Allen <sa@grid.space> - All Rights Reserved",
LICENSE:"See the license.md file included with the source distribution", LICENSE:"See the license.md file included with the source distribution",
VERSION:"1.6.1" VERSION:"1.6.2"
}; };
if (!module) var module = {}; if (!module) var module = {};
module.exports = exports; module.exports = exports;