Concentric.pm 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package Slic3r::Fill::Concentric;
  2. use Moo;
  3. extends 'Slic3r::Fill::Base';
  4. use Slic3r::Geometry qw(scale unscale X);
  5. use Slic3r::Geometry::Clipper qw(offset offset2 union_pt_chained);
  6. sub no_sort { 1 }
  7. sub fill_surface {
  8. my $self = shift;
  9. my ($surface, %params) = @_;
  10. # no rotation is supported for this infill pattern
  11. my $expolygon = $surface->expolygon;
  12. my $bounding_box = $expolygon->bounding_box;
  13. my $min_spacing = scale($self->spacing);
  14. my $distance = $min_spacing / $params{density};
  15. if ($params{density} == 1 && !$params{dont_adjust}) {
  16. $distance = $self->adjust_solid_spacing(
  17. width => $bounding_box->size->[X],
  18. distance => $distance,
  19. );
  20. $self->spacing(unscale $distance);
  21. }
  22. my @loops = my @last = map $_->clone, @$expolygon;
  23. while (@last) {
  24. push @loops, @last = @{offset2(\@last, -($distance + 0.5*$min_spacing), +0.5*$min_spacing)};
  25. }
  26. # generate paths from the outermost to the innermost, to avoid
  27. # adhesion problems of the first central tiny loops
  28. @loops = map Slic3r::Polygon->new(@$_),
  29. reverse @{union_pt_chained(\@loops)};
  30. # split paths using a nearest neighbor search
  31. my @paths = ();
  32. my $last_pos = Slic3r::Point->new(0,0);
  33. foreach my $loop (@loops) {
  34. push @paths, $loop->split_at_index($last_pos->nearest_point_index(\@$loop));
  35. $last_pos = $paths[-1]->last_point;
  36. }
  37. # clip the paths to prevent the extruder from getting exactly on the first point of the loop
  38. $_->clip_end($self->loop_clipping) for @paths;
  39. @paths = grep $_->is_valid, @paths; # remove empty paths (too short, thus eaten by clipping)
  40. # TODO: return ExtrusionLoop objects to get better chained paths
  41. return @paths;
  42. }
  43. 1;