PrusaSlicer-NonPlainar/lib/Slic3r/Layer.pm

79 lines
2.5 KiB
Perl
Raw Normal View History

2011-09-01 19:06:28 +00:00
package Slic3r::Layer;
use Moo;
2011-09-01 19:06:28 +00:00
use Slic3r::Geometry::Clipper qw(union_ex);
2011-09-01 19:06:28 +00:00
has 'id' => (is => 'rw', required => 1); # sequential number of layer, 0-based
has 'object' => (is => 'ro', weak_ref => 1, required => 1);
2012-09-23 00:52:31 +00:00
has 'regions' => (is => 'ro', default => sub { [] });
has 'slicing_errors' => (is => 'rw');
2011-09-01 19:06:28 +00:00
has 'slice_z' => (is => 'lazy');
has 'print_z' => (is => 'lazy');
has 'height' => (is => 'lazy');
has 'flow' => (is => 'ro', default => sub { $Slic3r::flow });
# collection of expolygons generated by slicing the original geometry;
2012-09-23 00:52:31 +00:00
# also known as 'islands' (all regions are merged here)
has 'slices' => (is => 'rw');
2012-02-19 11:03:36 +00:00
# ordered collection of extrusion paths to fill surfaces for support material
has 'support_fills' => (is => 'rw');
2011-09-05 10:21:27 +00:00
# Z used for slicing
sub _build_slice_z {
2011-09-01 19:06:28 +00:00
my $self = shift;
if ($self->id == 0) {
return $Slic3r::Config->get_value('first_layer_height') / 2 / &Slic3r::SCALING_FACTOR;
}
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
}
# Z used for printing
sub _build_print_z {
my $self = shift;
return ($Slic3r::Config->get_value('first_layer_height') + ($self->id * $Slic3r::Config->layer_height)) / &Slic3r::SCALING_FACTOR;
}
sub _build_height {
my $self = shift;
return $self->id == 0 ? $Slic3r::Config->get_value('first_layer_height') : $Slic3r::Config->layer_height;
}
2012-09-23 00:52:31 +00:00
sub region {
my $self = shift;
2012-09-23 00:52:31 +00:00
my ($region_id) = @_;
2012-09-23 00:52:31 +00:00
if (!defined $self->regions->[$region_id]) {
$self->regions->[$region_id] = Slic3r::Layer::Region->new(
layer => $self,
region => $self->object->print->regions->[$region_id],
);
}
2012-09-23 00:52:31 +00:00
return $self->regions->[$region_id];
}
2012-09-23 00:52:31 +00:00
# merge all regions' slices to get islands
sub make_slices {
my $self = shift;
2012-09-23 00:52:31 +00:00
# optimization for single-region layers
my @regions_with_slices = grep { @{$_->slices} } @{$self->regions};
if (@regions_with_slices == 1) {
$self->slices([ map $_->expolygon, @{$regions_with_slices[0]->slices} ]);
return;
}
2012-09-23 00:52:31 +00:00
$self->slices(union_ex([ map $_->p, map @{$_->slices}, @{$self->regions} ]));
}
sub make_perimeters {
my $self = shift;
Slic3r::debugf "Making perimeters for layer %d\n", $self->id;
2012-09-23 00:52:31 +00:00
$_->make_perimeters for @{$self->regions};
}
2011-09-01 19:06:28 +00:00
1;