From 3421e8fef81854b1385cc982d6e3593707961c2c Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 5 Sep 2011 20:29:07 +0200 Subject: [PATCH] Improvements to avoid blobs --- lib/Slic3r/Perimeter.pm | 26 ++++++++++++++++++++++++-- lib/Slic3r/Print.pm | 12 +++++++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/Slic3r/Perimeter.pm b/lib/Slic3r/Perimeter.pm index 88d273a97..1b85d7812 100644 --- a/lib/Slic3r/Perimeter.pm +++ b/lib/Slic3r/Perimeter.pm @@ -4,6 +4,9 @@ use Moose; use Math::Geometry::Planar; *Math::Geometry::Planar::OffsetPolygon = *Math::Geometry::Planar::Offset::OffsetPolygon; +use constant X => 0; +use constant Y => 1; + sub make_perimeter { my $self = shift; my ($layer) = @_; @@ -66,10 +69,13 @@ sub make_perimeter { my @path_points = (); foreach my $p (map $self->_mgp_from_points_ref($_), @$polylines) { my $points = $p->points; - # TODO: the initial $points->[0] should be replaced by the point of + # to avoid blobs, the first point is replaced by the point of # the segment which is $Slic3r::flow_width / $Slic3r::resolution # away from it to avoid the extruder to get two times there - push @path_points, @$points, $points->[0]; + push @$points, [ @{$points->[0]} ]; + $points->[0] = $self->_get_point_along_line($points->[0], $points->[1], + $Slic3r::flow_width * 1.2 / $Slic3r::resolution); + push @path_points, @$points; } push @{ $layer->perimeters }, Slic3r::ExtrusionPath->new_from_points(reverse @path_points); } @@ -140,4 +146,20 @@ sub _mgp_from_polygons_ref { return $p; } +sub _get_point_along_line { + my $self = shift; + my ($p1, $p2, $distance) = @_; + + my $point = [ @$p1 ]; + + my $line_length = sqrt( (($p2->[X] - $p1->[X])**2) + (($p2->[Y] - $p1->[Y])**2) ); + for (X, Y) { + if ($p1->[$_] != $p2->[$_]) { + $point->[$_] = $p1->[$_] + ($p2->[$_] - $p1->[$_]) * $distance / $line_length; + } + } + + return $point; +} + 1; diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 0a23aa32a..a53c4356c 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -150,11 +150,13 @@ sub export_gcode { } # go to first point while compensating retraction - $G1->($path->lines->[0]->a, $z, - $retracted - ? ($Slic3r::retract_length + $Slic3r::retract_restart_extra) - : 0, - "move to first $description point"); + $G1->($path->lines->[0]->a, $z, 0, "move to first $description point"); + + # compensate retraction + if ($retracted) { + $G1->(undef, undef, ($Slic3r::retract_length + $Slic3r::retract_restart_extra), + "compensate retraction"); + } # extrude while going to next points foreach my $line (@{ $path->lines }) {