implemented better hole detection system

This commit is contained in:
casperlamboo 2015-08-03 12:09:46 +02:00
parent 0c557172e0
commit 1ac87e6f0c
2 changed files with 48 additions and 38 deletions

View File

@ -159,11 +159,9 @@ export default class Paths extends Array {
for (var i = 0; i < this.length; i ++) { for (var i = 0; i < this.length; i ++) {
var shape = this[i]; var shape = this[i];
if (shape.closed) {
var area = Math.abs(ClipperLib.Clipper.Area(shape)); var area = Math.abs(ClipperLib.Clipper.Area(shape));
areas.push(area); areas.push(area);
} }
}
return areas; return areas;
} }
@ -213,11 +211,23 @@ export default class Paths extends Array {
return new Paths(ClipperLib.Clipper.CleanPolygons(this, cleanDelta), this.closed); return new Paths(ClipperLib.Clipper.CleanPolygons(this, cleanDelta), this.closed);
} }
isHole () {
if (this.length !== 1) {
console.log('wtf?');
}
return !ClipperLib.Clipper.Orientation(this[0]);
}
pointCollision (point) {
var collision = ClipperLib.Clipper.PointInPolygon(point, this[0]);
return ClipperLib.Clipper.PointInPolygon(point, this[0]);
}
boundSize () { boundSize () {
var bounds = this.bounds(); var bounds = this.bounds();
var width = bounds.right - bounds.left; var width = bounds.right - bounds.left;
var height = bounds.top - bounds.bottom; var height = bounds.bottom - bounds.top;
return width * height; return width * height;
} }

View File

