Skip to content

Commit

Permalink
Warn about models with overlapping or intersecting facets but try to …
Browse files Browse the repository at this point in the history
…repair wrong layers. #16
  • Loading branch information
alranel committed Nov 30, 2011
1 parent d51a37a commit 42383de
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Slic3r/Layer.pm
Expand Up @@ -13,6 +13,8 @@ has 'id' => (
required => 1,
);

has 'slicing_errors' => (is => 'rw');

# collection of spare segments generated by slicing the original geometry;
# these need to be merged in continuos (closed) polylines
has 'lines' => (
Expand Down
42 changes: 42 additions & 0 deletions lib/Slic3r/Print.pm
Expand Up @@ -98,6 +98,48 @@ sub new_from_mesh {
$layer->make_surfaces($mesh->make_loops($layer));
}

# detect slicing errors
my $warning_thrown = 0;
for (my $i = 0; $i <= $#{$print->layers}; $i++) {
my $layer = $print->layers->[$i];
next unless $layer->slicing_errors;
if (!$warning_thrown) {
warn "The model has overlapping or self-intersecting facets. I tried to repair it, "
. "however you might want to check the results or repair the input file and retry.\n";
$warning_thrown = 1;
}

# try to repair the layer surfaces by merging all contours and all holes from
# neighbor layers
Slic3r::debugf "Attempting to repair layer %d\n", $i;

my (@upper_surfaces, @lower_surfaces);
for (my $j = $i+1; $j <= $#{$print->layers}; $j++) {
if (!$print->layers->[$j]->slicing_errors) {
@upper_surfaces = @{$print->layers->[$j]->surfaces};
last;
}
}
for (my $j = $i-1; $j >= 0; $j--) {
if (!$print->layers->[$j]->slicing_errors) {
@lower_surfaces = @{$print->layers->[$j]->surfaces};
last;
}
}

my $union = union_ex([
map $_->expolygon->contour, @upper_surfaces, @lower_surfaces,
]);
my $diff = diff_ex(
[ map @$_, @$union ],
[ map $_->expolygon->holes, @upper_surfaces, @lower_surfaces, ],
);

@{$layer->surfaces} = map Slic3r::Surface->cast_from_expolygon
($_, surface_type => 'internal'),
@$diff;
}

return $print;
}

Expand Down
1 change: 1 addition & 0 deletions lib/Slic3r/TriangleMesh.pm
Expand Up @@ -215,6 +215,7 @@ sub make_loops {

if (@discarded_lines) {
print " Warning: even slow detection algorithm threw errors. Review the output before printing.\n";
$layer->slicing_errors(1);
}
}

Expand Down

0 comments on commit 42383de

Please sign in to comment.