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';
|
2013-02-05 16:27:45 +00:00
|
|
|
use Slic3r::Geometry qw(X Y PI scale chained_path);
|
2013-03-13 13:55:58 +00:00
|
|
|
use Slic3r::Geometry::Clipper qw(union_ex diff diff_ex intersection_ex offset);
|
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
|
|
|
|
2013-05-19 09:35:41 +00:00
|
|
|
has 'object' => (is => 'ro', required => 1, weak_ref => 1);
|
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
|
|
|
);
|
|
|
|
|
2012-04-30 21:50:38 +00:00
|
|
|
sub filler {
|
|
|
|
my $self = shift;
|
|
|
|
my ($filler) = @_;
|
2012-10-30 13:34:41 +00:00
|
|
|
|
2012-10-30 14:38:17 +00:00
|
|
|
if (!ref $self) {
|
|
|
|
return $FillTypes{$filler}->new;
|
|
|
|
}
|
|
|
|
|
2013-04-18 15:34:21 +00:00
|
|
|
$self->fillers->{$filler} ||= $FillTypes{$filler}->new(
|
2013-06-16 10:21:25 +00:00
|
|
|
bounding_box => $self->object->bounding_box,
|
2013-04-18 15:34:21 +00:00
|
|
|
);
|
2012-04-30 21:50:38 +00:00
|
|
|
return $self->fillers->{$filler};
|
2011-10-06 11:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub make_fill {
|
|
|
|
my $self = shift;
|
2013-02-27 09:44:42 +00:00
|
|
|
my ($layerm) = @_;
|
2011-10-06 11:43:32 +00:00
|
|
|
|
2013-02-27 09:44:42 +00:00
|
|
|
Slic3r::debugf "Filling layer %d:\n", $layerm->id;
|
2011-11-13 20:46:32 +00:00
|
|
|
|
2013-03-07 15:24:25 +00:00
|
|
|
my @surfaces = ();
|
|
|
|
|
|
|
|
# if hollow object is requested, remove internal surfaces
|
|
|
|
# (this needs to be done after internal-solid shells are created)
|
|
|
|
if ($Slic3r::Config->fill_density == 0) {
|
|
|
|
@surfaces = grep $_->surface_type != S_TYPE_INTERNAL, @surfaces;
|
|
|
|
}
|
|
|
|
|
2013-03-05 19:03:46 +00:00
|
|
|
# merge adjacent surfaces
|
|
|
|
# in case of bridge surfaces, the ones with defined angle will be attached to the ones
|
2013-03-07 14:47:32 +00:00
|
|
|
# without any angle (shouldn't this logic be moved to process_external_surfaces()?)
|
2011-11-23 11:29:27 +00:00
|
|
|
{
|
2013-02-27 09:44:42 +00:00
|
|
|
my @surfaces_with_bridge_angle = grep defined $_->bridge_angle, @{$layerm->fill_surfaces};
|
2012-01-11 22:15:32 +00:00
|
|
|
|
|
|
|
# give priority to bridges
|
2013-02-27 09:44:42 +00:00
|
|
|
my @groups = Slic3r::Surface->group({merge_solid => 1}, @{$layerm->fill_surfaces});
|
2012-01-11 22:15:32 +00:00
|
|
|
@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
|
|
|
);
|
|
|
|
|
2013-03-29 18:18:06 +00:00
|
|
|
push @surfaces, map $group->[0]->clone(expolygon => $_), @$union;
|
2011-11-23 11:29:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 00:03:54 +00:00
|
|
|
# we need to detect any narrow surfaces that might collapse
|
|
|
|
# when adding spacing below
|
|
|
|
# such narrow surfaces are often generated in sloping walls
|
|
|
|
# by bridge_over_infill() and combine_infill() as a result of the
|
|
|
|
# subtraction of the combinable area from the layer infill area,
|
|
|
|
# which leaves small areas near the perimeters
|
|
|
|
# we are going to grow such regions by overlapping them with the void (if any)
|
|
|
|
# TODO: detect and investigate whether there could be narrow regions without
|
|
|
|
# any void neighbors
|
2013-03-17 01:30:20 +00:00
|
|
|
my $distance_between_surfaces = $layerm->solid_infill_flow->scaled_spacing;
|
2011-12-18 12:38:45 +00:00
|
|
|
{
|
2013-03-13 13:55:58 +00:00
|
|
|
my $collapsed = diff(
|
2013-03-13 00:03:54 +00:00
|
|
|
[ map @{$_->expolygon}, @surfaces ],
|
|
|
|
[ offset(
|
|
|
|
[ offset([ map @{$_->expolygon}, @surfaces ], -$distance_between_surfaces/2) ],
|
|
|
|
+$distance_between_surfaces/2
|
|
|
|
) ],
|
2013-03-13 13:55:58 +00:00
|
|
|
1,
|
2013-03-13 00:03:54 +00:00
|
|
|
);
|
|
|
|
push @surfaces, map Slic3r::Surface->new(
|
|
|
|
expolygon => $_,
|
|
|
|
surface_type => S_TYPE_INTERNALSOLID,
|
|
|
|
), @{intersection_ex(
|
2013-03-13 13:55:58 +00:00
|
|
|
[ offset($collapsed, $distance_between_surfaces) ],
|
|
|
|
[
|
|
|
|
(map @{$_->expolygon}, grep $_->surface_type == S_TYPE_INTERNALVOID, @surfaces),
|
|
|
|
(@$collapsed),
|
|
|
|
],
|
|
|
|
undef,
|
|
|
|
1,
|
2013-03-13 00:03:54 +00:00
|
|
|
)};
|
2011-12-18 12:38:45 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 00:03:54 +00:00
|
|
|
# add spacing between surfaces
|
2013-03-17 01:30:20 +00:00
|
|
|
@surfaces = map $_->offset(-$distance_between_surfaces / 2 * &Slic3r::INFILL_OVERLAP_OVER_SPACING), @surfaces;
|
2013-03-13 00:03:54 +00:00
|
|
|
|
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) {
|
2013-03-13 00:03:54 +00:00
|
|
|
next if $surface->surface_type == S_TYPE_INTERNALVOID;
|
2012-07-27 19:13:03 +00:00
|
|
|
my $filler = $Slic3r::Config->fill_pattern;
|
|
|
|
my $density = $Slic3r::Config->fill_density;
|
2013-03-16 23:02:31 +00:00
|
|
|
my $flow = ($surface->surface_type == S_TYPE_TOP)
|
|
|
|
? $layerm->top_infill_flow
|
|
|
|
: $surface->is_solid
|
|
|
|
? $layerm->solid_infill_flow
|
|
|
|
: $layerm->infill_flow;
|
|
|
|
my $flow_spacing = $flow->spacing;
|
2013-02-27 09:44:42 +00:00
|
|
|
my $is_bridge = $layerm->id > 0 && $surface->is_bridge;
|
2013-02-23 20:39:13 +00:00
|
|
|
my $is_solid = $surface->is_solid;
|
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) {
|
2013-03-18 12:32:19 +00:00
|
|
|
$filler = 'rectilinear';
|
2013-02-27 09:44:42 +00:00
|
|
|
$flow_spacing = $layerm->extruders->{infill}->bridge_flow->spacing;
|
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
|
|
|
|
2012-11-06 21:16:01 +00:00
|
|
|
my @paths;
|
|
|
|
{
|
|
|
|
my $f = $self->filler($filler);
|
2013-02-27 09:44:42 +00:00
|
|
|
$f->layer_id($layerm->id);
|
2012-11-06 21:16:01 +00:00
|
|
|
@paths = $f->fill_surface(
|
|
|
|
$surface,
|
|
|
|
density => $density,
|
|
|
|
flow_spacing => $flow_spacing,
|
2012-11-16 17:10:09 +00:00
|
|
|
dont_adjust => $is_bridge,
|
2012-11-06 21:16:01 +00:00
|
|
|
);
|
|
|
|
}
|
2011-12-04 15:24:46 +00:00
|
|
|
my $params = shift @paths;
|
2011-11-23 11:29:27 +00:00
|
|
|
|
2012-11-18 14:42:59 +00:00
|
|
|
# ugly hack(tm) to get the right amount of flow (GCode.pm should be fixed)
|
2013-02-27 09:44:42 +00:00
|
|
|
$params->{flow_spacing} = $layerm->extruders->{infill}->bridge_flow->width if $is_bridge;
|
2012-11-18 14:42:59 +00:00
|
|
|
|
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(
|
2013-05-13 19:22:57 +00:00
|
|
|
no_sort => $params->{no_sort},
|
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(@$_),
|
2013-03-16 23:42:53 +00:00
|
|
|
role => ($surface->surface_type == S_TYPE_INTERNALBRIDGE
|
|
|
|
? EXTR_ROLE_INTERNALBRIDGE
|
|
|
|
: $is_bridge
|
|
|
|
? EXTR_ROLE_BRIDGE
|
|
|
|
: $is_solid
|
2013-07-15 10:14:22 +00:00
|
|
|
? (($surface->surface_type == S_TYPE_TOP) ? EXTR_ROLE_TOPSOLIDFILL : EXTR_ROLE_SOLIDFILL)
|
2013-03-16 23:42:53 +00:00
|
|
|
: EXTR_ROLE_FILL),
|
2013-03-17 00:10:40 +00:00
|
|
|
height => $surface->thickness,
|
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
|
2013-02-27 09:44:42 +00:00
|
|
|
push @fills, @{$layerm->thin_fills};
|
|
|
|
push @fills_ordering_points, map $_->unpack->points->[0], @{$layerm->thin_fills};
|
2012-06-30 14:33:01 +00:00
|
|
|
|
2013-02-06 11:03:53 +00:00
|
|
|
# organize infill paths using a nearest-neighbor search
|
|
|
|
@fills = @fills[ chained_path(\@fills_ordering_points) ];
|
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;
|