Skip to content

Commit

Permalink
Customizable overlap ratio (it defaults to 0.15 now)
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Dec 8, 2011
1 parent 9f6be23 commit d9a70ea
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 42 deletions.
12 changes: 8 additions & 4 deletions README.markdown
Expand Up @@ -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+,
Expand Down Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions lib/Slic3r.pm
Expand Up @@ -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;
Expand Down Expand Up @@ -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%
Expand Down
25 changes: 17 additions & 8 deletions lib/Slic3r/Config.pm
Expand Up @@ -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',
Expand All @@ -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' => {
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion 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} );
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 10 additions & 9 deletions lib/Slic3r/Fill.pm
Expand Up @@ -85,20 +85,21 @@ 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') {
$density = 1;
$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 {
Expand All @@ -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;

Expand Down
7 changes: 4 additions & 3 deletions lib/Slic3r/Fill/Concentric.pm
Expand Up @@ -3,6 +3,7 @@ use Moo;

extends 'Slic3r::Fill::Base';

use Slic3r::Geometry qw(scale);
use XXX;

sub fill_surface {
Expand All @@ -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 = ();
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Slic3r/Fill/PlanePath.pm
Expand Up @@ -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 }
Expand All @@ -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] ],
Expand Down
2 changes: 1 addition & 1 deletion lib/Slic3r/Fill/Rectilinear.pm
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions lib/Slic3r/Fill/Rectilinear2.pm
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/Slic3r/GUI/SkeinPanel.pm
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/Slic3r/Layer.pm
Expand Up @@ -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} = ();
Expand Down
4 changes: 2 additions & 2 deletions lib/Slic3r/Perimeter.pm
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lib/Slic3r/Polyline/Closed.pm
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Slic3r/Print.pm
Expand Up @@ -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');
}
Expand Down
12 changes: 8 additions & 4 deletions slic3r.pl
Expand Up @@ -131,10 +131,6 @@ sub usage {
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+,
Expand Down Expand Up @@ -174,6 +170,14 @@ sub usage {
--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);
Expand Down

0 comments on commit d9a70ea

Please sign in to comment.