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
3 changed files with 18 additions and 40 deletions
lib/Slic3r
|
@ -2,6 +2,7 @@ package Slic3r::ExtrusionPath::Collection;
|
||||||
use Moo;
|
use Moo;
|
||||||
|
|
||||||
has 'paths' => (is => 'rw', default => sub { [] });
|
has 'paths' => (is => 'rw', default => sub { [] });
|
||||||
|
has 'no_sort' => (is => 'rw');
|
||||||
|
|
||||||
# no-op
|
# no-op
|
||||||
sub unpack { $_[0] }
|
sub unpack { $_[0] }
|
||||||
|
@ -15,6 +16,8 @@ sub chained_path {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($start_near) = @_;
|
my ($start_near) = @_;
|
||||||
|
|
||||||
|
return @{$self->paths} if $self->no_sort;
|
||||||
|
|
||||||
# make sure we pass the same path objects to the Collection constructor
|
# make sure we pass the same path objects to the Collection constructor
|
||||||
# and the ->chained_path() method because the latter will reverse the
|
# and the ->chained_path() method because the latter will reverse the
|
||||||
# paths in-place when needed and we need to return them that way
|
# paths in-place when needed and we need to return them that way
|
||||||
|
|
|
@ -176,6 +176,7 @@ sub make_fill {
|
||||||
# save into layer
|
# save into layer
|
||||||
next unless @paths;
|
next unless @paths;
|
||||||
push @fills, Slic3r::ExtrusionPath::Collection->new(
|
push @fills, Slic3r::ExtrusionPath::Collection->new(
|
||||||
|
no_sort => $params->{no_sort},
|
||||||
paths => [
|
paths => [
|
||||||
map Slic3r::ExtrusionPath->pack(
|
map Slic3r::ExtrusionPath->pack(
|
||||||
polyline => Slic3r::Polyline->new(@$_),
|
polyline => Slic3r::Polyline->new(@$_),
|
||||||
|
|
|
@ -3,8 +3,8 @@ use Moo;
|
||||||
|
|
||||||
extends 'Slic3r::Fill::Base';
|
extends 'Slic3r::Fill::Base';
|
||||||
|
|
||||||
use Slic3r::ExtrusionPath ':roles';
|
use Slic3r::Geometry qw(scale unscale X1 X2);
|
||||||
use Slic3r::Geometry qw(scale unscale X1 Y1 X2 Y2);
|
use Slic3r::Geometry::Clipper qw(offset2 union_pt traverse_pt PFT_EVENODD);
|
||||||
|
|
||||||
sub fill_surface {
|
sub fill_surface {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
@ -27,48 +27,22 @@ sub fill_surface {
|
||||||
$flow_spacing = unscale $distance;
|
$flow_spacing = unscale $distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
my @contour_loops = ();
|
my @loops = my @last = @$expolygon;
|
||||||
my @hole_loops = ();
|
while (@last) {
|
||||||
my @last_offsets = ($expolygon->offset_ex($distance));
|
push @loops, @last = offset2(\@last, -1.5*$distance, +0.5*$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 = (@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
|
# clip the paths to avoid the extruder to get exactly on the first point of the loop
|
||||||
my @paths = ();
|
my $clip_length = scale $flow_spacing * &Slic3r::LOOP_CLIPPING_LENGTH_OVER_SPACING;
|
||||||
my $cur_pos = Slic3r::Point->new(
|
$_->clip_end($clip_length) for @paths;
|
||||||
($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;
|
|
||||||
|
|
||||||
# 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;
|
1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue