2011-09-01 19:06:28 +00:00
|
|
|
package Slic3r::Layer;
|
2011-09-06 09:50:43 +00:00
|
|
|
use Moo;
|
2011-09-01 19:06:28 +00:00
|
|
|
|
2012-09-22 17:04:36 +00:00
|
|
|
use Slic3r::Geometry::Clipper qw(union_ex);
|
2011-09-01 19:06:28 +00:00
|
|
|
|
2012-09-22 17:04:36 +00:00
|
|
|
has 'id' => (is => 'rw', required => 1); # sequential number of layer, 0-based
|
|
|
|
has 'materials' => (is => 'ro', default => sub { [] });
|
|
|
|
has 'slicing_errors' => (is => 'rw');
|
2011-09-01 19:06:28 +00:00
|
|
|
|
2012-09-22 17:04:36 +00:00
|
|
|
has 'slice_z' => (is => 'lazy');
|
|
|
|
has 'print_z' => (is => 'lazy');
|
|
|
|
has 'height' => (is => 'lazy');
|
|
|
|
has 'flow' => (is => 'lazy');
|
|
|
|
has 'perimeter_flow' => (is => 'lazy');
|
|
|
|
has 'infill_flow' => (is => 'lazy');
|
2011-11-30 15:28:09 +00:00
|
|
|
|
2012-09-22 17:04:36 +00:00
|
|
|
# collection of surfaces generated by slicing the original geometry;
|
|
|
|
# also known as 'islands' (all materials are merged here)
|
|
|
|
has 'slices' => (is => 'rw');
|
2011-09-04 10:04:01 +00:00
|
|
|
|
2012-02-19 11:03:36 +00:00
|
|
|
# ordered collection of extrusion paths to fill surfaces for support material
|
2012-09-22 17:04:36 +00:00
|
|
|
has 'support_fills' => (is => 'rw');
|
2011-09-05 10:21:27 +00:00
|
|
|
|
2011-11-07 15:04:27 +00:00
|
|
|
# Z used for slicing
|
2012-06-06 14:11:38 +00:00
|
|
|
sub _build_slice_z {
|
2011-09-01 19:06:28 +00:00
|
|
|
my $self = shift;
|
2012-06-06 14:11:38 +00:00
|
|
|
|
2011-11-13 18:08:19 +00:00
|
|
|
if ($self->id == 0) {
|
2012-07-27 19:13:03 +00:00
|
|
|
return $Slic3r::Config->get_value('first_layer_height') / 2 / &Slic3r::SCALING_FACTOR;
|
2011-11-13 18:08:19 +00:00
|
|
|
}
|
2012-07-27 19:13:03 +00:00
|
|
|
return ($Slic3r::Config->get_value('first_layer_height') + (($self->id-1) * $Slic3r::Config->layer_height) + ($Slic3r::Config->layer_height/2))
|
|
|
|
/ &Slic3r::SCALING_FACTOR; #/
|
2011-09-01 19:06:28 +00:00
|
|
|
}
|
|
|
|
|
2011-11-07 15:04:27 +00:00
|
|
|
# Z used for printing
|
2012-06-06 14:11:38 +00:00
|
|
|
sub _build_print_z {
|
2011-11-07 15:04:27 +00:00
|
|
|
my $self = shift;
|
2012-07-27 19:13:03 +00:00
|
|
|
return ($Slic3r::Config->get_value('first_layer_height') + ($self->id * $Slic3r::Config->layer_height)) / &Slic3r::SCALING_FACTOR;
|
2011-11-07 15:04:27 +00:00
|
|
|
}
|
|
|
|
|
2012-06-06 14:11:38 +00:00
|
|
|
sub _build_height {
|
2012-01-30 13:03:12 +00:00
|
|
|
my $self = shift;
|
2012-07-27 19:13:03 +00:00
|
|
|
return $self->id == 0 ? $Slic3r::Config->get_value('first_layer_height') : $Slic3r::Config->layer_height;
|
2012-01-30 13:03:12 +00:00
|
|
|
}
|
|
|
|
|
2012-06-06 16:05:03 +00:00
|
|
|
sub _build_flow {
|
2012-06-06 15:29:12 +00:00
|
|
|
my $self = shift;
|
2012-06-06 16:05:03 +00:00
|
|
|
return $self->id == 0 && $Slic3r::first_layer_flow
|
|
|
|
? $Slic3r::first_layer_flow
|
|
|
|
: $Slic3r::flow;
|
2012-06-06 15:29:12 +00:00
|
|
|
}
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
sub _build_perimeter_flow {
|
2012-06-06 15:29:12 +00:00
|
|
|
my $self = shift;
|
2012-06-06 16:05:03 +00:00
|
|
|
return $self->id == 0 && $Slic3r::first_layer_flow
|
|
|
|
? $Slic3r::first_layer_flow
|
2012-07-27 19:13:03 +00:00
|
|
|
: $Slic3r::perimeter_flow;
|
2012-06-06 16:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub _build_infill_flow {
|
|
|
|
my $self = shift;
|
|
|
|
return $self->id == 0 && $Slic3r::first_layer_flow
|
|
|
|
? $Slic3r::first_layer_flow
|
|
|
|
: $Slic3r::infill_flow;
|
2012-06-06 15:29:12 +00:00
|
|
|
}
|
|
|
|
|
2012-09-22 17:04:36 +00:00
|
|
|
sub material {
|
2012-04-29 10:51:20 +00:00
|
|
|
my $self = shift;
|
2012-09-22 17:04:36 +00:00
|
|
|
my ($material_idx) = @_;
|
2012-04-29 10:51:20 +00:00
|
|
|
|
2012-09-22 17:04:36 +00:00
|
|
|
for my $i (grep !defined $self->materials->[$_], 0..$material_idx) {
|
|
|
|
$self->materials->[$i] = Slic3r::Layer::Material->new(
|
|
|
|
layer => $self,
|
2012-07-20 13:02:25 +00:00
|
|
|
);
|
2012-04-29 10:51:20 +00:00
|
|
|
}
|
2012-09-22 17:04:36 +00:00
|
|
|
return $self->materials->[$material_idx];
|
2012-04-29 10:51:20 +00:00
|
|
|
}
|
|
|
|
|
2012-09-22 17:04:36 +00:00
|
|
|
# merge all materials' slices to get islands
|
|
|
|
sub make_slices {
|
2011-11-30 19:32:28 +00:00
|
|
|
my $self = shift;
|
|
|
|
|
2012-09-22 17:04:36 +00:00
|
|
|
# optimization for single-material layers
|
|
|
|
my @materials_with_slices = grep { @{$_->slices} } @{$self->materials};
|
|
|
|
if (@materials_with_slices == 1) {
|
|
|
|
$self->slices($materials_with_slices[0]->slices);
|
|
|
|
return;
|
2011-09-26 09:59:06 +00:00
|
|
|
}
|
2011-10-07 17:07:57 +00:00
|
|
|
|
2012-09-22 17:04:36 +00:00
|
|
|
$self->slices(union_ex([ map @{$_->slices}, @{$self->materials} ]));
|
2011-10-07 17:07:57 +00:00
|
|
|
}
|
|
|
|
|
2012-09-22 17:04:36 +00:00
|
|
|
sub make_perimeters {
|
2011-10-07 17:07:57 +00:00
|
|
|
my $self = shift;
|
2012-09-22 17:04:36 +00:00
|
|
|
Slic3r::debugf "Making perimeters for layer %d\n", $self->id;
|
|
|
|
$_->make_perimeters for @{$self->materials};
|
2011-10-07 17:07:57 +00:00
|
|
|
}
|
|
|
|
|
2011-09-01 19:06:28 +00:00
|
|
|
1;
|