Accept either absolute or relative values for --first-layer-height. #151

This commit is contained in:
Alessandro Ranellucci 2012-06-06 16:11:38 +02:00
parent 896c7e952e
commit 16b774603c
7 changed files with 31 additions and 33 deletions

View File

@ -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)

View File

@ -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

View File

@ -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+)?)%$/

View File

@ -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',

View File

@ -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 {

View File

@ -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 ]

View File

@ -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)