From 5c9916dc75a0a59f5751de5672f49c8c95584e49 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 6 Jun 2012 22:28:23 +0200 Subject: [PATCH] Some basic ability to close holes in non-manifold models --- lib/Slic3r/TriangleMesh.pm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/TriangleMesh.pm b/lib/Slic3r/TriangleMesh.pm index f9b06c1b..4fa77ccd 100644 --- a/lib/Slic3r/TriangleMesh.pm +++ b/lib/Slic3r/TriangleMesh.pm @@ -237,7 +237,7 @@ sub make_loops { grep defined $lines[$_][I_A_ID], (0..$#lines); - my (@polygons, %visited_lines) = (); + my (@polygons, @failed_loops, %visited_lines) = (); CYCLE: for (my $i = 0; $i <= $#lines; $i++) { my $line = $lines[$i]; next if $visited_lines{$line}; @@ -253,20 +253,24 @@ sub make_loops { } else { Slic3r::debugf " line has no next_facet_index or b_id\n"; $layer->slicing_errors(1); + push @failed_loops, [@points] if @points; next CYCLE; } if (!$next_line || $visited_lines{$next_line}) { Slic3r::debugf " failed to close this loop\n"; $layer->slicing_errors(1); + push @failed_loops, [@points] if @points; next CYCLE; } elsif (defined $next_line->[I_PREV_FACET_INDEX] && $next_line->[I_PREV_FACET_INDEX] != $line->[I_FACET_INDEX]) { Slic3r::debugf " wrong prev_facet_index\n"; $layer->slicing_errors(1); + push @failed_loops, [@points] if @points; next CYCLE; } elsif (defined $next_line->[I_A_ID] && $next_line->[I_A_ID] != $line->[I_B_ID]) { Slic3r::debugf " wrong a_id\n"; $layer->slicing_errors(1); + push @failed_loops, [@points] if @points; next CYCLE; } @@ -281,6 +285,14 @@ sub make_loops { if $Slic3r::debug; } + # TODO: we should try to combine failed loops + for (grep @$_ >= 3, @failed_loops) { + push @polygons, Slic3r::Polygon->new(@$_); + Slic3r::debugf " Discovered failed %s polygon of %d points\n", + ($polygons[-1]->is_counter_clockwise ? 'ccw' : 'cw'), scalar(@$_) + if $Slic3r::debug; + } + return [@polygons]; }