From 2275de9f0dd8a58ff60d4b2794a83c8083a42ff8 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 10 Mar 2013 11:37:16 +0100 Subject: [PATCH] Factored out the layer height logic --- lib/Slic3r/Layer.pm | 34 +++------------------------------- lib/Slic3r/Print/Object.pm | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/lib/Slic3r/Layer.pm b/lib/Slic3r/Layer.pm index 951805c8a..074baef55 100644 --- a/lib/Slic3r/Layer.pm +++ b/lib/Slic3r/Layer.pm @@ -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; diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index c77fd228f..094dd026a 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -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, ); } }