From 0ab1fd4c19ef921c54165a53e49c27e42c3a1f80 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 26 Nov 2011 10:38:05 +0100 Subject: [PATCH] concentric - new superfast infill pattern --- MANIFEST | 1 + lib/Slic3r/Config.pm | 4 +-- lib/Slic3r/Fill.pm | 2 ++ lib/Slic3r/Fill/Concentric.pm | 54 +++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 lib/Slic3r/Fill/Concentric.pm diff --git a/MANIFEST b/MANIFEST index d2ec690c6..b9b490a2b 100644 --- a/MANIFEST +++ b/MANIFEST @@ -10,6 +10,7 @@ lib/Slic3r/ExtrusionPath/Collection.pm lib/Slic3r/Fill.pm lib/Slic3r/Fill/ArchimedeanChords.pm lib/Slic3r/Fill/Base.pm +lib/Slic3r/Fill/Concentric.pm lib/Slic3r/Fill/Flowsnake.pm lib/Slic3r/Fill/HilbertCurve.pm lib/Slic3r/Fill/Line.pm diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index abbe6e7c2..d5dba7ec4 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -95,12 +95,12 @@ our $Options = { 'fill_pattern' => { label => 'Fill pattern', type => 'select', - values => [qw(rectilinear line hilbertcurve archimedeanchords octagramspiral)], + values => [qw(rectilinear line concentric hilbertcurve archimedeanchords octagramspiral)], }, 'solid_fill_pattern' => { label => 'Solid fill pattern', type => 'select', - values => [qw(rectilinear hilbertcurve archimedeanchords octagramspiral)], + values => [qw(rectilinear concentric hilbertcurve archimedeanchords octagramspiral)], }, 'fill_density' => { label => 'Fill density', diff --git a/lib/Slic3r/Fill.pm b/lib/Slic3r/Fill.pm index 9d630c7df..fb3094e19 100644 --- a/lib/Slic3r/Fill.pm +++ b/lib/Slic3r/Fill.pm @@ -3,6 +3,7 @@ use Moo; use Slic3r::Fill::ArchimedeanChords; use Slic3r::Fill::Base; +use Slic3r::Fill::Concentric; use Slic3r::Fill::Flowsnake; use Slic3r::Fill::HilbertCurve; use Slic3r::Fill::Line; @@ -26,6 +27,7 @@ our %FillTypes = ( octagramspiral => 'Slic3r::Fill::OctagramSpiral', hilbertcurve => 'Slic3r::Fill::HilbertCurve', line => 'Slic3r::Fill::Line', + concentric => 'Slic3r::Fill::Concentric', ); sub BUILD { diff --git a/lib/Slic3r/Fill/Concentric.pm b/lib/Slic3r/Fill/Concentric.pm new file mode 100644 index 000000000..6f6910b92 --- /dev/null +++ b/lib/Slic3r/Fill/Concentric.pm @@ -0,0 +1,54 @@ +package Slic3r::Fill::Concentric; +use Moo; + +extends 'Slic3r::Fill::Base'; + +use XXX; + +sub fill_surface { + my $self = shift; + my ($surface, %params) = @_; + + # no rotation is supported for this infill pattern + + my $flow_width_res = $params{flow_width} / $Slic3r::resolution; + my $distance = $flow_width_res / $params{density}; + + my @contour_loops = (); + my @hole_loops = (); + my @last_offsets = ($surface->expolygon->offset_ex($distance)); + while (@last_offsets) { + my @new_offsets = (); + foreach my $expolygon (@last_offsets) { + my @offsets = $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); + + # make paths + my @paths = (); + my $cur_pos = Slic3r::Point->new(0,0); + foreach my $loop (map Slic3r::ExtrusionLoop->cast($_), @loops) { + # find the point of the loop that is closest to the current extruder position + $cur_pos = $loop->nearest_point_to($cur_pos); + + # split the loop at the starting point and make a path + my $path = $loop->split_at($cur_pos); + + # clip the path to avoid the extruder to get exactly on the first point of the loop + $path->clip_end($Slic3r::flow_width / $Slic3r::resolution); + + push @paths, $path->p; + } + + return @paths; +} + +1;