Concentric.pm 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 traverse_pt PFT_EVENODD);
  6. sub fill_surface {
  7. my $self = shift;
  8. my ($surface, %params) = @_;
  9. # no rotation is supported for this infill pattern
  10. my $expolygon = $surface->expolygon;
  11. my $bounding_box = $expolygon->bounding_box;
  12. my $min_spacing = scale $params{flow_spacing};
  13. my $distance = $min_spacing / $params{density};
  14. my $flow_spacing = $params{flow_spacing};
  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. $flow_spacing = unscale $distance;
  21. }
  22. # compensate the overlap which is good for rectilinear but harmful for concentric
  23. # where the perimeter/infill spacing should be equal to any other loop spacing
  24. my @loops = my @last = @{offset($expolygon, -&Slic3r::INFILL_OVERLAP_OVER_SPACING * $min_spacing / 2)};
  25. while (@last) {
  26. push @loops, @last = @{offset2(\@last, -1.5*$distance, +0.5*$distance)};
  27. }
  28. # generate paths from the outermost to the innermost, to avoid
  29. # adhesion problems of the first central tiny loops
  30. @loops = map Slic3r::Polygon->new(@$_),
  31. reverse traverse_pt( union_pt(\@loops) );
  32. # order paths using a nearest neighbor search
  33. my @paths = ();
  34. my $last_pos = [0,0];
  35. foreach my $loop (@loops) {
  36. push @paths, $loop->split_at_index($last_pos->nearest_point_index($loop));
  37. $last_pos = $paths[-1][-1];
  38. }
  39. # clip the paths to avoid the extruder to get exactly on the first point of the loop
  40. my $clip_length = scale $flow_spacing * &Slic3r::LOOP_CLIPPING_LENGTH_OVER_SPACING;
  41. $_->clip_end($clip_length) for @paths;
  42. # TODO: return ExtrusionLoop objects to get better chained paths
  43. return { flow_spacing => $flow_spacing, no_sort => 1 }, @paths;
  44. }
  45. 1;