Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Ranellucci <aar@cpan.org>2011-11-30 19:28:09 +0400
committerAlessandro Ranellucci <aar@cpan.org>2011-11-30 19:28:09 +0400
commit42383dec847fcdfd04ce2a0122b580cd5c8615b9 (patch)
treeafa0db02c085b3783a950039d593c97dc4457eda /lib/Slic3r/Print.pm
parentd51a37a0ae1d27f2336e97284fb5852f0f204e4a (diff)
Warn about models with overlapping or intersecting facets but try to repair wrong layers. #16
Diffstat (limited to 'lib/Slic3r/Print.pm')
-rw-r--r--lib/Slic3r/Print.pm42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm
index cfba9561d..d2a54c544 100644
--- a/lib/Slic3r/Print.pm
+++ b/lib/Slic3r/Print.pm
@@ -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;
}