add first approximation of thin fill

This commit is contained in:
Stewart Allen 2018-01-11 08:01:42 -05:00
commit 456f3f1e30
5 changed files with 69 additions and 16 deletions

View file

@ -493,7 +493,7 @@ var gs_base_polygons = exports;
polys = fromClipperTree(ctre, z);
// detect possible thin walls
if (polys.length && thins) {
if (thins) {
var circ1 = sumCirc(orig),
circ2 = sumCirc(polys),
diff = Math.abs(1 - (circ1 / circ2));
@ -578,6 +578,8 @@ var gs_base_polygons = exports;
* @returns {Point[]} supplied output or new array
*/
function fillArea(polys, angle, spacing, output, minLen, maxLen) {
if (polys.length === 0) return;
var i = 1,
p0 = polys[0],
zpos = p0.getZ(),

View file

@ -131,6 +131,7 @@ var gs_kiri_fdm = exports;
}, "solids");
forSlices(0.35, 0.5, function(slice) {
slice.doSolidsFill(fillSpacing, sliceFillAngle, minSolid);
slice.doThinFill(fillSpacing, sliceFillAngle);
sliceFillAngle += 90.0;
}, "solids");
}

View file

@ -347,6 +347,32 @@ var gs_kiri_slice = exports;
layer.render();
};
/**
* given two arrays of points (lines), eliminate intersections of the second
* to the first, then return a unified array.
*
* @param {Point[]} r1
* @param {Point[]} r2
* @returns {Point[]}
*/
function cullIntersections(r1, r2) {
if (!(r1 && r2 && r1.length && r2.length)) return;
if (r2.length > r1.length) {
var r3 = r1;
r1 = r2;
r2 = r3;
}
var valid = r1.slice();
outer: for (var i=0; i<r2.length; i += 2) {
for (var j=0; j<r1.length; j += 2) {
if (UTIL.intersect(r1[j], r1[j+1], r2[i], r2[i+1])) continue outer;
}
valid.push(r2[i]);
valid.push(r2[i+1]);
}
return valid;
}
/**
* Compute offset shell polygons. For FDM, the first offset is usually half
* of the nozzle width. Each subsequent offset is a full nozzle width. User
@ -368,7 +394,8 @@ var gs_kiri_slice = exports;
if (opt.vase) top.poly = top.poly.clone(false);
top.traces = [];
top.inner = [];
var last = [];
var last = [],
z = top.poly.getZ();
if (opt.thin) {
top.thin_fill = [];
@ -402,18 +429,19 @@ var gs_kiri_slice = exports;
},
// thin wall probe
function(p1, p2) {
// var pall = [].appendAll(p1).appendAll(p2),
// r1 = fillArea(pall, 45, offsetN, [], offsetN, offsetN * 2),
// r2 = fillArea(pall, 135, offsetN, [], offsetN, offsetN * 2),
// rall = top.thin_fill.appendAll(r1).appendAll(r2);
// console.log([slice.index, p1, p2, r1, r2]);
var pall = POLY.nest([].appendAll(p1).appendAll(p2), true),
pnew = POLY.expand(pall, -offset1, z, null, 1),
r1 = fillArea(pnew, 45, offsetN, [], 0, offsetN * 2),
r2 = fillArea(pnew, 135, offsetN, [], 0, offsetN * 2),
rall = top.thin_fill.appendAll(cullIntersections(r1, r2));
// if (rall.length) console.log([slice.index, pnew.length, rall.length]);
},
top.poly.getZ());
z);
} else {
POLY.expand(
[top.poly],
-offset1,
top.poly.getZ(),
z,
top.traces,
count,
-offsetN,
@ -610,9 +638,9 @@ var gs_kiri_slice = exports;
poly = POLY.fromClipperNode(node, scope.z);
tops.forEach(function(top) {
// filter out polygons under min length (0.5mm)
if (poly.isInside(top.poly) && poly.perimeter() > 0.5) {
// if (poly.isInside(top.poly) && poly.perimeter() > 0.5) {
top.fill_sparse.push(poly);
}
// }
});
});
}
@ -802,6 +830,24 @@ var gs_kiri_slice = exports;
return true;
};
/**
* fill thin areas, if present
* @return {boolean} true if filled, false if not
*/
PRO.doThinFill = function(spacing, angle) {
this.tops.forEach(function(top) {
if (top.thin_fill.length > 0) {
if (top.fill_lines) {
top.fill_lines.appendAll(top.thin_fill)
} else {
top.fill_lines = top.thin_fill;
}
}
});
return true;
};
PRO.renderSolidOutlines = function() {
var layer = this.layers.solid,
trimmed = this.solids.trimmed;

View file

@ -2593,7 +2593,10 @@ self.kiri.license = exports.LICENSE;
showSerial(true);
break;
case cca('U'): // full settings url
storeSettingsToServer();
storeSettingsToServer(true);
break;
case cca('u'): // full settings url
loadSettingsFromServer(prompt("settings id to load"));
break;
case cca('s'): // complete slice
prepareSlices();
@ -2704,8 +2707,8 @@ self.kiri.license = exports.LICENSE;
moveSelection(x, y, z, true);
}
function loadSettingsFromServer() {
var hash = LOC.hash.substring(1).split("/");
function loadSettingsFromServer(tok) {
var hash = tok || LOC.hash.substring(1).split("/");
if (hash.length === 2) {
new moto.Ajax(function(reply) {
if (reply) {
@ -2722,13 +2725,14 @@ self.kiri.license = exports.LICENSE;
}
}
function storeSettingsToServer() {
function storeSettingsToServer(display) {
var set = btoa(JSON.stringify(settings));
new moto.Ajax(function(reply) {
if (reply) {
var res = JSON.parse(reply);
if (res && res.ver) {
LOC.hash = res.space + "/" + res.ver;
if (display) alert("unique settings id is: " + res.space + "/" + res.ver);
}
} else {
updateSpaceState();

View file

@ -1,7 +1,7 @@
var exports = {
COPYRIGHT:"Copyright (C) 2014-2017 Stewart Allen <stewart@neuron.com> - All Rights Reserved",
LICENSE:"Unauthorized copying, modification and re-distribution are strictly prohibited without prior written consent.",
VERSION:"1.0.81"
VERSION:"1.0.82"
};
if (!module) var module = {};
module.exports = exports;