PrusaSlicer-NonPlainar/lib/Slic3r/Layer.pm

76 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 List::Util qw(first);
use Slic3r::Geometry qw(scale chained_path);
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, handles => [qw(print config)]);
has 'upper_layer' => (is => 'rw', weak_ref => 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
2013-11-23 18:25:33 +00:00
has 'slice_z' => (is => 'ro', required => 1); # Z used for slicing in unscaled coordinates
2013-07-28 22:27:53 +00:00
has 'print_z' => (is => 'ro', required => 1); # Z used for printing in unscaled coordinates
2013-03-10 10:37:16 +00:00
has 'height' => (is => 'ro', required => 1); # layer height in unscaled coordinates
# collection of expolygons generated by slicing the original geometry;
# also known as 'islands' (all regions and surface types are merged here)
has 'slices' => (is => 'rw', default => sub { Slic3r::ExPolygon::Collection->new });
# the purpose of this method is to be overridden for ::Support layers
sub islands {
my $self = shift;
return $self->slices;
2013-06-03 10:29:45 +00:00
}
2012-09-23 00:52:31 +00:00
sub region {
my $self = shift;
2012-09-23 00:52:31 +00:00
my ($region_id) = @_;
for (my $i = @{$self->regions}; $i <= $region_id; $i++) {
$self->regions->[$i] //= Slic3r::Layer::Region->new(
2012-09-23 00:52:31 +00:00
layer => $self,
region => $self->object->print->regions->[$i],
);
}
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;
my $slices = union_ex([ map $_->p, map @{$_->slices}, @{$self->regions} ]);
# sort slices
$slices = [ @$slices[@{chained_path([ map $_->contour->first_point, @$slices ])}] ];
$self->slices->clear;
$self->slices->append(@$slices);
}
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};
}
2013-07-29 18:49:54 +00:00
package Slic3r::Layer::Support;
use Moo;
extends 'Slic3r::Layer';
# ordered collection of extrusion paths to fill surfaces for support material
has 'support_islands' => (is => 'rw', default => sub { Slic3r::ExPolygon::Collection->new });
has 'support_fills' => (is => 'rw', default => sub { Slic3r::ExtrusionPath::Collection->new });
has 'support_interface_fills' => (is => 'rw', default => sub { Slic3r::ExtrusionPath::Collection->new });
2013-07-29 18:49:54 +00:00
sub islands {
my $self = shift;
return [ @{$self->slices}, @{$self->support_islands} ];
}
2011-09-01 19:06:28 +00:00
1;