Improved hole detection algorithm

This commit is contained in:
casperlamboo 2015-07-28 12:28:05 +02:00
parent 13c1333ce8
commit 3b455377ba
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.Slicer();
//var slicer = new SLICER.SlicerWorker(); //var slicer = new SLICER.SlicerWorker();
slicer.setGeometry(geometry); slicer.setGeometry(geometry.clone());
slicer.onfinish = function (gCode) { slicer.onfinish = function (gCode) {
document.getElementById('gcode').innerHTML = gCode.replace(/(?:\r\n|\r|\n)/g, '<br />'); document.getElementById('gcode').innerHTML = gCode.replace(/(?:\r\n|\r|\n)/g, '<br />');
}; };

View File

@ -1,27 +1,27 @@
<!DOCTYPE> <!DOCTYPE>
<html> <html>
<head> <head>
<title>Doodle3D Slicer</title> <title>Doodle3D Slicer</title>
<style> <style>
#gcode { #gcode {
font-family: monospace; font-family: monospace;
} }
</style> </style>
<script type="text/javascript" src="../jspm_packages/system.js"></script> <script type="text/javascript" src="../jspm_packages/system.js"></script>
<script type="text/javascript" src="../config.js"></script> <script type="text/javascript" src="../config.js"></script>
<script type="text/javascript"> <script type="text/javascript">
System.import('example/app.js'); System.import('example/app.js');
</script> </script>
</head> </head>
<body> <body>
<p id="gcode"></p> <p id="gcode"></p>
</body> </body>
</html> </html>

View File

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