attempt to fix flat detection and processing

This commit is contained in:
Stewart Allen 2019-01-09 13:53:22 -05:00
commit f89953bb32
2 changed files with 10 additions and 19 deletions

View file

@ -139,7 +139,7 @@ var gs_kiri_slicer = exports;
}
// 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) {
var zkey = UTIL.round(p1.z, 5),
var zkey = p1.z.toFixed(5),
area = Math.abs(UTIL.area2(p1,p2,p3)) / 2;
if (!zFlat[zkey]) {
zFlat[zkey] = area;
@ -201,8 +201,7 @@ var gs_kiri_slicer = exports;
for (key in zFlat) {
// todo make threshold for flat detection configurable
if (!zFlat.hasOwnProperty(key) || zFlat[key] < 100) continue;
key = parseFloat(key) + 0.001;
if (!zIndexes.contains(key) && key >= zMin) zIndexes.push(key);
if (!zIndexes.contains(key) && key >= zMin) zIndexes.push(parseFloat(key));
}
// sort top down
zIndexes.sort(function(a,b) {
@ -362,25 +361,20 @@ var gs_kiri_slicer = exports;
* @param {number} [height] optional real height (fdm)
*/
function sliceZ(z, height) {
z = UTIL.round(z,5);
// avoid slicing directly on flat faces as it greatly increases
// the chances of artifacts, broken joins and excessive path walks
if (zFlat[z]) {
if (z) {
z -= 0.001;
} else {
z += 0.001;
}
}
var phash = {},
lines = [],
onflat = zFlat[z.toFixed(5)] > 0,
slice = newSlice(z, options.view ? options.view.newGroup() : null),
bucket = bucketCount == 1 ? points : buckets[Math.floor(z * zScale)];
if (!bucket) return;
if (onflat) {
// annotate slices with cam flats for finishing waterlines
if (options.cam) slice.hasFlats = true;
z += 0.001;
}
// iterate over matching buckets for this z offset
for (var i = 0; i < bucket.length;) {
p1 = bucket[i++];
@ -423,9 +417,6 @@ var gs_kiri_slicer = exports;
slice.index = slices.length;
slice.lines = removeDuplicateLines(lines);
// annotate slices with cam flats for finishing waterlines
if (options.cam) slice.hasFlats = zFlat[z] > 0;
// for topo slices, we just need the raw lines
if (!topoMode) {
slice.groups = connectLines(slice.lines, slices.length);

View file

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