2011-09-05 10:21:27 +00:00
|
|
|
package Slic3r::Fill;
|
2011-09-06 09:50:43 +00:00
|
|
|
use Moo;
|
2011-09-05 10:21:27 +00:00
|
|
|
|
2011-11-13 17:14:02 +00:00
|
|
|
use Slic3r::Fill::ArchimedeanChords;
|
2011-10-06 11:43:32 +00:00
|
|
|
use Slic3r::Fill::Base;
|
2011-11-26 09:38:05 +00:00
|
|
|
use Slic3r::Fill::Concentric;
|
2011-11-13 17:14:02 +00:00
|
|
|
use Slic3r::Fill::Flowsnake;
|
|
|
|
use Slic3r::Fill::HilbertCurve;
|
2012-04-16 09:55:14 +00:00
|
|
|
use Slic3r::Fill::Honeycomb;
|
2011-11-14 09:31:07 +00:00
|
|
|
use Slic3r::Fill::Line;
|
2011-11-13 17:14:02 +00:00
|
|
|
use Slic3r::Fill::OctagramSpiral;
|
2011-11-14 14:23:17 +00:00
|
|
|
use Slic3r::Fill::PlanePath;
|
2011-09-05 10:21:27 +00:00
|
|
|
use Slic3r::Fill::Rectilinear;
|
2012-05-19 13:40:11 +00:00
|
|
|
use Slic3r::ExtrusionPath ':roles';
|
2012-04-30 12:56:01 +00:00
|
|
|
use Slic3r::Geometry qw(X Y scale shortest_path);
|
2011-11-23 11:29:27 +00:00
|
|
|
use Slic3r::Geometry::Clipper qw(union_ex diff_ex);
|
2012-05-19 14:04:33 +00:00
|
|
|
use Slic3r::Surface ':types';
|
2011-09-05 10:21:27 +00:00
|
|
|
|
2011-10-07 17:07:57 +00:00
|
|
|
|
2011-10-06 11:43:32 +00:00
|
|
|
has 'print' => (is => 'ro', required => 1);
|
2012-04-30 21:50:38 +00:00
|
|
|
has 'max_print_dimension' => (is => 'rw');
|
2011-10-06 11:43:32 +00:00
|
|
|
has 'fillers' => (is => 'rw', default => sub { {} });
|
|
|
|
|
|
|
|
our %FillTypes = (
|
2011-11-13 17:14:02 +00:00
|
|
|
archimedeanchords => 'Slic3r::Fill::ArchimedeanChords',
|
|
|
|
rectilinear => 'Slic3r::Fill::Rectilinear',
|
|
|
|
flowsnake => 'Slic3r::Fill::Flowsnake',
|
|
|
|
octagramspiral => 'Slic3r::Fill::OctagramSpiral',
|
|
|
|
hilbertcurve => 'Slic3r::Fill::HilbertCurve',
|
2011-11-14 09:31:07 +00:00
|
|
|
line => 'Slic3r::Fill::Line',
|
2011-11-26 09:38:05 +00:00
|
|
|
concentric => 'Slic3r::Fill::Concentric',
|
2012-04-16 09:55:14 +00:00
|
|
|
honeycomb => 'Slic3r::Fill::Honeycomb',
|
2011-10-06 11:43:32 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
sub BUILD {
|
|
|
|
my $self = shift;
|
2012-02-19 11:03:36 +00:00
|
|
|
|
2012-04-30 12:56:01 +00:00
|
|
|
my $print_size = $self->print->size;
|
|
|
|
my $max_print_dimension = ($print_size->[X] > $print_size->[Y] ? $print_size->[X] : $print_size->[Y]) * sqrt(2);
|
2012-04-30 21:50:38 +00:00
|
|
|
$self->max_print_dimension($max_print_dimension);
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
$self->filler($_) for ('rectilinear', $Slic3r::Config->fill_pattern, $Slic3r::Config->solid_fill_pattern);
|
2012-04-30 21:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub filler {
|
|
|
|
my $self = shift;
|
|
|
|
my ($filler) = @_;
|
|
|
|
if (!$self->fillers->{$filler}) {
|
|
|
|
$self->fillers->{$filler} = $FillTypes{$filler}->new(print => $self->print);
|
|
|
|
$self->fillers->{$filler}->max_print_dimension($self->max_print_dimension);
|
|
|
|
}
|
|
|
|
return $self->fillers->{$filler};
|
2011-10-06 11:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub make_fill {
|
|
|
|
my $self = shift;
|
|
|
|
my ($layer) = @_;
|
|
|
|
|
2012-02-19 11:03:36 +00:00
|
|
|
$_->layer($layer) for values %{$self->fillers};
|
2011-10-06 11:43:32 +00:00
|
|
|
|
2012-02-20 11:50:05 +00:00
|
|
|
Slic3r::debugf "Filling layer %d:\n", $layer->id;
|
2011-11-13 20:46:32 +00:00
|
|
|
|
2011-11-23 11:29:27 +00:00
|
|
|
# merge overlapping surfaces
|
|
|
|
my @surfaces = ();
|
|
|
|
{
|
2011-11-30 19:32:28 +00:00
|
|
|
my @surfaces_with_bridge_angle = grep defined $_->bridge_angle, @{$layer->fill_surfaces};
|
2012-01-11 22:15:32 +00:00
|
|
|
|
|
|
|
# give priority to bridges
|
|
|
|
my @groups = Slic3r::Surface->group({merge_solid => 1}, @{$layer->fill_surfaces});
|
|
|
|
@groups = sort { defined $a->[0]->bridge_angle ? -1 : 0 } @groups;
|
|
|
|
|
|
|
|
foreach my $group (@groups) {
|
2011-12-02 22:35:39 +00:00
|
|
|
my $union = union_ex([ map $_->p, @$group ], undef, 1);
|
2011-10-06 11:43:32 +00:00
|
|
|
|
2011-11-23 11:29:27 +00:00
|
|
|
# subtract surfaces having a defined bridge_angle from any other
|
|
|
|
if (@surfaces_with_bridge_angle && !defined $group->[0]->bridge_angle) {
|
|
|
|
$union = diff_ex(
|
|
|
|
[ map @$_, @$union ],
|
|
|
|
[ map $_->p, @surfaces_with_bridge_angle ],
|
2011-12-04 15:24:46 +00:00
|
|
|
1,
|
2011-11-23 11:29:27 +00:00
|
|
|
);
|
2011-10-06 11:43:32 +00:00
|
|
|
}
|
|
|
|
|
2011-11-29 10:36:52 +00:00
|
|
|
# subtract any other surface already processed
|
|
|
|
$union = diff_ex(
|
|
|
|
[ map @$_, @$union ],
|
|
|
|
[ map $_->p, @surfaces ],
|
2011-12-04 15:24:46 +00:00
|
|
|
1,
|
2011-11-29 10:36:52 +00:00
|
|
|
);
|
|
|
|
|
2011-12-30 18:59:51 +00:00
|
|
|
push @surfaces, map Slic3r::Surface->new(
|
|
|
|
expolygon => $_,
|
2011-11-23 11:29:27 +00:00
|
|
|
surface_type => $group->[0]->surface_type,
|
|
|
|
bridge_angle => $group->[0]->bridge_angle,
|
2011-11-26 14:21:15 +00:00
|
|
|
depth_layers => $group->[0]->depth_layers,
|
2011-11-23 11:29:27 +00:00
|
|
|
), @$union;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-18 12:38:45 +00:00
|
|
|
# add spacing between adjacent surfaces
|
|
|
|
{
|
2012-09-23 01:03:08 +00:00
|
|
|
my $distance = $layer->infill_flow->scaled_spacing / 2;
|
2011-12-18 12:38:45 +00:00
|
|
|
my @offsets = ();
|
|
|
|
foreach my $surface (@surfaces) {
|
|
|
|
my $expolygon = $surface->expolygon;
|
|
|
|
my $diff = diff_ex(
|
|
|
|
[ $expolygon->offset($distance) ],
|
|
|
|
$expolygon,
|
|
|
|
1,
|
|
|
|
);
|
|
|
|
push @offsets, map @$_, @$diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
my @new_surfaces = ();
|
|
|
|
foreach my $surface (@surfaces) {
|
|
|
|
my $diff = diff_ex(
|
|
|
|
$surface->expolygon,
|
|
|
|
[ @offsets ],
|
|
|
|
);
|
|
|
|
|
2011-12-30 18:59:51 +00:00
|
|
|
push @new_surfaces, map Slic3r::Surface->new(
|
|
|
|
expolygon => $_,
|
2011-12-18 12:38:45 +00:00
|
|
|
surface_type => $surface->surface_type,
|
|
|
|
bridge_angle => $surface->bridge_angle,
|
|
|
|
depth_layers => $surface->depth_layers,
|
|
|
|
), @$diff;
|
|
|
|
}
|
|
|
|
@surfaces = @new_surfaces;
|
|
|
|
}
|
|
|
|
|
2012-01-28 15:27:52 +00:00
|
|
|
my @fills = ();
|
2012-06-30 14:33:01 +00:00
|
|
|
my @fills_ordering_points = ();
|
2011-11-23 11:29:27 +00:00
|
|
|
SURFACE: foreach my $surface (@surfaces) {
|
2012-07-27 19:13:03 +00:00
|
|
|
my $filler = $Slic3r::Config->fill_pattern;
|
|
|
|
my $density = $Slic3r::Config->fill_density;
|
2012-06-27 17:55:54 +00:00
|
|
|
my $flow_spacing = $layer->infill_flow->spacing;
|
2012-05-19 14:04:33 +00:00
|
|
|
my $is_bridge = $layer->id > 0 && $surface->surface_type == S_TYPE_BOTTOM;
|
2012-05-20 15:28:53 +00:00
|
|
|
my $is_solid = (grep { $surface->surface_type == $_ } S_TYPE_TOP, S_TYPE_BOTTOM, S_TYPE_INTERNALSOLID) ? 1 : 0;
|
2011-11-23 11:29:27 +00:00
|
|
|
|
|
|
|
# force 100% density and rectilinear fill for external surfaces
|
2012-05-19 14:04:33 +00:00
|
|
|
if ($surface->surface_type != S_TYPE_INTERNAL) {
|
2011-11-23 11:29:27 +00:00
|
|
|
$density = 1;
|
2012-07-27 19:13:03 +00:00
|
|
|
$filler = $Slic3r::Config->solid_fill_pattern;
|
2011-12-04 19:29:21 +00:00
|
|
|
if ($is_bridge) {
|
|
|
|
$filler = 'rectilinear';
|
2012-07-27 19:13:03 +00:00
|
|
|
$flow_spacing = sqrt($Slic3r::Config->bridge_flow_ratio * ($layer->infill_flow->nozzle_diameter**2));
|
2012-05-19 14:04:33 +00:00
|
|
|
} elsif ($surface->surface_type == S_TYPE_INTERNALSOLID) {
|
2011-12-15 21:05:15 +00:00
|
|
|
$filler = 'rectilinear';
|
2011-12-04 19:29:21 +00:00
|
|
|
}
|
2011-11-23 11:29:27 +00:00
|
|
|
} else {
|
|
|
|
next SURFACE unless $density > 0;
|
2011-10-06 11:43:32 +00:00
|
|
|
}
|
2011-11-23 11:29:27 +00:00
|
|
|
|
|
|
|
my @paths = $self->fillers->{$filler}->fill_surface(
|
|
|
|
$surface,
|
2011-12-07 18:33:59 +00:00
|
|
|
density => $density,
|
2011-12-17 18:52:34 +00:00
|
|
|
flow_spacing => $flow_spacing,
|
2011-11-23 11:29:27 +00:00
|
|
|
);
|
2011-12-04 15:24:46 +00:00
|
|
|
my $params = shift @paths;
|
2011-11-23 11:29:27 +00:00
|
|
|
|
|
|
|
# save into layer
|
2012-06-30 14:33:01 +00:00
|
|
|
next unless @paths;
|
2012-01-28 15:27:52 +00:00
|
|
|
push @fills, Slic3r::ExtrusionPath::Collection->new(
|
2011-11-23 11:29:27 +00:00
|
|
|
paths => [
|
2012-07-20 12:39:07 +00:00
|
|
|
map Slic3r::ExtrusionPath->pack(
|
2011-12-30 18:59:51 +00:00
|
|
|
polyline => Slic3r::Polyline->new(@$_),
|
2012-06-06 17:57:16 +00:00
|
|
|
role => ($is_bridge
|
|
|
|
? EXTR_ROLE_BRIDGE
|
|
|
|
: $is_solid
|
|
|
|
? ($surface->surface_type == S_TYPE_TOP ? EXTR_ROLE_TOPSOLIDFILL : EXTR_ROLE_SOLIDFILL)
|
|
|
|
: EXTR_ROLE_FILL),
|
2011-11-23 11:29:27 +00:00
|
|
|
depth_layers => $surface->depth_layers,
|
2012-09-12 10:13:43 +00:00
|
|
|
flow_spacing => $params->{flow_spacing} || (warn "Warning: no flow_spacing was returned by the infill engine, please report this to the developer\n"),
|
2011-11-23 11:29:27 +00:00
|
|
|
), @paths,
|
|
|
|
],
|
2012-06-30 14:33:01 +00:00
|
|
|
);
|
|
|
|
push @fills_ordering_points, $paths[0][0];
|
2011-10-06 11:43:32 +00:00
|
|
|
}
|
2012-01-12 21:05:35 +00:00
|
|
|
|
|
|
|
# add thin fill regions
|
2012-07-01 16:12:21 +00:00
|
|
|
{
|
|
|
|
my %args = (
|
|
|
|
role => EXTR_ROLE_SOLIDFILL,
|
2012-07-27 19:13:03 +00:00
|
|
|
flow_spacing => $layer->perimeter_flow->spacing,
|
2012-07-01 16:12:21 +00:00
|
|
|
);
|
|
|
|
push @fills, map {
|
2012-06-30 14:33:01 +00:00
|
|
|
$_->isa('Slic3r::Polygon')
|
2012-07-28 09:04:26 +00:00
|
|
|
? (map $_->pack, Slic3r::ExtrusionLoop->new(polygon => $_, %args)->split_at_first_point)
|
2012-07-20 12:39:07 +00:00
|
|
|
: Slic3r::ExtrusionPath->pack(polyline => $_, %args),
|
2012-06-30 14:33:01 +00:00
|
|
|
} @{$layer->thin_fills};
|
2012-07-01 16:12:21 +00:00
|
|
|
}
|
2012-06-30 14:33:01 +00:00
|
|
|
push @fills_ordering_points, map $_->[0], @{$layer->thin_fills};
|
|
|
|
|
|
|
|
# organize infill paths using a shortest path search
|
|
|
|
@fills = @{shortest_path([
|
|
|
|
map [ $fills_ordering_points[$_], $fills[$_] ], 0..$#fills,
|
|
|
|
])};
|
2012-01-28 15:27:52 +00:00
|
|
|
|
|
|
|
return @fills;
|
2011-10-06 11:43:32 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 10:21:27 +00:00
|
|
|
1;
|