New --first-layer-height-ratio option. #36

This commit is contained in:
Alessandro Ranellucci 2011-11-13 19:08:19 +01:00
parent 097b8d9acb
commit 75a71a23a5
6 changed files with 36 additions and 5 deletions

View File

@ -116,6 +116,9 @@ The author is Alessandro Ranellucci (me).
Accuracy options: Accuracy options:
--layer-height Layer height in mm (default: 0.4) --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)
--infill-every-layers --infill-every-layers
Infill every N layers (default: 1) Infill every N layers (default: 1)

View File

@ -53,6 +53,7 @@ our $bottom_layer_speed_ratio = 0.3;
# accuracy options # accuracy options
our $resolution = 0.00000001; our $resolution = 0.00000001;
our $layer_height = 0.4; our $layer_height = 0.4;
our $first_layer_height_ratio = 1;
our $infill_every_layers = 1; our $infill_every_layers = 1;
our $thickness_ratio = 1; our $thickness_ratio = 1;
our $flow_width; our $flow_width;

View File

@ -68,6 +68,10 @@ our $Options = {
label => 'Layer height (mm)', label => 'Layer height (mm)',
type => 'f', type => 'f',
}, },
'first_layer_height_ratio' => {
label => 'First layer height ratio',
type => 'f',
},
'infill_every_layers' => { 'infill_every_layers' => {
label => 'Infill every N layers', label => 'Infill every N layers',
type => 'i', type => 'i',
@ -249,6 +253,10 @@ sub validate {
die "--layer-height must be a multiple of print resolution\n" die "--layer-height must be a multiple of print resolution\n"
if $Slic3r::layer_height / $Slic3r::resolution % 1 != 0; if $Slic3r::layer_height / $Slic3r::resolution % 1 != 0;
# --first-layer-height-ratio
die "Invalid value for --first-layer-height-ratio\n"
if $Slic3r::first_layer_height_ratio < 0;
# --filament-diameter # --filament-diameter
die "Invalid value for --filament-diameter\n" die "Invalid value for --filament-diameter\n"
if $Slic3r::filament_diameter < 1; if $Slic3r::filament_diameter < 1;
@ -258,6 +266,8 @@ sub validate {
if $Slic3r::nozzle_diameter < 0; if $Slic3r::nozzle_diameter < 0;
die "--layer-height can't be greater than --nozzle-diameter\n" die "--layer-height can't be greater than --nozzle-diameter\n"
if $Slic3r::layer_height > $Slic3r::nozzle_diameter; 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;
$Slic3r::flow_width = ($Slic3r::nozzle_diameter**2) $Slic3r::flow_width = ($Slic3r::nozzle_diameter**2)
* $Slic3r::thickness_ratio * PI / (4 * $Slic3r::layer_height); * $Slic3r::thickness_ratio * PI / (4 * $Slic3r::layer_height);

View File

@ -75,13 +75,19 @@ has 'fills' => (
# Z used for slicing # Z used for slicing
sub slice_z { sub slice_z {
my $self = shift; my $self = shift;
return ($self->id * $Slic3r::layer_height + $Slic3r::layer_height/2) / $Slic3r::resolution; if ($self->id == 0) {
return ($Slic3r::layer_height * $Slic3r::first_layer_height_ratio) / 2 / $Slic3r::resolution;
}
return (($Slic3r::layer_height * $Slic3r::first_layer_height_ratio)
+ (($self->id-1) * $Slic3r::layer_height)
+ ($Slic3r::layer_height/2)) / $Slic3r::resolution;
} }
# Z used for printing # Z used for printing
sub print_z { sub print_z {
my $self = shift; my $self = shift;
return ($self->id + 1) * $Slic3r::layer_height / $Slic3r::resolution; return (($Slic3r::layer_height * $Slic3r::first_layer_height_ratio)
+ ($self->id * $Slic3r::layer_height)) / $Slic3r::resolution;
} }
sub add_surface { sub add_surface {

View File

@ -87,6 +87,10 @@ sub parse_file {
} }
} }
# remove last layer if empty
# (we might have created it because of the $max_layer = ... + 1 code below)
pop @{$print->layers} if !@{$print->layers->[-1]->surfaces} && !@{$print->layers->[-1]->lines};
return $print; return $print;
} }
@ -110,8 +114,11 @@ sub _facet {
} }
# calculate the layer extents # calculate the layer extents
my $min_layer = int($min_z * $Slic3r::resolution / $Slic3r::layer_height); # (the -1 and +1 here are used as a quick and dirty replacement for some
my $max_layer = int($max_z * $Slic3r::resolution / $Slic3r::layer_height); # complex calculation of the first layer height ratio logic)
my $min_layer = int($min_z * $Slic3r::resolution / $Slic3r::layer_height) - 1;
$min_layer = 0 if $min_layer < 0;
my $max_layer = int($max_z * $Slic3r::resolution / $Slic3r::layer_height) + 1;
Slic3r::debugf "layers: min = %s, max = %s\n", $min_layer, $max_layer; Slic3r::debugf "layers: min = %s, max = %s\n", $min_layer, $max_layer;
# reorder vertices so that the first one is the one with lowest Z # reorder vertices so that the first one is the one with lowest Z
@ -131,7 +138,7 @@ sub _facet {
sub intersect_facet { sub intersect_facet {
my $self = shift; my $self = shift;
my ($vertices, $z) = @_; my ($vertices, $z) = @_;
printf "Slicing at $z\n";
# build the three segments of the triangle facet # build the three segments of the triangle facet
my @edges = ( my @edges = (
[ $vertices->[0], $vertices->[1] ], [ $vertices->[0], $vertices->[1] ],

View File

@ -43,6 +43,7 @@ GetOptions(
# accuracy options # accuracy options
'layer-height=f' => \$Slic3r::layer_height, 'layer-height=f' => \$Slic3r::layer_height,
'first-layer-height-ratio=f' => \$Slic3r::first_layer_height_ratio,
'infill-every-layers=i' => \$Slic3r::infill_every_layers, 'infill-every-layers=i' => \$Slic3r::infill_every_layers,
# print options # print options
@ -155,6 +156,9 @@ Usage: slic3r.pl [ OPTIONS ] file.stl
Accuracy options: Accuracy options:
--layer-height Layer height in mm (default: $Slic3r::layer_height) --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)
--infill-every-layers --infill-every-layers
Infill every N layers (default: $Slic3r::infill_every_layers) Infill every N layers (default: $Slic3r::infill_every_layers)