From 56691c1dea6a140e1c816b855e5f26fcf5d00a86 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 13 Dec 2011 17:34:31 +0100 Subject: [PATCH 1/4] Model extrusion threads as rectangles with semicircles at the end. Remove overlap_ratio setting. #109 #112 --- README.markdown | 2 -- lib/Slic3r.pm | 4 +--- lib/Slic3r/Config.pm | 27 ++++++++++----------------- lib/Slic3r/Extruder.pm | 14 +++++++------- lib/Slic3r/ExtrusionPath.pm | 3 +-- lib/Slic3r/Fill.pm | 11 ++++------- lib/Slic3r/Fill/Concentric.pm | 6 +++--- lib/Slic3r/Fill/PlanePath.pm | 2 +- lib/Slic3r/Fill/Rectilinear.pm | 15 +++++++++------ lib/Slic3r/Fill/Rectilinear2.pm | 2 +- lib/Slic3r/GUI/SkeinPanel.pm | 2 +- lib/Slic3r/Layer.pm | 2 +- lib/Slic3r/Perimeter.pm | 4 ++-- lib/Slic3r/Polyline/Closed.pm | 2 +- lib/Slic3r/Print.pm | 2 +- slic3r.pl | 2 -- 16 files changed, 43 insertions(+), 57 deletions(-) diff --git a/README.markdown b/README.markdown index da49afc2a..77e9371f6 100644 --- a/README.markdown +++ b/README.markdown @@ -170,8 +170,6 @@ The author is Alessandro Ranellucci (me). 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 84e36dafb..d165b85fe 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -66,10 +66,8 @@ our $infill_every_layers = 1; # flow options our $extrusion_width_ratio = 0; our $bridge_flow_ratio = 1; -our $flow_speed_ratio = 1; +our $overlap_factor = 0.15; our $flow_width; -our $overlap_ratio = 0.15; -our $flow_spacing; # print options our $perimeters = 3; diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 1a391219d..ee12502f5 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -137,11 +137,6 @@ our $Options = { cli => 'bridge-flow-ratio=f', type => 'f', }, - 'overlap_ratio' => { - label => 'Extrusion overlap (ratio over extrusion width)', # the double space here prevents a bug in WxWidgets (Mac) - cli => 'overlap-ratio=f', - type => 'f', - }, # print options 'perimeters' => { @@ -367,23 +362,21 @@ sub validate { 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_speed_ratio * PI / (4 * $Slic3r::layer_height); - my $max_flow_width = $Slic3r::layer_height + $Slic3r::nozzle_diameter; if ($Slic3r::extrusion_width_ratio) { - my $flow_width = $Slic3r::layer_height * $Slic3r::extrusion_width_ratio; - $Slic3r::flow_speed_ratio = $flow_width / $Slic3r::flow_width; - $Slic3r::flow_width = $flow_width; - } elsif ($Slic3r::flow_width > $max_flow_width) { - $Slic3r::flow_speed_ratio = $max_flow_width / $Slic3r::flow_width; - $Slic3r::flow_width = $max_flow_width; + $Slic3r::flow_width = $Slic3r::layer_height * $Slic3r::extrusion_width_ratio; + } else { + # here we calculate a sane default by matching the flow speed (at the nozzle) + # and the feed rate + $Slic3r::flow_width = (($Slic3r::nozzle_diameter**2) * PI + ($Slic3r::layer_height**2) * (4 - PI)) / (4 * $Slic3r::layer_height); + + my $max_flow_width = $Slic3r::layer_height + $Slic3r::nozzle_diameter; + $Slic3r::flow_width = $max_flow_width if $Slic3r::flow_width > $max_flow_width; + $Slic3r::flow_width = $Slic3r::nozzle_diameter * 1.05 + if $Slic3r::flow_width < $Slic3r::nozzle_diameter; } - $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 9822e1204..51deaf192 100644 --- a/lib/Slic3r/Extruder.pm +++ b/lib/Slic3r/Extruder.pm @@ -7,7 +7,6 @@ has 'layer' => (is => 'rw'); has 'shift_x' => (is => 'ro', default => sub {0} ); has 'shift_y' => (is => 'ro', default => sub {0} ); has 'z' => (is => 'rw', default => sub {0} ); -has 'flow_ratio' => (is => 'rw', default => sub {1}); has 'print_feed_rate' => (is => 'rw'); has 'extrusion_distance' => (is => 'rw', default => sub {0} ); @@ -77,7 +76,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(scale $Slic3r::flow_spacing); + $extrusion_path->clip_end(scale $Slic3r::flow_width); # extrude along the path return $self->extrude($extrusion_path, $description); @@ -119,13 +118,14 @@ sub extrude { $gcode .= $self->unretract if $self->retracted; # calculate extrusion length per distance unit + my $w = $path->flow_width || $Slic3r::flow_width; + my $h = $path->depth_layers * $Slic3r::layer_height; + $h = $w if $path->role eq 'bridge'; + my $e = $Slic3r::resolution - * (($Slic3r::nozzle_diameter**2) / ($Slic3r::filament_diameter ** 2)) - * $Slic3r::flow_speed_ratio - * $self->flow_ratio - * ($path->flow_ratio || 1) + * ($w * $h + ($Slic3r::layer_height**2) / 4 * (PI - 4) + $Slic3r::overlap_factor * (($Slic3r::layer_height**2) - ($Slic3r::layer_height**2) / 4 * PI)) * $Slic3r::extrusion_multiplier - * $path->depth_layers; + * (4 / (($Slic3r::filament_diameter ** 2) * PI)); # extrude arc or line $self->print_feed_rate( diff --git a/lib/Slic3r/ExtrusionPath.pm b/lib/Slic3r/ExtrusionPath.pm index 17e627659..fb61761bb 100644 --- a/lib/Slic3r/ExtrusionPath.pm +++ b/lib/Slic3r/ExtrusionPath.pm @@ -7,8 +7,7 @@ extends 'Slic3r::Polyline'; # expressed in layers has 'depth_layers' => (is => 'ro', default => sub {1}); -# multiplier for the flow rate -has 'flow_ratio' => (is => 'rw'); +has 'flow_width' => (is => 'rw'); # perimeter/fill/solid-fill/bridge/skirt has 'role' => (is => 'rw', required => 1); diff --git a/lib/Slic3r/Fill.pm b/lib/Slic3r/Fill.pm index 545582a7c..aaddb1b8e 100644 --- a/lib/Slic3r/Fill.pm +++ b/lib/Slic3r/Fill.pm @@ -87,8 +87,7 @@ sub make_fill { SURFACE: foreach my $surface (@surfaces) { my $filler = $Slic3r::fill_pattern; my $density = $Slic3r::fill_density; - my $flow_spacing = $Slic3r::flow_spacing; - my $flow_ratio = 1; + my $flow_width = $Slic3r::flow_width; my $is_bridge = $layer->id > 0 && $surface->surface_type eq 'bottom'; my $is_solid = $surface->surface_type =~ /^(top|bottom)$/; @@ -98,9 +97,7 @@ sub make_fill { $filler = $Slic3r::solid_fill_pattern; if ($is_bridge) { $filler = 'rectilinear'; - $flow_spacing = sqrt($Slic3r::bridge_flow_ratio * ($Slic3r::nozzle_diameter**2)) - * (1-$Slic3r::overlap_ratio); - $flow_ratio = $Slic3r::bridge_flow_ratio; + $flow_width = sqrt($Slic3r::bridge_flow_ratio * ($Slic3r::nozzle_diameter**2)); } } else { next SURFACE unless $density > 0; @@ -109,7 +106,7 @@ sub make_fill { my @paths = $self->fillers->{$filler}->fill_surface( $surface, density => $density, - flow_spacing => $flow_spacing, + flow_width => $flow_width, ); my $params = shift @paths; @@ -120,7 +117,7 @@ sub make_fill { [ @$_ ], role => ($is_bridge ? 'bridge' : $is_solid ? 'solid-fill' : 'fill'), depth_layers => $surface->depth_layers, - flow_ratio => $flow_ratio * ($params->{flow_ratio} || 1), + flow_width => $flow_width, ), @paths, ], ) if @paths; diff --git a/lib/Slic3r/Fill/Concentric.pm b/lib/Slic3r/Fill/Concentric.pm index 7d1ecd1bd..c2d3142bb 100644 --- a/lib/Slic3r/Fill/Concentric.pm +++ b/lib/Slic3r/Fill/Concentric.pm @@ -12,8 +12,8 @@ sub fill_surface { # no rotation is supported for this infill pattern - my $scaled_flow_spacing = scale $params{flow_spacing}; - my $distance = $scaled_flow_spacing / $params{density}; + my $scaled_flow_width = scale $params{flow_width}; + my $distance = $scaled_flow_width / $params{density}; my @contour_loops = (); my @hole_loops = (); @@ -44,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(scale $Slic3r::flow_spacing); + $path->clip_end(scale $Slic3r::flow_width); push @paths, $path->p; } diff --git a/lib/Slic3r/Fill/PlanePath.pm b/lib/Slic3r/Fill/PlanePath.pm index caf92c948..13bdcdce9 100644 --- a/lib/Slic3r/Fill/PlanePath.pm +++ b/lib/Slic3r/Fill/PlanePath.pm @@ -27,7 +27,7 @@ sub fill_surface { my $rotate_vector = $self->infill_direction($surface); $self->rotate_points($expolygon, $rotate_vector); - my $distance_between_lines = scale $params{flow_spacing} / $params{density} * $self->multiplier; + my $distance_between_lines = scale $params{flow_width} / $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 313b73c78..5607f09d0 100644 --- a/lib/Slic3r/Fill/Rectilinear.pm +++ b/lib/Slic3r/Fill/Rectilinear.pm @@ -3,7 +3,7 @@ use Moo; extends 'Slic3r::Fill::Base'; -use Slic3r::Geometry qw(X1 Y1 X2 Y2 A B X Y scale epsilon); +use Slic3r::Geometry qw(X1 Y1 X2 Y2 A B X Y scale unscale epsilon); use XXX; sub fill_surface { @@ -19,14 +19,17 @@ sub fill_surface { $bounding_box->[X1] += scale 0.1; $bounding_box->[X2] -= scale 0.1; - my $min_spacing = scale $params{flow_spacing}; + my $min_spacing = scale $params{flow_width}; my $distance_between_lines = $min_spacing / $params{density}; my $line_oscillation = $distance_between_lines - $min_spacing; my $number_of_lines = int(($bounding_box->[X2] - $bounding_box->[X1]) / $distance_between_lines) + 1; - my $extra_space = ($bounding_box->[X2] - $bounding_box->[X1]) % $distance_between_lines; - $distance_between_lines += $extra_space / ($number_of_lines - 1) if $number_of_lines > 1; - my $flow_ratio = $distance_between_lines / ($min_spacing / $params{density}); + my $flow_width = undef; + if ($params{density} == 1) { + my $extra_space = ($bounding_box->[X2] - $bounding_box->[X1]) % $distance_between_lines; + $distance_between_lines += $extra_space / ($number_of_lines - 1) if $number_of_lines > 1; + $flow_width = unscale $distance_between_lines; + } my @paths = (); my $x = $bounding_box->[X1]; @@ -70,7 +73,7 @@ sub fill_surface { # paths must be rotated back $self->rotate_points_back(\@paths, $rotate_vector); - return { flow_ratio => $flow_ratio }, @paths; + return { flow_width => $flow_width }, @paths; } 1; diff --git a/lib/Slic3r/Fill/Rectilinear2.pm b/lib/Slic3r/Fill/Rectilinear2.pm index d8b8f0bb0..9ece7ee26 100644 --- a/lib/Slic3r/Fill/Rectilinear2.pm +++ b/lib/Slic3r/Fill/Rectilinear2.pm @@ -16,7 +16,7 @@ sub fill_surface { my $rotate_vector = $self->infill_direction($surface); $self->rotate_points($polygons, $rotate_vector); - my $distance_between_lines = scale $params{flow_spacing} / $params{density}; + my $distance_between_lines = scale $params{flow_width} / $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 bc8f27192..19209aef5 100644 --- a/lib/Slic3r/GUI/SkeinPanel.pm +++ b/lib/Slic3r/GUI/SkeinPanel.pm @@ -59,7 +59,7 @@ sub new { }, extrusion => { title => 'Extrusion', - options => [qw(extrusion_width_ratio bridge_flow_ratio overlap_ratio)], + options => [qw(extrusion_width_ratio bridge_flow_ratio)], }, ); $self->{panels} = \%panels; diff --git a/lib/Slic3r/Layer.pm b/lib/Slic3r/Layer.pm index 47a5c8fce..322f1025c 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_spacing / 2; + my $distance = scale $Slic3r::flow_width / 2; my @surfaces = @{$self->fill_surfaces}; @{$self->fill_surfaces} = (); diff --git a/lib/Slic3r/Perimeter.pm b/lib/Slic3r/Perimeter.pm index 413f205a7..1532dc9d7 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 = scale $Slic3r::flow_spacing; + $distance = scale $Slic3r::flow_width; } # create one more offset to be used as boundary for fill { - $distance -= scale $Slic3r::flow_spacing; + $distance -= scale $Slic3r::flow_width; 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 8d9d54c3a..bb321a950 100644 --- a/lib/Slic3r/Polyline/Closed.pm +++ b/lib/Slic3r/Polyline/Closed.pm @@ -32,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], -(scale $Slic3r::flow_spacing / 2), $Slic3r::resolution * 100000, JT_MITER, 2); + my $offsets = Math::Clipper::offset([$p], -(scale $Slic3r::flow_width / 2), $Slic3r::resolution * 100000, JT_MITER, 2); return @$offsets ? 1 : 0; } diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 31111e716..552e92002 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -335,7 +335,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_spacing * $i)); + my $distance = scale ($Slic3r::skirt_distance + ($Slic3r::flow_width * $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 b58dcb18a..d74db5070 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -176,8 +176,6 @@ Usage: slic3r.pl [ OPTIONS ] file.stl 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); From 569e737ae1c66015586b7d7bfb6fbd329bac249a Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 13 Dec 2011 17:36:03 +0100 Subject: [PATCH 2/4] Only connect infill edges when not doing solid surfaces --- lib/Slic3r/Fill/Rectilinear.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Slic3r/Fill/Rectilinear.pm b/lib/Slic3r/Fill/Rectilinear.pm index 5607f09d0..b15524454 100644 --- a/lib/Slic3r/Fill/Rectilinear.pm +++ b/lib/Slic3r/Fill/Rectilinear.pm @@ -45,7 +45,7 @@ sub fill_surface { } # connect lines - { + if ($params{density} < 1) { my $collection = Slic3r::ExtrusionPath::Collection->new( paths => [ map Slic3r::ExtrusionPath->cast([ @$_ ], role => 'bogus'), @paths ], ); From 4bee1a12b8fc06d6fe8c07c547258ffbc2b0d4fe Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 14 Dec 2011 11:21:43 +0100 Subject: [PATCH 3/4] Take overlap into account for external dimensions --- lib/Slic3r/Layer.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/Layer.pm b/lib/Slic3r/Layer.pm index 322f1025c..85725eee2 100644 --- a/lib/Slic3r/Layer.pm +++ b/lib/Slic3r/Layer.pm @@ -124,7 +124,14 @@ sub make_surfaces { # the contours must be offsetted by half extrusion width inwards { - my $distance = scale $Slic3r::flow_width / 2; + my $distance = $Slic3r::flow_width / 2; + if ($Slic3r::overlap_factor) { + # our overlap is done by increasing the flow; however external perimeters will grow + # outwards, so we offset by the correct amount + $distance = ($Slic3r::flow_width + $Slic3r::overlap_factor * $Slic3r::layer_height * (1 - PI/4)) / 2; + } + $distance = scale $distance; + my @surfaces = @{$self->slices}; @{$self->slices} = (); foreach my $surface (@surfaces) { From 048f7ca46843082cbe057cdfea1afe7841c8917d Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 14 Dec 2011 11:35:19 +0100 Subject: [PATCH 4/4] Adjusted flow width for solid infills was ignored --- lib/Slic3r/Fill.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Slic3r/Fill.pm b/lib/Slic3r/Fill.pm index aaddb1b8e..14fa7deff 100644 --- a/lib/Slic3r/Fill.pm +++ b/lib/Slic3r/Fill.pm @@ -117,7 +117,7 @@ sub make_fill { [ @$_ ], role => ($is_bridge ? 'bridge' : $is_solid ? 'solid-fill' : 'fill'), depth_layers => $surface->depth_layers, - flow_width => $flow_width, + flow_width => $params->{flow_width}, ), @paths, ], ) if @paths;