@ -62,6 +62,8 @@ export default class {
var slices = this._shapesToSlices(shapes, settings); var slices = this._shapesToSlices(shapes, settings);
//return;
this._generateInnerLines(slices, settings); this._generateInnerLines(slices, settings);
this._generateInfills(slices, settings); this._generateInfills(slices, settings);
@ -109,13 +111,13 @@ export default class {
if (face.normal.y !== 1 && face.normal.y !== -1) { if (face.normal.y !== 1 && face.normal.y !== -1) {
var normal = new THREE.Vector2(face.normal.z, face.normal.x).normalize(); var normal = new THREE.Vector2(face.normal.z, face.normal.x).normalize();
//check for only adding unique lines // check for only adding unique lines
//returns index of said line // returns index of said line
var a = addLine(face.a, face.b); var a = addLine(face.a, face.b);
var b = addLine(face.b, face.c); var b = addLine(face.b, face.c);
var c = addLine(face.c, face.a); var c = addLine(face.c, face.a);
//set connecting lines (based on face) // set connecting lines (based on face)
lines[a].connects.push(b, c); lines[a].connects.push(b, c);
lines[b].connects.push(c, a); lines[b].connects.push(c, a);
lines[c].connects.push(a, b); lines[c].connects.push(a, b);
@ -213,7 +215,7 @@ export default class {
while (index !== -1) { while (index !== -1) {
var intersection = intersectionPoints[index]; var intersection = intersectionPoints[index];
//uppercase X and Y because clipper vector // uppercase X and Y because clipper vector
shape.push({X: intersection.x, Y: intersection.y}); shape.push({X: intersection.x, Y: intersection.y});
delete intersectionPoints[index]; delete intersectionPoints[index];
@ -297,9 +299,8 @@ export default class {
} }
} }
// don't think this check is nessecary
if (shape.length > 0) {
var part = new Paths([shape], closed).clean(0.01); var part = new Paths([shape], closed).clean(0.01);
if (part.length > 0) {
shapeParts.push(part); shapeParts.push(part);
} }
} }
@ -319,36 +320,37 @@ export default class {
for (var layer = 0; layer < shapes.length; layer ++) { for (var layer = 0; layer < shapes.length; layer ++) {
var shapeParts = shapes[layer]; var shapeParts = shapes[layer];
// sort object for better hole detections
// holes always have a smaller bound as its parent
shapeParts.sort((a, b) => {
return a.boundSize() - b.boundSize();
});
var slice = new Slice(); var slice = new Slice();
for (var i = 0; i < shapeParts.length; i ++) { var holes = [];
var shapePart1 = shapeParts[i]; var outlines = [];
if (!shapePart1.closed) { for (var i = 0; i < shapeParts.length; i ++) {
slice.add(shapePart1); var shape = shapeParts[i];
continue;
if (!shape.closed) {
slice.add(shape);
}
else if (shape.isHole()) {
holes.push(shape);
}
else {
slice.add(shape);
outlines.push(shape);
}
} }
var merge = false; for (var i = 0; i < holes.length; i ++) {
var hole = holes[i];
for (var j = 0; j < slice.parts.length; j ++) { for (var j = 0; j < outlines.length; j ++) {
var shapePart2 = slice.parts[j].intersect; var outline = outlines[j];
if (shapePart2.closed && shapePart2.intersect(shapePart1).length > 0) {
shapePart2.join(shapePart1); if (outline.pointCollision(hole[0][0])) {
merge = true; outline.join(hole);
break; break;
} }
} }
if (!merge) {
slice.add(shapePart1);
}
} }
slices.push(slice); slices.push(slice);
@ -451,8 +453,8 @@ export default class {
var inset = (part.innerLines.length > 0) ? part.innerLines[part.innerLines.length - 1] : outerLine; var inset = (part.innerLines.length > 0) ? part.innerLines[part.innerLines.length - 1] : outerLine;
var fillArea = inset.offset(-nozzleRadius); var fillArea = inset.offset(-nozzleRadius);
var lowFillArea = false;
if (surroundingLayer) { if (surroundingLayer) {
var highFillArea = fillArea.difference(surroundingLayer); var highFillArea = fillArea.difference(surroundingLayer);
if (infillOverlap > 0) { if (infillOverlap > 0) {
@ -464,13 +466,12 @@ export default class {
var lowFillArea = fillArea.difference(highFillArea); var lowFillArea = fillArea.difference(highFillArea);
} }
else { else {
var lowFillArea = new Paths([], true);
var highFillArea = fillArea; var highFillArea = fillArea;
} }
var fill = new Paths([], false); var fill = new Paths([], false);
if (lowFillArea.length > 0 && lowFillArea.length > 0) { if (lowFillArea && lowFillArea.length > 0) {
var bounds = lowFillArea.bounds(); var bounds = lowFillArea.bounds();
var lowFillTemplate = this._getFillTemplate(bounds, fillGridSize, true, true); var lowFillTemplate = this._getFillTemplate(bounds, fillGridSize, true, true);
@ -519,7 +520,7 @@ export default class {
sliceSkin = sliceSkin; sliceSkin = sliceSkin;
var supportAreasSlimmed = supportAreas.difference(sliceSkin.offset(supportMargin)); var supportAreasSlimmed = supportAreas.difference(sliceSkin.offset(supportMargin));
if (supportAreasSlimmed.length === 0) { if (supportAreasSlimmed.area() < 100.0) {
supportAreas = supportAreas.difference(sliceSkin); supportAreas = supportAreas.difference(sliceSkin);
} }
else { else {
@ -530,7 +531,7 @@ export default class {
var supportTemplate = this._getFillTemplate(supportAreas.bounds(), supportGridSize, true, true); var supportTemplate = this._getFillTemplate(supportAreas.bounds(), supportGridSize, true, true);
var supportFill = supportTemplate.intersect(supportAreas); var supportFill = supportTemplate.intersect(supportAreas);
if (supportFill.length === 0 || true) { if (supportFill.length === 0) {
currentSlice.support = supportAreas.clone(); currentSlice.support = supportAreas.clone();
} }
else { else {
@ -562,7 +563,6 @@ export default class {
this.progress.generatedSupport = true; this.progress.generatedSupport = true;
this._updateProgress(settings); this._updateProgress(settings);
} }
_optimizePaths (slices, settings) { _optimizePaths (slices, settings) {