2011-11-26 10:38:05 +01:00
|
|
|
package Slic3r::Fill::Concentric;
|
|
|
|
use Moo;
|
|
|
|
|
|
|
|
extends 'Slic3r::Fill::Base';
|
|
|
|
|
2013-08-27 00:52:20 +02:00
|
|
|
use Slic3r::Geometry qw(scale unscale X);
|
2013-08-27 01:26:44 +02:00
|
|
|
use Slic3r::Geometry::Clipper qw(offset offset2 union_pt traverse_pt);
|
2011-11-26 10:38:05 +01:00
|
|
|
|
|
|
|
sub fill_surface {
|
|
|
|
my $self = shift;
|
|
|
|
my ($surface, %params) = @_;
|
|
|
|
|
|
|
|
# no rotation is supported for this infill pattern
|
|
|
|
|
2011-12-17 20:29:06 +01:00
|
|
|
my $expolygon = $surface->expolygon;
|
2013-06-16 12:21:25 +02:00
|
|
|
my $bounding_box = $expolygon->bounding_box;
|
2011-12-17 19:56:56 +01:00
|
|
|
|
2011-12-17 20:29:06 +01:00
|
|
|
my $min_spacing = scale $params{flow_spacing};
|
|
|
|
my $distance = $min_spacing / $params{density};
|
|
|
|
|
2012-09-12 12:13:43 +02:00
|
|
|
my $flow_spacing = $params{flow_spacing};
|
2012-11-16 18:24:09 +01:00
|
|
|
if ($params{density} == 1 && !$params{dont_adjust}) {
|
2011-12-19 09:55:03 +01:00
|
|
|
$distance = $self->adjust_solid_spacing(
|
2013-06-16 12:21:25 +02:00
|
|
|
width => $bounding_box->size->[X],
|
2011-12-19 09:55:03 +01:00
|
|
|
distance => $distance,
|
|
|
|
);
|
|
|
|
$flow_spacing = unscale $distance;
|
|
|
|
}
|
2011-11-26 10:38:05 +01:00
|
|
|
|
2013-06-23 00:37:04 +02: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-07-17 00:48:29 +02:00
|
|
|
my @loops = my @last = @{offset($expolygon, -&Slic3r::INFILL_OVERLAP_OVER_SPACING * $min_spacing / 2)};
|
2013-05-13 21:22:57 +02:00
|
|
|
while (@last) {
|
2013-07-17 00:48:29 +02:00
|
|
|
push @loops, @last = @{offset2(\@last, -1.5*$distance, +0.5*$distance)};
|
2011-11-26 10:38:05 +01:00
|
|
|
}
|
|
|
|
|
2013-05-13 21:22:57 +02:00
|
|
|
# generate paths from the outermost to the innermost, to avoid
|
|
|
|
# adhesion problems of the first central tiny loops
|
2013-06-23 00:50:44 +02:00
|
|
|
@loops = map Slic3r::Polygon->new(@$_),
|
2013-08-26 18:37:19 +02:00
|
|
|
reverse traverse_pt( union_pt(\@loops) );
|
2011-11-26 10:38:05 +01:00
|
|
|
|
2013-06-23 00:50:44 +02:00
|
|
|
# order paths using a nearest neighbor search
|
|
|
|
my @paths = ();
|
|
|
|
my $last_pos = [0,0];
|
|
|
|
foreach my $loop (@loops) {
|
2013-08-27 00:52:20 +02:00
|
|
|
push @paths, $loop->split_at_index($last_pos->nearest_point_index($loop));
|
2013-06-23 00:50:44 +02:00
|
|
|
$last_pos = $paths[-1][-1];
|
|
|
|
}
|
|
|
|
|
2013-05-13 21:22:57 +02:00
|
|
|
# clip the paths to avoid the extruder to get exactly on the first point of the loop
|
|
|
|
my $clip_length = scale $flow_spacing * &Slic3r::LOOP_CLIPPING_LENGTH_OVER_SPACING;
|
|
|
|
$_->clip_end($clip_length) for @paths;
|
2011-11-26 10:38:05 +01:00
|
|
|
|
2013-05-13 21:22:57 +02:00
|
|
|
# TODO: return ExtrusionLoop objects to get better chained paths
|
|
|
|
return { flow_spacing => $flow_spacing, no_sort => 1 }, @paths;
|
2011-11-26 10:38:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|