mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-05 21:14:01 -06:00
Refactoring: initialize all layers at once and avoid duplication of slicing height math
This commit is contained in:
parent
a1a4d97f9f
commit
08270022dd
3 changed files with 25 additions and 24 deletions
|
@ -2,39 +2,42 @@ package Slic3r::Print::Object;
|
|||
use Moo;
|
||||
|
||||
use Slic3r::ExtrusionPath ':roles';
|
||||
use Slic3r::Geometry qw(scale unscale deg2rad);
|
||||
use Slic3r::Geometry qw(Z scale unscale deg2rad);
|
||||
use Slic3r::Geometry::Clipper qw(diff_ex intersection_ex union_ex);
|
||||
use Slic3r::Surface ':types';
|
||||
|
||||
has 'input_file' => (is => 'rw', required => 0);
|
||||
has 'mesh' => (is => 'rw', required => 0);
|
||||
has 'size' => (is => 'rw', required => 1);
|
||||
has 'layers' => (is => 'rw', default => sub { [] } );
|
||||
|
||||
has 'layers' => (
|
||||
traits => ['Array'],
|
||||
is => 'rw',
|
||||
#isa => 'ArrayRef[Slic3r::Layer]',
|
||||
default => sub { [] },
|
||||
);
|
||||
sub BUILD {
|
||||
my $self = shift;
|
||||
|
||||
# make layers
|
||||
while (!@{$self->layers} || $self->layers->[-1]->slice_z < $self->size->[Z]) {
|
||||
push @{$self->layers}, Slic3r::Layer->new(id => $#{$self->layers} + 1);
|
||||
}
|
||||
}
|
||||
|
||||
sub layer_count {
|
||||
my $self = shift;
|
||||
return scalar @{ $self->layers };
|
||||
}
|
||||
|
||||
sub layer {
|
||||
sub get_layer_range {
|
||||
my $self = shift;
|
||||
my ($layer_id) = @_;
|
||||
my ($min_z, $max_z) = @_;
|
||||
|
||||
# extend our print by creating all necessary layers
|
||||
|
||||
if ($self->layer_count < $layer_id + 1) {
|
||||
for (my $i = $self->layer_count; $i <= $layer_id; $i++) {
|
||||
push @{ $self->layers }, Slic3r::Layer->new(id => $i);
|
||||
my ($min_layer, $max_layer) = (0, undef);
|
||||
for my $layer (@{$self->layers}) {
|
||||
$min_layer = $layer->id if $layer->slice_z <= $min_z;
|
||||
if ($layer->slice_z >= $max_z) {
|
||||
$max_layer = $layer->id;
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
return $self->layers->[$layer_id];
|
||||
return ($min_layer, $max_layer);
|
||||
}
|
||||
|
||||
sub slice {
|
||||
|
@ -46,7 +49,7 @@ sub slice {
|
|||
my $apply_lines = sub {
|
||||
my $lines = shift;
|
||||
foreach my $layer_id (keys %$lines) {
|
||||
my $layer = $self->layer($layer_id);
|
||||
my $layer = $self->layers->[$layer_id];
|
||||
push @{$layer->lines}, @{$lines->{$layer_id}};
|
||||
}
|
||||
};
|
||||
|
@ -399,7 +402,7 @@ sub combine_infill {
|
|||
|
||||
# start from bottom, skip first layer
|
||||
for (my $i = 1; $i < $self->layer_count; $i++) {
|
||||
my $layer = $self->layer($i);
|
||||
my $layer = $self->layers->[$i];
|
||||
|
||||
# skip layer if no internal fill surfaces
|
||||
next if !grep $_->surface_type == S_TYPE_INTERNAL, @{$layer->fill_surfaces};
|
||||
|
@ -408,7 +411,7 @@ sub combine_infill {
|
|||
# we do this from the greater depth to the smaller
|
||||
for (my $d = $Slic3r::Config->infill_every_layers - 1; $d >= 1; $d--) {
|
||||
next if ($i - $d) < 0;
|
||||
my $lower_layer = $self->layer($i - 1);
|
||||
my $lower_layer = $self->layers->[$i - 1];
|
||||
|
||||
# select surfaces of the lower layer having the depth we're looking for
|
||||
my @lower_surfaces = grep $_->depth_layers == $d && $_->surface_type == S_TYPE_INTERNAL,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue