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-11-05 17:19:35 +00:00
|
|
|
use Math::ConvexHull 1.0.4 qw(convex_hull);
|
2011-09-18 17:28:12 +00:00
|
|
|
use XXX;
|
2011-09-02 19:10:20 +00:00
|
|
|
|
2011-09-05 18:29:07 +00:00
|
|
|
use constant X => 0;
|
|
|
|
use constant Y => 1;
|
|
|
|
|
2011-09-02 19:10:20 +00:00
|
|
|
sub make_perimeter {
|
|
|
|
my $self = shift;
|
|
|
|
my ($layer) = @_;
|
|
|
|
printf "Making perimeter for layer %d:\n", $layer->id;
|
|
|
|
|
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-09-04 09:06:15 +00:00
|
|
|
if $Slic3r::perimeter_offsets == 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)
|
|
|
|
# [ Slic3r::ExPolygon, Slic3r::ExPolygon... ], #item 0: outer loop
|
|
|
|
# [ Slic3r::ExPolygon, Slic3r::ExPolygon... ], #item 1: inner loop
|
|
|
|
# ],
|
|
|
|
# [ # second object
|
|
|
|
# ...
|
|
|
|
# ]
|
|
|
|
# )
|
|
|
|
my @perimeters = (); # one item per depth; each item
|
|
|
|
|
2011-10-07 17:07:57 +00:00
|
|
|
foreach my $surface (@{ $layer->perimeter_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);
|
|
|
|
my $distance = $Slic3r::flow_width / 2 / $Slic3r::resolution;
|
2011-09-02 19:10:20 +00:00
|
|
|
|
|
|
|
# create other offsets
|
2011-10-15 09:36:05 +00:00
|
|
|
push @perimeters, [];
|
|
|
|
for (my $loop = 0; $loop < $Slic3r::perimeter_offsets; $loop++) {
|
2011-09-04 10:04:01 +00:00
|
|
|
# offsetting a polygon can result in one or many offset polygons
|
2011-10-15 09:36:05 +00:00
|
|
|
@last_offsets = map $_->offset(-$distance), @last_offsets;
|
|
|
|
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-10-15 09:36:05 +00:00
|
|
|
my @fill_surfaces = map Slic3r::Surface->cast_from_expolygon
|
|
|
|
($_, surface_type => $surface->surface_type),
|
|
|
|
map $_->offset(-$distance), @last_offsets;
|
2011-10-07 17:07:57 +00:00
|
|
|
|
2011-10-15 09:36:05 +00:00
|
|
|
push @{ $layer->fill_surfaces }, [@fill_surfaces] if @fill_surfaces;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# first generate paths for all holes, starting from external (innermost) perimeters
|
|
|
|
foreach my $i (1..$Slic3r::perimeter_offsets) {
|
|
|
|
foreach my $hole (map $_->holes, map @{$_->[$i-1]}, @perimeters) {
|
|
|
|
push @{ $layer->perimeters }, Slic3r::ExtrusionLoop->cast($hole);
|
2011-10-07 17:07:57 +00:00
|
|
|
}
|
2011-09-02 19:10:20 +00:00
|
|
|
}
|
|
|
|
|
2011-10-15 09:36:05 +00:00
|
|
|
# then generate paths for contours
|
2011-09-02 19:10:20 +00:00
|
|
|
# this time we do something different: we do contour loops for one
|
|
|
|
# shape (that is, one original surface) at a time: we start from the
|
|
|
|
# innermost loop (that is, internal one), then without interrupting
|
|
|
|
# our path we go onto the outer loop and continue; this should ensure
|
|
|
|
# good surface quality
|
2011-10-15 09:36:05 +00:00
|
|
|
foreach my $contour (map $_->contour, map @$_, map @$_, @perimeters) {
|
|
|
|
push @{ $layer->perimeters }, Slic3r::ExtrusionLoop->cast($contour);
|
2011-09-02 19:10:20 +00:00
|
|
|
}
|
2011-09-05 18:00:59 +00:00
|
|
|
|
|
|
|
# generate skirt on bottom layer
|
2011-10-04 15:55:55 +00:00
|
|
|
if ($layer->id == 0 && $Slic3r::skirts > 0 && @{ $layer->surfaces }) {
|
2011-09-05 18:00:59 +00:00
|
|
|
# find out convex hull
|
2011-10-06 10:39:58 +00:00
|
|
|
my $convex_hull = convex_hull([ map @$_, map $_->p, @{ $layer->surfaces } ]);
|
2011-09-05 18:00:59 +00:00
|
|
|
|
|
|
|
# draw outlines from outside to inside
|
|
|
|
for (my $i = $Slic3r::skirts - 1; $i >= 0; $i--) {
|
2011-09-25 18:24:14 +00:00
|
|
|
my $distance = ($Slic3r::skirt_distance + ($Slic3r::flow_width * $i)) / $Slic3r::resolution;
|
2011-10-06 10:39:58 +00:00
|
|
|
my $outline = offset([$convex_hull], $distance, $Slic3r::resolution * 100, JT_ROUND);
|
2011-09-26 09:42:08 +00:00
|
|
|
push @{ $layer->skirts }, Slic3r::ExtrusionLoop->cast([ @{$outline->[0]} ]);
|
2011-09-05 18:00:59 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-02 19:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|