Factored out the layer height logic

This commit is contained in:
Alessandro Ranellucci 2013-03-10 11:37:16 +01:00
parent 06a592f25e
commit 2275de9f0d
2 changed files with 24 additions and 32 deletions

View File

@ -10,9 +10,9 @@ has 'object' => (is => 'ro', weak_ref => 1, required => 1);
has 'regions' => (is => 'ro', default => sub { [] });
has 'slicing_errors' => (is => 'rw');
has 'slice_z' => (is => 'lazy');
has 'print_z' => (is => 'lazy');
has 'height' => (is => 'lazy');
has 'slice_z' => (is => 'ro', required => 1); # Z used for slicing in scaled coordinates
has 'print_z' => (is => 'ro', required => 1); # Z used for printing in scaled coordinates
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 are merged here)
@ -28,34 +28,6 @@ sub _trigger_id {
$_->_trigger_layer for @{$self->regions || []};
}
# Z used for slicing in scaled coordinates
sub _build_slice_z {
my $self = shift;
if ($Slic3r::Config->raft_layers == 0) {
if ($self->id == 0) {
return scale $Slic3r::Config->get_value('first_layer_height') / 2;
}
return scale($Slic3r::Config->get_value('first_layer_height') + ($self->id-1 + 0.5) * $Slic3r::Config->layer_height);
} else {
return -1 if $self->id < $Slic3r::Config->raft_layers;
my $object_layer_id = $self->id - $Slic3r::Config->raft_layers;
return scale ($object_layer_id + 0.5) * $Slic3r::Config->layer_height;
}
}
# Z used for printing in scaled coordinates
sub _build_print_z {
my $self = shift;
return ($Slic3r::Config->get_value('first_layer_height') + ($self->id * $Slic3r::Config->layer_height)) / &Slic3r::SCALING_FACTOR;
}
# layer height in unscaled coordinates
sub _build_height {
my $self = shift;
return $self->id == 0 ? $Slic3r::Config->get_value('first_layer_height') : $Slic3r::Config->layer_height;
}
# layer height of contact paths in unscaled coordinates
sub support_material_contact_height {
my $self = shift;

View File

@ -18,10 +18,30 @@ sub BUILD {
my $self = shift;
# make layers
my $print_z = my $slice_z = my $raft_z = 0;
while (!@{$self->layers} || $self->layers->[-1]->slice_z < $self->size->[Z]) {
my $id = $#{$self->layers} + 1;
my $height = $id == 0
? $Slic3r::Config->get_value('first_layer_height')
: $Slic3r::Config->layer_height;
$print_z += $height;
if ($id < $Slic3r::Config->raft_layers) {
# this is a raft layer
$raft_z += $height;
$slice_z = -1;
} else {
$slice_z = $print_z - ($height/2) - $raft_z;
}
### Slic3r::debugf "Layer %d: height = %s; slice_z = %s; print_z = %s\n", $id, $height, $slice_z, $print_z;
push @{$self->layers}, Slic3r::Layer->new(
object => $self,
id => $#{$self->layers} + 1,
id => $id,
height => $height,
print_z => scale $print_z,
slice_z => scale $slice_z,
);
}
}