2011-11-26 09:38:05 +00:00
|
|
|
package Slic3r::Fill::Concentric;
|
|
|
|
use Moo;
|
|
|
|
|
|
|
|
extends 'Slic3r::Fill::Base';
|
|
|
|
|
2013-08-26 22:52:20 +00:00
|
|
|
use Slic3r::Geometry qw(scale unscale X);
|
2013-11-23 22:21:59 +00:00
|
|
|
use Slic3r::Geometry::Clipper qw(offset offset2 union_pt_chained);
|
2011-11-26 09:38:05 +00:00
|
|
|
|
|
|
|
sub fill_surface {
|
|
|
|
my $self = shift;
|
|
|
|
my ($surface, %params) = @_;
|
|
|
|
|
|
|
|
# no rotation is supported for this infill pattern
|
|
|
|
|
2011-12-17 19:29:06 +00:00
|
|
|
my $expolygon = $surface->expolygon;
|
2013-06-16 10:21:25 +00:00
|
|
|
my $bounding_box = $expolygon->bounding_box;
|
2011-12-17 18:56:56 +00:00
|
|
|
|
2014-01-03 19:02:00 +00:00
|
|
|
my $flow = $params{flow};
|
|
|
|
my $min_spacing = $flow->scaled_spacing;
|
2011-12-17 19:29:06 +00:00
|
|
|
my $distance = $min_spacing / $params{density};
|
|
|
|
|
2014-01-03 19:02:00 +00:00
|
|
|
my $flow_spacing = $flow->spacing;
|
2012-11-16 17:24:09 +00:00
|
|
|
if ($params{density} == 1 && !$params{dont_adjust}) {
|
2011-12-19 08:55:03 +00:00
|
|
|
$distance = $self->adjust_solid_spacing(
|
2013-06-16 10:21:25 +00:00
|
|
|
width => $bounding_box->size->[X],
|
2011-12-19 08:55:03 +00:00
|
|
|
distance => $distance,
|
|
|
|
);
|
2014-01-03 19:02:00 +00:00
|
|
|
$flow = Slic3r::Flow->new_from_spacing(
|
|
|
|
spacing => unscale($distance),
|
|
|
|
nozzle_diameter => $flow->nozzle_diameter,
|
2014-04-19 14:53:37 +00:00
|
|
|
layer_height => ($params{layer_height} or die "No layer_height supplied to fill_surface()"),
|
2014-01-03 19:02:00 +00:00
|
|
|
bridge => $flow->bridge,
|
|
|
|
);
|
2011-12-19 08:55:03 +00:00
|
|
|
}
|
2011-11-26 09:38:05 +00:00
|
|
|
|
2013-06-22 22:37:04 +00:00
|
|
|
# compensate the overlap which is good for rectilinear but harmful for concentric
|
|
|
|
# where the perimeter/infill spacing should be equal to any other loop spacing
|
2013-09-12 09:13:11 +00:00
|
|
|
my @loops = my @last = @{offset(\@$expolygon, -&Slic3r::INFILL_OVERLAP_OVER_SPACING * $min_spacing / 2)};
|
2013-05-13 19:22:57 +00:00
|
|
|
while (@last) {
|
2013-07-16 22:48:29 +00:00
|
|
|
push @loops, @last = @{offset2(\@last, -1.5*$distance, +0.5*$distance)};
|
2011-11-26 09:38:05 +00:00
|
|
|
}
|
|
|
|
|
2013-05-13 19:22:57 +00:00
|
|
|
# generate paths from the outermost to the innermost, to avoid
|
|
|
|
# adhesion problems of the first central tiny loops
|
2013-06-22 22:50:44 +00:00
|
|
|
@loops = map Slic3r::Polygon->new(@$_),
|
2013-11-23 22:21:59 +00:00
|
|
|
reverse @{union_pt_chained(\@loops)};
|
2011-11-26 09:38:05 +00:00
|
|
|
|
2013-06-22 22:50:44 +00:00
|
|
|
# order paths using a nearest neighbor search
|
|
|
|
my @paths = ();
|
2013-09-12 09:13:11 +00:00
|
|
|
my $last_pos = Slic3r::Point->new(0,0);
|
2013-06-22 22:50:44 +00:00
|
|
|
foreach my $loop (@loops) {
|
2013-09-12 09:13:11 +00:00
|
|
|
push @paths, $loop->split_at_index($last_pos->nearest_point_index(\@$loop));
|
2013-09-27 09:48:44 +00:00
|
|
|
$last_pos = $paths[-1]->last_point;
|
2013-06-22 22:50:44 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 15:05:40 +00:00
|
|
|
# clip the paths to prevent the extruder from getting exactly on the first point of the loop
|
2014-01-03 19:02:00 +00:00
|
|
|
my $clip_length = scale($flow->nozzle_diameter) * &Slic3r::LOOP_CLIPPING_LENGTH_OVER_NOZZLE_DIAMETER;
|
2013-05-13 19:22:57 +00:00
|
|
|
$_->clip_end($clip_length) for @paths;
|
2014-02-10 15:05:40 +00:00
|
|
|
@paths = grep $_->is_valid, @paths; # remove empty paths (too short, thus eaten by clipping)
|
2011-11-26 09:38:05 +00:00
|
|
|
|
2013-05-13 19:22:57 +00:00
|
|
|
# TODO: return ExtrusionLoop objects to get better chained paths
|
2014-01-03 19:02:00 +00:00
|
|
|
return { flow => $flow, no_sort => 1 }, @paths;
|
2011-11-26 09:38:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|