Concentric.pm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package Slic3r::Fill::Concentric;
  2. use Moo;
  3. extends 'Slic3r::Fill::Base';
  4. use Slic3r::ExtrusionPath ':roles';
  5. use Slic3r::Geometry qw(scale unscale X1 Y1 X2 Y2);
  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;
  15. if ($params{density} == 1) {
  16. $distance = $self->adjust_solid_spacing(
  17. width => $bounding_box->[X2] - $bounding_box->[X1],
  18. distance => $distance,
  19. );
  20. $flow_spacing = unscale $distance;
  21. }
  22. my @contour_loops = ();
  23. my @hole_loops = ();
  24. my @last_offsets = ($expolygon->offset_ex($distance));
  25. while (@last_offsets) {
  26. my @new_offsets = ();
  27. foreach my $last_expolygon (@last_offsets) {
  28. my @offsets = $last_expolygon->offset_ex(-$distance);
  29. foreach my $offset (@offsets) {
  30. push @new_offsets, $offset;
  31. push @contour_loops, $offset->contour;
  32. push @hole_loops, $offset->holes;
  33. }
  34. }
  35. @last_offsets = @new_offsets;
  36. }
  37. my @loops = (@contour_loops, reverse @hole_loops);
  38. # make paths
  39. my @paths = ();
  40. my $cur_pos = Slic3r::Point->new(
  41. ($bounding_box->[X1] + $bounding_box->[X2]) / 2,
  42. ($bounding_box->[Y1] + $bounding_box->[Y2]) / 2,
  43. );
  44. foreach my $loop (map Slic3r::ExtrusionLoop->new(polygon => $_, role => EXTR_ROLE_FILL), @loops) {
  45. # extrude all loops ccw
  46. $loop->deserialize;
  47. $loop->polygon->make_counter_clockwise;
  48. # find the point of the loop that is closest to the current extruder position
  49. $cur_pos = $loop->nearest_point_to($cur_pos);
  50. # split the loop at the starting point and make a path
  51. my $path = $loop->split_at($cur_pos);
  52. $path->deserialize;
  53. # clip the path to avoid the extruder to get exactly on the first point of the loop
  54. $path->clip_end(scale($self->layer->flow_width || $Slic3r::flow_width) * 0.15);
  55. push @paths, $path->points if @{$path->points};
  56. }
  57. return { flow_spacing => $flow_spacing }, @paths;
  58. }
  59. 1;