2011-09-02 19:10:20 +00:00
|
|
|
package Slic3r::Perimeter;
|
2011-09-06 09:50:43 +00:00
|
|
|
use Moo;
|
2011-09-02 19:10:20 +00:00
|
|
|
|
2011-09-18 17:28:12 +00:00
|
|
|
use Math::Clipper ':all';
|
2011-12-03 17:31:31 +00:00
|
|
|
use Slic3r::Geometry qw(X Y shortest_path scale);
|
2011-09-18 17:28:12 +00:00
|
|
|
use XXX;
|
2011-09-02 19:10:20 +00:00
|
|
|
|
|
|
|
sub make_perimeter {
|
|
|
|
my $self = shift;
|
|
|
|
my ($layer) = @_;
|
2011-11-19 15:08:00 +00:00
|
|
|
printf "Making perimeter for layer %d\n", $layer->id;
|
2011-09-02 19:10:20 +00:00
|
|
|
|
2011-09-04 09:06:15 +00:00
|
|
|
# at least one perimeter is required
|
2011-10-15 09:36:05 +00:00
|
|
|
die "Can't slice object with no perimeters!\n"
|
2011-11-17 09:38:23 +00:00
|
|
|
if $Slic3r::perimeters == 0;
|
2011-09-02 19:10:20 +00:00
|
|
|
|
2011-10-15 09:36:05 +00:00
|
|
|
# this array will hold one arrayref per original surface;
|
|
|
|
# each item of this arrayref is an arrayref representing a depth (from inner
|
|
|
|
# perimeters to outer); each item of this arrayref is an ExPolygon:
|
|
|
|
# @perimeters = (
|
|
|
|
# [ # first object (identified by a single surface before offsetting)
|
2011-11-07 13:25:36 +00:00
|
|
|
# [ Slic3r::ExPolygon, Slic3r::ExPolygon... ], #depth 0: outer loop
|
|
|
|
# [ Slic3r::ExPolygon, Slic3r::ExPolygon... ], #depth 1: inner loop
|
2011-10-15 09:36:05 +00:00
|
|
|
# ],
|
|
|
|
# [ # second object
|
|
|
|
# ...
|
|
|
|
# ]
|
|
|
|
# )
|
|
|
|
my @perimeters = (); # one item per depth; each item
|
|
|
|
|
2011-11-23 11:29:27 +00:00
|
|
|
# organize perimeter surfaces using a shortest path search
|
|
|
|
my @surfaces = @{shortest_path([
|
2011-12-03 17:31:31 +00:00
|
|
|
map [ $_->contour->points->[0], $_ ], @{$layer->slices},
|
2011-11-07 14:40:09 +00:00
|
|
|
])};
|
|
|
|
|
2011-11-23 11:29:27 +00:00
|
|
|
foreach my $surface (@surfaces) {
|
2011-10-15 09:36:05 +00:00
|
|
|
# the outer loop must be offsetted by half extrusion width inwards
|
|
|
|
my @last_offsets = ($surface->expolygon);
|
2011-12-03 17:31:31 +00:00
|
|
|
my $distance = scale $Slic3r::flow_width / 2;
|
2011-09-02 19:10:20 +00:00
|
|
|
|
|
|
|
# create other offsets
|
2011-10-15 09:36:05 +00:00
|
|
|
push @perimeters, [];
|
2011-11-17 09:38:23 +00:00
|
|
|
for (my $loop = 0; $loop < $Slic3r::perimeters; $loop++) {
|
2011-09-04 10:04:01 +00:00
|
|
|
# offsetting a polygon can result in one or many offset polygons
|
2011-11-16 15:35:20 +00:00
|
|
|
@last_offsets = map $_->offset_ex(-$distance), @last_offsets;
|
2011-10-15 09:36:05 +00:00
|
|
|
push @{ $perimeters[-1] }, [@last_offsets];
|
2011-09-02 19:10:20 +00:00
|
|
|
|
2011-10-15 09:36:05 +00:00
|
|
|
# offset distance for inner loops
|
|
|
|
$distance = $Slic3r::flow_width / $Slic3r::resolution;
|
2011-09-02 19:10:20 +00:00
|
|
|
}
|
2011-09-04 10:04:01 +00:00
|
|
|
|
|
|
|
# create one more offset to be used as boundary for fill
|
2011-10-07 17:07:57 +00:00
|
|
|
{
|
2011-12-03 17:31:31 +00:00
|
|
|
$distance -= scale $Slic3r::flow_width * $Slic3r::perimeter_infill_overlap_ratio;
|
2011-11-23 11:29:27 +00:00
|
|
|
my @fill_boundaries = map Slic3r::Surface->cast_from_expolygon
|
2011-10-15 09:36:05 +00:00
|
|
|
($_, surface_type => $surface->surface_type),
|
2011-11-16 15:35:20 +00:00
|
|
|
map $_->offset_ex(-$distance), @last_offsets;
|
2011-10-07 17:07:57 +00:00
|
|
|
|
2011-11-23 11:29:27 +00:00
|
|
|
push @{ $layer->fill_boundaries }, @fill_boundaries if @fill_boundaries;
|
2011-10-15 09:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-07 13:25:36 +00:00
|
|
|
# process one island (original surface) at time
|
|
|
|
foreach my $island (@perimeters) {
|
|
|
|
# do holes starting from innermost one
|
|
|
|
foreach my $hole (map $_->holes, map @$_, @$island) {
|
2011-11-28 17:37:53 +00:00
|
|
|
push @{ $layer->perimeters }, Slic3r::ExtrusionLoop->cast($hole, role => 'perimeter');
|
2011-10-07 17:07:57 +00:00
|
|
|
}
|
2011-11-07 13:25:36 +00:00
|
|
|
|
|
|
|
# do contours starting from innermost one
|
|
|
|
foreach my $contour (map $_->contour, map @$_, reverse @$island) {
|
2011-11-28 17:37:53 +00:00
|
|
|
push @{ $layer->perimeters }, Slic3r::ExtrusionLoop->cast($contour, role => 'perimeter');
|
2011-11-07 13:25:36 +00:00
|
|
|
}
|
2011-09-02 19:10:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|