diff --git a/README.markdown b/README.markdown index a7b6b13cd..9041b8823 100644 --- a/README.markdown +++ b/README.markdown @@ -136,9 +136,7 @@ The author is Alessandro Ranellucci. Accuracy options: --layer-height Layer height in mm (default: 0.4) - --first-layer-height-ratio - Multiplication factor for the height to slice and print the first - layer with (> 0, default: 1) + --first-layer-height Layer height for first layer (mm or %, default: 100%) --infill-every-layers Infill every N layers (default: 1) diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index 4cb84906c..efe5fd3ae 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -95,7 +95,8 @@ our $scaling_factor = 0.000001; our $resolution = 0.01; our $small_perimeter_length = (6.5 / $scaling_factor)*2*PI; our $layer_height = 0.4; -our $first_layer_height_ratio = 1; +our $first_layer_height = '100%'; # mm or % +our $_first_layer_height = undef; # mm (computed) our $infill_every_layers = 1; # flow options diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 8b51f7dea..de3f9fce6 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -186,9 +186,9 @@ our $Options = { cli => 'layer-height=f', type => 'f', }, - 'first_layer_height_ratio' => { - label => 'First layer height ratio', - cli => 'first-layer-height-ratio=f', + 'first_layer_height' => { + label => 'First layer height (mm or %)', + cli => 'first-layer-height=f', type => 'f', }, 'infill_every_layers' => { @@ -520,7 +520,7 @@ sub load { # handle legacy options next if $ignore{$key}; - if ($key =~ /^(?:extrusion_width|bottom_layer_speed)_ratio$/) { + if ($key =~ /^(?:extrusion_width|bottom_layer_speed|first_layer_height)_ratio$/) { $key = $1; $key =~ s/^bottom_layer_speed$/first_layer_speed/; $val = $val =~ /^\d+(\.\d+)?$/ ? ($val*100) . "%" : 0; @@ -571,9 +571,12 @@ sub validate { die "--layer-height must be a multiple of print resolution\n" if $Slic3r::layer_height / $Slic3r::scaling_factor % 1 != 0; - # --first-layer-height-ratio - die "Invalid value for --first-layer-height-ratio\n" - if $Slic3r::first_layer_height_ratio < 0; + # --first-layer-height + die "Invalid value for --first-layer-height\n" + if $Slic3r::first_layer_height !~ /^(?:\d+(?:\.\d+)?)%?$/; + $Slic3r::_first_layer_height = $Slic3r::first_layer_height =~ /^(\d+(?:\.\d+)?)%$/ + ? ($Slic3r::layer_height * $1/100) + : $Slic3r::first_layer_height; # --filament-diameter die "Invalid value for --filament-diameter\n" @@ -585,9 +588,7 @@ sub validate { die "--layer-height can't be greater than --nozzle-diameter\n" if $Slic3r::layer_height > $Slic3r::nozzle_diameter; die "First layer height can't be greater than --nozzle-diameter\n" - if ($Slic3r::layer_height * $Slic3r::first_layer_height_ratio) > $Slic3r::nozzle_diameter; - die "First layer height can't be zero or negative\n" - if ($Slic3r::layer_height * $Slic3r::first_layer_height_ratio) <= 0; + if $Slic3r::_first_layer_height > $Slic3r::nozzle_diameter; if ($Slic3r::extrusion_width) { $Slic3r::flow_width = $Slic3r::extrusion_width =~ /^(\d+(?:\.\d+)?)%$/ diff --git a/lib/Slic3r/GUI/SkeinPanel.pm b/lib/Slic3r/GUI/SkeinPanel.pm index 6ea6f6dd6..b61c40804 100644 --- a/lib/Slic3r/GUI/SkeinPanel.pm +++ b/lib/Slic3r/GUI/SkeinPanel.pm @@ -40,7 +40,7 @@ sub new { }, accuracy => { title => 'Accuracy', - options => [qw(layer_height first_layer_height_ratio infill_every_layers)], + options => [qw(layer_height first_layer_height infill_every_layers)], }, print => { title => 'Print settings', diff --git a/lib/Slic3r/Layer.pm b/lib/Slic3r/Layer.pm index e886e49a6..a85a68c17 100644 --- a/lib/Slic3r/Layer.pm +++ b/lib/Slic3r/Layer.pm @@ -16,6 +16,10 @@ has 'id' => ( has 'slicing_errors' => (is => 'rw'); +has 'slice_z' => (is => 'lazy'); +has 'print_z' => (is => 'lazy'); +has 'height' => (is => 'lazy'); + # collection of spare segments generated by slicing the original geometry; # these need to be merged in continuos (closed) polylines has 'lines' => ( @@ -74,28 +78,25 @@ has 'fills' => ( ); # Z used for slicing -sub slice_z { +sub _build_slice_z { my $self = shift; + if ($self->id == 0) { - return ($Slic3r::layer_height * $Slic3r::first_layer_height_ratio) / 2 / $Slic3r::scaling_factor; + return $Slic3r::_first_layer_height / 2 / $Slic3r::scaling_factor; } - return (($Slic3r::layer_height * $Slic3r::first_layer_height_ratio) - + (($self->id-1) * $Slic3r::layer_height) - + ($Slic3r::layer_height/2)) / $Slic3r::scaling_factor; + return ($Slic3r::_first_layer_height + (($self->id-1) * $Slic3r::layer_height) + ($Slic3r::layer_height/2)) + / $Slic3r::scaling_factor; #/ } # Z used for printing -sub print_z { +sub _build_print_z { my $self = shift; - return (($Slic3r::layer_height * $Slic3r::first_layer_height_ratio) - + ($self->id * $Slic3r::layer_height)) / $Slic3r::scaling_factor; + return ($Slic3r::_first_layer_height + ($self->id * $Slic3r::layer_height)) / $Slic3r::scaling_factor; } -sub height { +sub _build_height { my $self = shift; - return $self->id == 0 - ? ($Slic3r::layer_height * $Slic3r::first_layer_height_ratio) - : $Slic3r::layer_height; + return $self->id == 0 ? $Slic3r::_first_layer_height : $Slic3r::layer_height; } sub add_line { diff --git a/lib/Slic3r/TriangleMesh.pm b/lib/Slic3r/TriangleMesh.pm index 795c4ec4a..5def6e342 100644 --- a/lib/Slic3r/TriangleMesh.pm +++ b/lib/Slic3r/TriangleMesh.pm @@ -390,10 +390,9 @@ sub slice_facet { } # calculate the layer extents - my $first_layer_height = $Slic3r::layer_height * $Slic3r::first_layer_height_ratio; - my $min_layer = int((unscale($min_z) - ($first_layer_height + $Slic3r::layer_height / 2)) / $Slic3r::layer_height) - 2; + my $min_layer = int((unscale($min_z) - ($Slic3r::_first_layer_height + $Slic3r::layer_height / 2)) / $Slic3r::layer_height) - 2; $min_layer = 0 if $min_layer < 0; - my $max_layer = int((unscale($max_z) - ($first_layer_height + $Slic3r::layer_height / 2)) / $Slic3r::layer_height) + 2; + my $max_layer = int((unscale($max_z) - ($Slic3r::_first_layer_height + $Slic3r::layer_height / 2)) / $Slic3r::layer_height) + 2; Slic3r::debugf "layers: min = %s, max = %s\n", $min_layer, $max_layer; my $lines = {}; # layer_id => [ lines ] diff --git a/slic3r.pl b/slic3r.pl index 8dcd9a983..607b4ba20 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -180,9 +180,7 @@ $j Accuracy options: --layer-height Layer height in mm (default: $Slic3r::layer_height) - --first-layer-height-ratio - Multiplication factor for the height to slice and print the first - layer with (> 0, default: $Slic3r::first_layer_height_ratio) + --first-layer-height Layer height for first layer (mm or %, default: $Slic3r::first_layer_height) --infill-every-layers Infill every N layers (default: $Slic3r::infill_every_layers)