Improved hole detection algorithm

This commit is contained in:
casperlamboo 2015-07-28 12:28:05 +02:00 committed by Simon Voordouw
parent f1e6328f6f
commit 5f4c366132
3 changed files with 49 additions and 44 deletions

View File

@ -13,7 +13,7 @@ setTimeout(() => {
var slicer = new SLICER.Slicer();
//var slicer = new SLICER.SlicerWorker();
slicer.setGeometry(geometry);
slicer.setGeometry(geometry.clone());
slicer.onfinish = function (gCode) {
document.getElementById('gcode').innerHTML = gCode.replace(/(?:\r\n|\r|\n)/g, '<br />');
};

View File

@ -1,6 +1,6 @@
<!DOCTYPE>
<html>
<head>
<head>
<title>Doodle3D Slicer</title>
@ -17,11 +17,11 @@
System.import('example/app.js');
</script>
</head>
</head>
<body>
<body>
<p id="gcode"></p>
<p id="gcode"></p>
</body>
</body>
</html>

View File

@ -41,9 +41,8 @@ export default class {
geometry.applyMatrix(matrix);
}
geometry.computeBoundingBox();
geometry.computeFaceNormals();
geometry.mergeVertices();
geometry.computeFaceNormals();
this.geometry = geometry;
@ -290,20 +289,17 @@ export default class {
}
}
sliceParts.sort(function (a, b) {
return b.area() - a.area();
sliceParts.sort((a, b) => {
return b.boundSize() - a.boundSize();
});
var slice = new Slice();
for (var i = 0; i < sliceParts.length; i ++) {
var slicePart1 = sliceParts[i];
for (var slicePart1 of sliceParts) {
if (slicePart1.closed) {
var merge = false;
for (var j = 0; j < slice.parts.length; j ++) {
var slicePart2 = slice.parts[j].intersect;
for (var slicePart2 of slice.parts) {
if (slicePart2.closed && slicePart2.intersect(slicePart1).length > 0) {
slicePart2.join(slicePart1);
merge = true;
@ -469,35 +465,37 @@ export default class {
var supportMargin = settings.config["supportMargin"] * scale;
var plateSize = settings.config["supportPlateSize"] * scale;
var supportDistanceY = settings.config["supportDistanceY"];
var supportDistanceLayers = Math.ceil(supportDistanceY / layerHeight);
var supportDistanceLayers = Math.max(Math.ceil(supportDistanceY / layerHeight), 1);
var nozzleDiameter = settings.config["nozzleDiameter"] * scale;
var supportAreas = new Paths([], true);
for (var layer = slices.length - 1 - supportDistanceLayers; layer >= 0; layer --) {
var currentSlice = slices[layer];
if (supportAreas.length > 0) {
if (layer >= supportDistanceLayers) {
//var sliceSkin = slices[layer - supportDistanceLayers].getOutline();
var sliceSkin = slices[layer].getOutline();
sliceSkin = sliceSkin.offset(supportMargin);
var sliceSkin = slices[layer - supportDistanceLayers].getOutline();
sliceSkin = sliceSkin;
var supportAreasSlimmed = supportAreas.difference(sliceSkin.offset(supportMargin));
if (supportAreasSlimmed.length === 0) {
supportAreas = supportAreas.difference(sliceSkin);
}
else {
supportAreas = supportAreasSlimmed;
}
}
var currentSlice = slices[layer];
if (layer === 0) {
supportAreas = supportAreas.offset(plateSize).difference(sliceSkin);
var template = this._getFillTemplate(supportAreas.bounds(), nozzleDiameter, true, false);
currentSlice.support = template.intersect(supportAreas);
var supportTemplate = this._getFillTemplate(supportAreas.bounds(), supportGridSize, true, true);
var supportFill = supportTemplate.intersect(supportAreas);
if (supportFill.length === 0 || true) {
currentSlice.support = supportAreas.clone();
}
else {
var supportTemplate = this._getFillTemplate(supportAreas.bounds(), supportGridSize, true, true);
currentSlice.support = supportTemplate.intersect(supportAreas).join(supportAreas.clone());
currentSlice.support = supportFill;
}
}
@ -506,19 +504,26 @@ export default class {
var slice = slices[layer + supportDistanceLayers];
for (var i = 0; i < slice.parts.length; i ++) {
var slicePart = slice.parts[i];
if (slicePart.intersect.closed) {
var outerLine = slicePart.outerLine;
}
else {
var outerLine = slicePart.intersect.offset(supportAcceptanceMargin);
}
var overlap = supportSkin.offset(supportAcceptanceMargin).intersect(outerLine);
var overhang = outerLine.difference(overlap);
if (overlap.length === 0 || overhang.length > 0) {
supportAreas = supportAreas.union(overhang.offset(supportAcceptanceMargin).intersect(outerLine));
supportAreas = supportAreas.join(overhang);
}
}
}
this.progress.generatedSupport = true;
this._updateProgress(settings);
}
_optimizePaths (slices, settings) {