Faster implementation of concentric infill, with loop order reversed so that smaller loops will be printed at the end. #898
This commit is contained in:
parent
ccdb29ddc9
commit
a73020c10e
@ -2,6 +2,7 @@ package Slic3r::ExtrusionPath::Collection;
|
||||
use Moo;
|
||||
|
||||
has 'paths' => (is => 'rw', default => sub { [] });
|
||||
has 'no_sort' => (is => 'rw');
|
||||
|
||||
# no-op
|
||||
sub unpack { $_[0] }
|
||||
@ -15,6 +16,8 @@ sub chained_path {
|
||||
my $self = shift;
|
||||
my ($start_near) = @_;
|
||||
|
||||
return @{$self->paths} if $self->no_sort;
|
||||
|
||||
# make sure we pass the same path objects to the Collection constructor
|
||||
# and the ->chained_path() method because the latter will reverse the
|
||||
# paths in-place when needed and we need to return them that way
|
||||
|
@ -176,6 +176,7 @@ sub make_fill {
|
||||
# save into layer
|
||||
next unless @paths;
|
||||
push @fills, Slic3r::ExtrusionPath::Collection->new(
|
||||
no_sort => $params->{no_sort},
|
||||
paths => [
|
||||
map Slic3r::ExtrusionPath->pack(
|
||||
polyline => Slic3r::Polyline->new(@$_),
|
||||
|
@ -3,8 +3,8 @@ use Moo;
|
||||
|
||||
extends 'Slic3r::Fill::Base';
|
||||
|
||||
use Slic3r::ExtrusionPath ':roles';
|
||||
use Slic3r::Geometry qw(scale unscale X1 Y1 X2 Y2);
|
||||
use Slic3r::Geometry qw(scale unscale X1 X2);
|
||||
use Slic3r::Geometry::Clipper qw(offset2 union_pt traverse_pt PFT_EVENODD);
|
||||
|
||||
sub fill_surface {
|
||||
my $self = shift;
|
||||
@ -27,48 +27,22 @@ sub fill_surface {
|
||||
$flow_spacing = unscale $distance;
|
||||
}
|
||||
|
||||
my @contour_loops = ();
|
||||
my @hole_loops = ();
|
||||
my @last_offsets = ($expolygon->offset_ex($distance));
|
||||
while (@last_offsets) {
|
||||
my @new_offsets = ();
|
||||
foreach my $last_expolygon (@last_offsets) {
|
||||
my @offsets = $last_expolygon->offset_ex(-$distance);
|
||||
foreach my $offset (@offsets) {
|
||||
push @new_offsets, $offset;
|
||||
push @contour_loops, $offset->contour;
|
||||
push @hole_loops, $offset->holes;
|
||||
}
|
||||
}
|
||||
@last_offsets = @new_offsets;
|
||||
my @loops = my @last = @$expolygon;
|
||||
while (@last) {
|
||||
push @loops, @last = offset2(\@last, -1.5*$distance, +0.5*$distance);
|
||||
}
|
||||
|
||||
my @loops = (@contour_loops, reverse @hole_loops);
|
||||
# generate paths from the outermost to the innermost, to avoid
|
||||
# adhesion problems of the first central tiny loops
|
||||
my @paths = map Slic3r::Polygon->new(@$_)->split_at_first_point,
|
||||
reverse traverse_pt( union_pt(\@loops, PFT_EVENODD) );
|
||||
|
||||
# make paths
|
||||
my @paths = ();
|
||||
my $cur_pos = Slic3r::Point->new(
|
||||
($bounding_box->[X1] + $bounding_box->[X2]) / 2,
|
||||
($bounding_box->[Y1] + $bounding_box->[Y2]) / 2,
|
||||
);
|
||||
foreach my $loop (@loops) {
|
||||
# extrude all loops ccw
|
||||
$loop->make_counter_clockwise;
|
||||
# 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;
|
||||
|
||||
# find the point of the loop that is closest to the current extruder position
|
||||
my $index = $loop->nearest_point_index_to($cur_pos);
|
||||
$cur_pos = $loop->[0];
|
||||
|
||||
# split the loop at the starting point and make a path
|
||||
my $path = $loop->split_at_index($index);
|
||||
|
||||
# clip the path to avoid the extruder to get exactly on the first point of the loop
|
||||
$path->clip_end(scale $flow_spacing * &Slic3r::LOOP_CLIPPING_LENGTH_OVER_SPACING);
|
||||
|
||||
push @paths, $path if @$path;
|
||||
}
|
||||
|
||||
return { flow_spacing => $flow_spacing }, @paths;
|
||||
# TODO: return ExtrusionLoop objects to get better chained paths
|
||||
return { flow_spacing => $flow_spacing, no_sort => 1 }, @paths;
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user