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;
|
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;
|
2011-10-06 13:24:21 +00:00
|
|
|
use Slic3r::Fill::Rectilinear2;
|
2011-11-13 20:46:32 +00:00
|
|
|
use Slic3r::Geometry qw(shortest_path);
|
2011-11-23 11:29:27 +00:00
|
|
|
use Slic3r::Geometry::Clipper qw(union_ex diff_ex);
|
2011-09-05 10:21:27 +00:00
|
|
|
|
2011-10-07 17:07:57 +00:00
|
|
|
use XXX;
|
|
|
|
|
2011-10-06 11:43:32 +00:00
|
|
|
has 'print' => (is => 'ro', required => 1);
|
|
|
|
has 'fillers' => (is => 'rw', default => sub { {} });
|
|
|
|
|
|
|
|
our %FillTypes = (
|
2011-11-13 17:14:02 +00:00
|
|
|
archimedeanchords => 'Slic3r::Fill::ArchimedeanChords',
|
|
|
|
rectilinear => 'Slic3r::Fill::Rectilinear',
|
|
|
|
rectilinear2 => 'Slic3r::Fill::Rectilinear2',
|
|
|
|
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',
|
2011-10-06 11:43:32 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
sub BUILD {
|
|
|
|
my $self = shift;
|
|
|
|
$self->fillers->{$_} ||= $FillTypes{$_}->new(print => $self->print)
|
2011-11-13 17:14:02 +00:00
|
|
|
for ('rectilinear', $Slic3r::fill_pattern, $Slic3r::solid_fill_pattern);
|
2011-10-06 11:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub make_fill {
|
|
|
|
my $self = shift;
|
|
|
|
my ($layer) = @_;
|
|
|
|
|
|
|
|
my $max_print_dimension = $self->print->max_length * sqrt(2);
|
|
|
|
for (values %{$self->fillers}) {
|
|
|
|
$_->layer($layer);
|
|
|
|
$_->max_print_dimension($max_print_dimension);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf "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};
|
|
|
|
foreach my $group (Slic3r::Surface->group({merge_solid => 1}, @{$layer->fill_surfaces})) {
|
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-11-23 11:29:27 +00:00
|
|
|
push @surfaces, map Slic3r::Surface->cast_from_expolygon($_,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# organize infill surfaces using a shortest path search
|
|
|
|
@surfaces = @{shortest_path([
|
|
|
|
map [ $_->contour->points->[0], $_ ], @surfaces,
|
|
|
|
])};
|
|
|
|
|
|
|
|
SURFACE: foreach my $surface (@surfaces) {
|
2011-12-07 18:33:59 +00:00
|
|
|
my $filler = $Slic3r::fill_pattern;
|
|
|
|
my $density = $Slic3r::fill_density;
|
2011-12-13 16:34:31 +00:00
|
|
|
my $flow_width = $Slic3r::flow_width;
|
2011-12-07 18:33:59 +00:00
|
|
|
my $is_bridge = $layer->id > 0 && $surface->surface_type eq 'bottom';
|
|
|
|
my $is_solid = $surface->surface_type =~ /^(top|bottom)$/;
|
2011-11-23 11:29:27 +00:00
|
|
|
|
|
|
|
# force 100% density and rectilinear fill for external surfaces
|
2011-11-30 19:32:28 +00:00
|
|
|
if ($surface->surface_type ne 'internal') {
|
2011-11-23 11:29:27 +00:00
|
|
|
$density = 1;
|
2011-12-04 19:29:21 +00:00
|
|
|
$filler = $Slic3r::solid_fill_pattern;
|
|
|
|
if ($is_bridge) {
|
|
|
|
$filler = 'rectilinear';
|
2011-12-13 16:34:31 +00:00
|
|
|
$flow_width = sqrt($Slic3r::bridge_flow_ratio * ($Slic3r::nozzle_diameter**2));
|
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-13 16:34:31 +00:00
|
|
|
flow_width => $flow_width,
|
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
|
|
|
|
push @{ $layer->fills }, Slic3r::ExtrusionPath::Collection->new(
|
|
|
|
paths => [
|
|
|
|
map Slic3r::ExtrusionPath->cast(
|
|
|
|
[ @$_ ],
|
2011-11-28 18:11:26 +00:00
|
|
|
role => ($is_bridge ? 'bridge' : $is_solid ? 'solid-fill' : 'fill'),
|
2011-11-23 11:29:27 +00:00
|
|
|
depth_layers => $surface->depth_layers,
|
2011-12-14 10:35:19 +00:00
|
|
|
flow_width => $params->{flow_width},
|
2011-11-23 11:29:27 +00:00
|
|
|
), @paths,
|
|
|
|
],
|
2011-12-05 18:54:19 +00:00
|
|
|
) if @paths;
|
2011-12-04 15:24:46 +00:00
|
|
|
###$layer->fills->[-1]->cleanup;
|
2011-10-06 11:43:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-05 10:21:27 +00:00
|
|
|
1;
|