From d9a70ea80d5fef79240eae8b24f714656dafe97f Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 7 Dec 2011 19:33:59 +0100 Subject: [PATCH] Customizable overlap ratio (it defaults to 0.15 now) --- README.markdown | 12 ++++++++---- lib/Slic3r.pm | 7 +++++-- lib/Slic3r/Config.pm | 25 +++++++++++++++++-------- lib/Slic3r/Extruder.pm | 4 +++- lib/Slic3r/Fill.pm | 19 ++++++++++--------- lib/Slic3r/Fill/Concentric.pm | 7 ++++--- lib/Slic3r/Fill/PlanePath.pm | 4 ++-- lib/Slic3r/Fill/Rectilinear.pm | 2 +- lib/Slic3r/Fill/Rectilinear2.pm | 4 ++-- lib/Slic3r/GUI/SkeinPanel.pm | 2 +- lib/Slic3r/Layer.pm | 2 +- lib/Slic3r/Perimeter.pm | 4 ++-- lib/Slic3r/Polyline/Closed.pm | 3 ++- lib/Slic3r/Print.pm | 2 +- slic3r.pl | 12 ++++++++---- 15 files changed, 67 insertions(+), 42 deletions(-) diff --git a/README.markdown b/README.markdown index f23efc888..da49afc2a 100644 --- a/README.markdown +++ b/README.markdown @@ -125,10 +125,6 @@ The author is Alessandro Ranellucci (me). layer with (> 0, default: 1) --infill-every-layers Infill every N layers (default: 1) - --extrusion-width-ratio - Calculate the extrusion width as the layer height multiplied by - this value (> 0, default: calculated automatically) - --bridge-flow-ratio Multiplier for extrusion when bridging (> 0, default: 1) Print options: --perimeters Number of perimeters/horizontal skins (range: 1+, @@ -168,6 +164,14 @@ The author is Alessandro Ranellucci (me). --duplicate-x Number of items along X axis (1+, default: 1) --duplicate-y Number of items along Y axis (1+, default: 1) --duplicate-distance Distance in mm between copies (default: 6) + + Flow options (advanced): + --extrusion-width-ratio + Calculate the extrusion width as the layer height multiplied by + this value (> 0, default: calculated automatically) + --bridge-flow-ratio Multiplier for extrusion when bridging (> 0, default: 1) + --overlap-ratio Overlap between extrusion threads expressed as a ratio over extrusion + width (> 0, default: 0.15) If you want to change a preset file, just do diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index 321f863e4..1dfea9777 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -18,7 +18,7 @@ use Slic3r::ExtrusionPath; use Slic3r::ExtrusionPath::Arc; use Slic3r::ExtrusionPath::Collection; use Slic3r::Fill; -use Slic3r::Geometry; +use Slic3r::Geometry qw(PI); use Slic3r::Layer; use Slic3r::Line; use Slic3r::Perimeter; @@ -62,15 +62,18 @@ our $small_perimeter_area = (5 / $resolution) ** 2; our $layer_height = 0.4; our $first_layer_height_ratio = 1; our $infill_every_layers = 1; + +# flow options our $extrusion_width_ratio = 0; our $bridge_flow_ratio = 1; our $flow_speed_ratio = 1; our $flow_width; +our $overlap_ratio = 0.15; +our $flow_spacing; # print options our $perimeters = 3; our $solid_layers = 3; -our $perimeter_infill_overlap_ratio = 0.15; # factor for flow width our $fill_pattern = 'rectilinear'; our $solid_fill_pattern = 'rectilinear'; our $fill_density = 0.4; # 1 = 100% diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 38c531a9f..8ae916f07 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -115,6 +115,18 @@ our $Options = { cli => 'layer-height=f', type => 'f', }, + 'first_layer_height_ratio' => { + label => 'First layer height ratio', + cli => 'first-layer-height-ratio=f', + type => 'f', + }, + 'infill_every_layers' => { + label => 'Infill every N layers', + cli => 'infill-every-layers=i', + type => 'i', + }, + + # flow options 'extrusion_width_ratio' => { label => 'Extrusion width (ratio over layer height; leave zero to calculate automatically)', cli => 'extrusion-width-ratio=f', @@ -125,16 +137,11 @@ our $Options = { cli => 'bridge-flow-ratio=f', type => 'f', }, - 'first_layer_height_ratio' => { - label => 'First layer height ratio', - cli => 'first-layer-height-ratio=f', + 'overlap_ratio' => { + label => 'Extrusion overlap (ratio over extrusion width)', + cli => 'overlap-ratio=f', type => 'f', }, - 'infill_every_layers' => { - label => 'Infill every N layers', - cli => 'infill-every-layers=i', - type => 'i', - }, # print options 'perimeters' => { @@ -371,9 +378,11 @@ sub validate { $Slic3r::flow_speed_ratio = $max_flow_width / $Slic3r::flow_width; $Slic3r::flow_width = $max_flow_width; } + $Slic3r::flow_spacing = $Slic3r::flow_width * (1-$Slic3r::overlap_ratio); Slic3r::debugf "Flow width = $Slic3r::flow_width\n"; Slic3r::debugf "Flow speed ratio = $Slic3r::flow_speed_ratio\n"; + Slic3r::debugf "Flow spacing = $Slic3r::flow_spacing\n"; # --perimeters die "Invalid value for --perimeters\n" diff --git a/lib/Slic3r/Extruder.pm b/lib/Slic3r/Extruder.pm index e5e4a561b..50f10f5aa 100644 --- a/lib/Slic3r/Extruder.pm +++ b/lib/Slic3r/Extruder.pm @@ -1,6 +1,8 @@ package Slic3r::Extruder; use Moo; +use Slic3r::Geometry qw(scale); + has 'layer' => (is => 'rw'); has 'shift_x' => (is => 'ro', default => sub {0} ); has 'shift_y' => (is => 'ro', default => sub {0} ); @@ -75,7 +77,7 @@ sub extrude_loop { my $extrusion_path = $loop->split_at($start_at); # clip the path to avoid the extruder to get exactly on the first point of the loop - $extrusion_path->clip_end($Slic3r::flow_width / $Slic3r::resolution); + $extrusion_path->clip_end(scale $Slic3r::flow_spacing); # extrude along the path return $self->extrude($extrusion_path, $description); diff --git a/lib/Slic3r/Fill.pm b/lib/Slic3r/Fill.pm index 57a23e502..545582a7c 100644 --- a/lib/Slic3r/Fill.pm +++ b/lib/Slic3r/Fill.pm @@ -85,12 +85,12 @@ sub make_fill { ])}; SURFACE: foreach my $surface (@surfaces) { - my $filler = $Slic3r::fill_pattern; - my $density = $Slic3r::fill_density; - my $flow_width = $Slic3r::flow_width; - my $flow_ratio = 1; - my $is_bridge = $layer->id > 0 && $surface->surface_type eq 'bottom'; - my $is_solid = $surface->surface_type =~ /^(top|bottom)$/; + my $filler = $Slic3r::fill_pattern; + my $density = $Slic3r::fill_density; + my $flow_spacing = $Slic3r::flow_spacing; + my $flow_ratio = 1; + my $is_bridge = $layer->id > 0 && $surface->surface_type eq 'bottom'; + my $is_solid = $surface->surface_type =~ /^(top|bottom)$/; # force 100% density and rectilinear fill for external surfaces if ($surface->surface_type ne 'internal') { @@ -98,7 +98,8 @@ sub make_fill { $filler = $Slic3r::solid_fill_pattern; if ($is_bridge) { $filler = 'rectilinear'; - $flow_width = sqrt($Slic3r::bridge_flow_ratio * ($Slic3r::nozzle_diameter**2)); + $flow_spacing = sqrt($Slic3r::bridge_flow_ratio * ($Slic3r::nozzle_diameter**2)) + * (1-$Slic3r::overlap_ratio); $flow_ratio = $Slic3r::bridge_flow_ratio; } } else { @@ -107,8 +108,8 @@ sub make_fill { my @paths = $self->fillers->{$filler}->fill_surface( $surface, - density => $density, - flow_width => $flow_width, + density => $density, + flow_spacing => $flow_spacing, ); my $params = shift @paths; diff --git a/lib/Slic3r/Fill/Concentric.pm b/lib/Slic3r/Fill/Concentric.pm index 2c59e17d4..7d1ecd1bd 100644 --- a/lib/Slic3r/Fill/Concentric.pm +++ b/lib/Slic3r/Fill/Concentric.pm @@ -3,6 +3,7 @@ use Moo; extends 'Slic3r::Fill::Base'; +use Slic3r::Geometry qw(scale); use XXX; sub fill_surface { @@ -11,8 +12,8 @@ sub fill_surface { # no rotation is supported for this infill pattern - my $flow_width_res = $params{flow_width} / $Slic3r::resolution; - my $distance = $flow_width_res / $params{density}; + my $scaled_flow_spacing = scale $params{flow_spacing}; + my $distance = $scaled_flow_spacing / $params{density}; my @contour_loops = (); my @hole_loops = (); @@ -43,7 +44,7 @@ sub fill_surface { my $path = $loop->split_at($cur_pos); # clip the path to avoid the extruder to get exactly on the first point of the loop - $path->clip_end($Slic3r::flow_width / $Slic3r::resolution); + $path->clip_end(scale $Slic3r::flow_spacing); push @paths, $path->p; } diff --git a/lib/Slic3r/Fill/PlanePath.pm b/lib/Slic3r/Fill/PlanePath.pm index bbb2a5648..caf92c948 100644 --- a/lib/Slic3r/Fill/PlanePath.pm +++ b/lib/Slic3r/Fill/PlanePath.pm @@ -3,7 +3,7 @@ use Moo; extends 'Slic3r::Fill::Base'; -use Slic3r::Geometry qw(bounding_box X1 Y1 X2 Y2); +use Slic3r::Geometry qw(scale bounding_box X1 Y1 X2 Y2); use XXX; sub multiplier () { 1 } @@ -27,7 +27,7 @@ sub fill_surface { my $rotate_vector = $self->infill_direction($surface); $self->rotate_points($expolygon, $rotate_vector); - my $distance_between_lines = $params{flow_width} / $Slic3r::resolution / $params{density} * $self->multiplier; + my $distance_between_lines = scale $params{flow_spacing} / $params{density} * $self->multiplier; my $bounding_box = [ bounding_box(map @$_, $expolygon) ]; my $bounding_box_polygon = Slic3r::Polygon->new([ [ $bounding_box->[X1], $bounding_box->[Y1] ], diff --git a/lib/Slic3r/Fill/Rectilinear.pm b/lib/Slic3r/Fill/Rectilinear.pm index 639e67be0..313b73c78 100644 --- a/lib/Slic3r/Fill/Rectilinear.pm +++ b/lib/Slic3r/Fill/Rectilinear.pm @@ -19,7 +19,7 @@ sub fill_surface { $bounding_box->[X1] += scale 0.1; $bounding_box->[X2] -= scale 0.1; - my $min_spacing = scale $params{flow_width}; + my $min_spacing = scale $params{flow_spacing}; my $distance_between_lines = $min_spacing / $params{density}; my $line_oscillation = $distance_between_lines - $min_spacing; diff --git a/lib/Slic3r/Fill/Rectilinear2.pm b/lib/Slic3r/Fill/Rectilinear2.pm index 7d741e65e..d8b8f0bb0 100644 --- a/lib/Slic3r/Fill/Rectilinear2.pm +++ b/lib/Slic3r/Fill/Rectilinear2.pm @@ -3,7 +3,7 @@ use Moo; extends 'Slic3r::Fill::Base'; -use Slic3r::Geometry qw(X1 Y1 X2 Y2 A B X Y); +use Slic3r::Geometry qw(scale X1 Y1 X2 Y2 A B X Y); use XXX; sub fill_surface { @@ -16,7 +16,7 @@ sub fill_surface { my $rotate_vector = $self->infill_direction($surface); $self->rotate_points($polygons, $rotate_vector); - my $distance_between_lines = $params{flow_width} / $Slic3r::resolution / $params{density}; + my $distance_between_lines = scale $params{flow_spacing} / $params{density}; my $number_of_lines = int(0.99999999 + $self->max_print_dimension / $distance_between_lines); # ceil #printf "distance = %f\n", $distance_between_lines; diff --git a/lib/Slic3r/GUI/SkeinPanel.pm b/lib/Slic3r/GUI/SkeinPanel.pm index 06e746c26..1f993df17 100644 --- a/lib/Slic3r/GUI/SkeinPanel.pm +++ b/lib/Slic3r/GUI/SkeinPanel.pm @@ -57,7 +57,7 @@ sub new { }, extrusion => { title => 'Extrusion', - options => [qw(extrusion_width_ratio bridge_flow_ratio)], + options => [qw(extrusion_width_ratio bridge_flow_ratio overlap_ratio)], }, ); $self->{panels} = \%panels; diff --git a/lib/Slic3r/Layer.pm b/lib/Slic3r/Layer.pm index 56ede956c..6dcfe94e9 100644 --- a/lib/Slic3r/Layer.pm +++ b/lib/Slic3r/Layer.pm @@ -182,7 +182,7 @@ sub prepare_fill_surfaces { sub remove_small_surfaces { my $self = shift; - my $distance = scale $Slic3r::flow_width / 2; + my $distance = scale $Slic3r::flow_spacing / 2; my @surfaces = @{$self->fill_surfaces}; @{$self->fill_surfaces} = (); diff --git a/lib/Slic3r/Perimeter.pm b/lib/Slic3r/Perimeter.pm index 286be4291..413f205a7 100644 --- a/lib/Slic3r/Perimeter.pm +++ b/lib/Slic3r/Perimeter.pm @@ -45,12 +45,12 @@ sub make_perimeter { push @{ $perimeters[-1] }, [@last_offsets]; # offset distance for inner loops - $distance = $Slic3r::flow_width / $Slic3r::resolution; + $distance = scale $Slic3r::flow_spacing; } # create one more offset to be used as boundary for fill { - $distance -= scale $Slic3r::flow_width * $Slic3r::perimeter_infill_overlap_ratio; + $distance -= scale $Slic3r::flow_spacing; my @fill_boundaries = map Slic3r::Surface->cast_from_expolygon ($_, surface_type => $surface->surface_type), map $_->offset_ex(-$distance), @last_offsets; diff --git a/lib/Slic3r/Polyline/Closed.pm b/lib/Slic3r/Polyline/Closed.pm index c92287821..8d9d54c3a 100644 --- a/lib/Slic3r/Polyline/Closed.pm +++ b/lib/Slic3r/Polyline/Closed.pm @@ -4,6 +4,7 @@ use Moo; extends 'Slic3r::Polyline'; use Math::Clipper qw(JT_MITER); +use Slic3r::Geometry qw(scale); sub lines { my $self = shift; @@ -31,7 +32,7 @@ sub is_printable { # if no offset is possible, then polyline is not printable my $p = $self->p; @$p = reverse @$p if !Math::Clipper::is_counter_clockwise($p); - my $offsets = Math::Clipper::offset([$p], -($Slic3r::flow_width / 2 / $Slic3r::resolution), $Slic3r::resolution * 100000, JT_MITER, 2); + my $offsets = Math::Clipper::offset([$p], -(scale $Slic3r::flow_spacing / 2), $Slic3r::resolution * 100000, JT_MITER, 2); return @$offsets ? 1 : 0; } diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 90b382fb7..201e99d4f 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -334,7 +334,7 @@ sub extrude_skirt { # draw outlines from outside to inside my @skirts = (); for (my $i = $Slic3r::skirts - 1; $i >= 0; $i--) { - my $distance = scale ($Slic3r::skirt_distance + ($Slic3r::flow_width * $i)); + my $distance = scale ($Slic3r::skirt_distance + ($Slic3r::flow_spacing * $i)); my $outline = offset([$convex_hull], $distance, $Slic3r::resolution * 100, JT_ROUND); push @skirts, Slic3r::ExtrusionLoop->cast([ @{$outline->[0]} ], role => 'skirt'); } diff --git a/slic3r.pl b/slic3r.pl index 1bcddd26c..b58dcb18a 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -131,10 +131,6 @@ Usage: slic3r.pl [ OPTIONS ] file.stl layer with (> 0, default: $Slic3r::first_layer_height_ratio) --infill-every-layers Infill every N layers (default: $Slic3r::infill_every_layers) - --extrusion-width-ratio - Calculate the extrusion width as the layer height multiplied by - this value (> 0, default: calculated automatically) - --bridge-flow-ratio Multiplier for extrusion when bridging (> 0, default: $Slic3r::bridge_flow_ratio) Print options: --perimeters Number of perimeters/horizontal skins (range: 1+, @@ -174,6 +170,14 @@ Usage: slic3r.pl [ OPTIONS ] file.stl --duplicate-x Number of items along X axis (1+, default: $Slic3r::duplicate_x) --duplicate-y Number of items along Y axis (1+, default: $Slic3r::duplicate_y) --duplicate-distance Distance in mm between copies (default: $Slic3r::duplicate_distance) + + Flow options (advanced): + --extrusion-width-ratio + Calculate the extrusion width as the layer height multiplied by + this value (> 0, default: calculated automatically) + --bridge-flow-ratio Multiplier for extrusion when bridging (> 0, default: $Slic3r::bridge_flow_ratio) + --overlap-ratio Overlap between extrusion threads expressed as a ratio over extrusion + width (> 0, default: $Slic3r::overlap_ratio) EOF exit ($exit_code || 0);