diff --git a/lib/Slic3r/Geometry.pm b/lib/Slic3r/Geometry.pm index 2b60b280a..bdb9efa03 100644 --- a/lib/Slic3r/Geometry.pm +++ b/lib/Slic3r/Geometry.pm @@ -38,7 +38,7 @@ use constant MIN => 0; use constant MAX => 1; our $parallel_degrees_limit = abs(deg2rad(3)); -our $epsilon = 1E-6; +our $epsilon = 1E-4; sub epsilon () { $epsilon } sub scale ($) { $_[0] / $Slic3r::resolution } @@ -212,7 +212,7 @@ sub polyline_lines { my @lines = (); my $last_point; foreach my $point (@$polygon) { - push @lines, [ $last_point, $point ] if $last_point; + push @lines, Slic3r::Line->new($last_point, $point) if $last_point; $last_point = $point; } diff --git a/lib/Slic3r/TriangleMesh.pm b/lib/Slic3r/TriangleMesh.pm index aef77ef54..6e5a537bf 100644 --- a/lib/Slic3r/TriangleMesh.pm +++ b/lib/Slic3r/TriangleMesh.pm @@ -2,7 +2,7 @@ package Slic3r::TriangleMesh; use Moo; use Slic3r::Geometry qw(X Y Z A B PI epsilon same_point points_coincide angle3points - merge_collinear_lines nearest_point); + merge_collinear_lines nearest_point polyline_lines); use XXX; has 'facets' => (is => 'ro', default => sub { [] }); @@ -194,28 +194,40 @@ sub make_loops { Slic3r::debugf " %d lines out of %d were discarded and %d polylines were not closed\n", scalar(@discarded_lines), scalar(@lines), scalar(@discarded_polylines); print " Warning: errors while parsing this layer (dirty or non-manifold model).\n"; - print " Retrying with slower algorithm.\n"; - if (0) { - require "Slic3r/SVG.pm"; - Slic3r::SVG::output(undef, "layer" . $self->id . "_detected.svg", - white_polygons => \@polygons, - ); - Slic3r::SVG::output(undef, "layer" . $self->id . "_discarded_lines.svg", - red_lines => \@discarded_lines, - ); - Slic3r::SVG::output(undef, "layer" . $self->id . "_discarded_polylines.svg", - polylines => \@discarded_polylines, - ); - } + my $total_detected_length = 0; + $total_detected_length += $_->length for map $_->lines, @polygons; + my $total_discarded_length = 0; + $total_discarded_length += $_->length for map polyline_lines($_), @discarded_polylines; + $total_discarded_length += $_->length for @discarded_lines; + my $discarded_ratio = $total_discarded_length / $total_detected_length; - $sparse_lines = merge_collinear_lines($sparse_lines); - eval { $detect->(); }; - warn $@ if $@; + Slic3r::debugf " length ratio of discarded lines is %f\n", $discarded_ratio; - if (@discarded_lines) { - print " Warning: even slow detection algorithm threw errors. Review the output before printing.\n"; - $layer->slicing_errors(1); + if ($discarded_ratio > 0.00001) { + print " Retrying with slower algorithm.\n"; + + if (0) { + require "Slic3r/SVG.pm"; + Slic3r::SVG::output(undef, "layer" . $layer->id . "_detected.svg", + white_polygons => \@polygons, + ); + Slic3r::SVG::output(undef, "layer" . $layer->id . "_discarded_lines.svg", + red_lines => \@discarded_lines, + ); + Slic3r::SVG::output(undef, "layer" . $layer->id . "_discarded_polylines.svg", + polylines => \@discarded_polylines, + ); + } + + $sparse_lines = merge_collinear_lines($sparse_lines); + eval { $detect->(); }; + warn $@ if $@; + + if (@discarded_lines) { + print " Warning: even slow detection algorithm threw errors. Review the output before printing.\n"; + $layer->slicing_errors(1); + } } }