From 177f1a9bf08f4c30ce42b142b3f74edebd71ad12 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 28 Jan 2013 14:12:01 +0100 Subject: [PATCH 1/2] New raft_layers option. #123 --- README.markdown | 1 + lib/Slic3r/Config.pm | 8 ++++++++ lib/Slic3r/GUI/Tab.pm | 4 ++++ lib/Slic3r/Layer.pm | 14 ++++++++++---- lib/Slic3r/Print/Object.pm | 7 ++++--- slic3r.pl | 1 + 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/README.markdown b/README.markdown index bc012abcf..d0e38e3b9 100644 --- a/README.markdown +++ b/README.markdown @@ -209,6 +209,7 @@ The author of the Silk icon set is Mark James. Spacing between pattern lines (mm, default: 2.5) --support-material-angle Support material angle in degrees (range: 0-90, default: 0) + --raft-layers Number of layers to raise the printed objects by (range: 0+, default: 0) Retraction options: --retract-length Length of retraction in mm when pausing extrusion (default: 1) diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index f57eff597..f22e1fd9e 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -578,6 +578,14 @@ our $Options = { type => 'i', default => 0, }, + 'raft_layers' => { + label => 'Raft layers', + tooltip => 'Number of total raft layers to insert below the object(s).', + sidetext => 'layers', + cli => 'raft-layers=i', + type => 'i', + default => 0, + }, 'start_gcode' => { label => 'Start G-code', tooltip => 'This start procedure is inserted at the beginning of the output file, right after the temperature control commands for extruder and bed. If Slic3r detects M104 or M190 in your custom codes, such commands will not be prepended automatically. Note that you can use placeholder variables for all Slic3r settings, so you can put a "M104 S[first_layer_temperature]" command wherever you want.', diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index a0ebc1a9a..f48c3782b 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -456,6 +456,10 @@ sub build { title => 'Support material', options => [qw(support_material support_material_threshold support_material_pattern support_material_spacing support_material_angle)], }, + { + title => 'Raft', + options => [qw(raft_layers)], + }, ]); $self->add_options_page('Notes', 'note.png', optgroups => [ diff --git a/lib/Slic3r/Layer.pm b/lib/Slic3r/Layer.pm index d22188ab5..e523df21c 100644 --- a/lib/Slic3r/Layer.pm +++ b/lib/Slic3r/Layer.pm @@ -2,6 +2,7 @@ package Slic3r::Layer; use Moo; use List::Util qw(first); +use Slic3r::Geometry qw(scale); use Slic3r::Geometry::Clipper qw(union_ex); has 'id' => (is => 'rw', required => 1, trigger => 1); # sequential number of layer, 0-based @@ -32,11 +33,16 @@ sub _trigger_id { sub _build_slice_z { my $self = shift; - if ($self->id == 0) { - return $Slic3r::Config->get_value('first_layer_height') / 2 / &Slic3r::SCALING_FACTOR; + if ($Slic3r::Config->raft_layers == 0) { + if ($self->id == 0) { + return scale $Slic3r::Config->get_value('first_layer_height') / 2; + } + return scale($Slic3r::Config->get_value('first_layer_height') + ($self->id-1 + 0.5) * $Slic3r::Config->layer_height); + } else { + return -1 if $self->id < $Slic3r::Config->raft_layers; + my $object_layer_id = $self->id - $Slic3r::Config->raft_layers; + return scale ($object_layer_id + 0.5) * $Slic3r::Config->layer_height; } - return ($Slic3r::Config->get_value('first_layer_height') + (($self->id-1) * $Slic3r::Config->layer_height) + ($Slic3r::Config->layer_height/2)) - / &Slic3r::SCALING_FACTOR; #/ } # Z used for printing in scaled coordinates diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 1457a66ec..b1c02bbff 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -173,9 +173,10 @@ sub slice { } # remove empty layers from bottom - while (@{$self->layers} && !@{$self->layers->[0]->slices} && !map @{$_->thin_walls}, @{$self->layers->[0]->regions}) { - shift @{$self->layers}; - for (my $i = 0; $i <= $#{$self->layers}; $i++) { + my $first_object_layer_id = $Slic3r::Config->raft_layers; + while (@{$self->layers} && !@{$self->layers->[$first_object_layer_id]->slices} && !map @{$_->thin_walls}, @{$self->layers->[$first_object_layer_id]->regions}) { + splice @{$self->layers}, $first_object_layer_id, 1; + for (my $i = $first_object_layer_id; $i <= $#{$self->layers}; $i++) { $self->layers->[$i]->id($i); } } diff --git a/slic3r.pl b/slic3r.pl index c66277c58..a8a6386b0 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -257,6 +257,7 @@ $j Spacing between pattern lines (mm, default: $config->{support_material_spacing}) --support-material-angle Support material angle in degrees (range: 0-90, default: $config->{support_material_angle}) + --raft-layers Number of layers to raise the printed objects by (range: 0+, default: $config->{raft_layers}) Retraction options: --retract-length Length of retraction in mm when pausing extrusion (default: $config->{retract_length}[0]) From c7b4d99d7e418ce7d29d5e228835ede715b3e523 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 2 Feb 2013 16:16:43 +0100 Subject: [PATCH 2/2] Generate raft automatically even when support material is disabled --- lib/Slic3r/Print.pm | 8 ++++---- lib/Slic3r/Print/Object.pm | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 5f06cf1db..38e0a78ad 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -216,7 +216,7 @@ sub init_extruders { } # calculate support material flow - if ($self->config->support_material) { + if ($self->config->support_material || $self->config->raft_layers > 0) { my $extruder = $self->extruders->[$self->config->support_material_extruder-1]; $self->support_material_flow($extruder->make_flow( width => $self->config->support_material_extrusion_width || $self->config->extrusion_width, @@ -413,7 +413,7 @@ sub export_gcode { } # generate support material - if ($Slic3r::Config->support_material) { + if ($Slic3r::Config->support_material || $Slic3r::Config->raft_layers > 0) { $status_cb->(85, "Generating support material"); $_->generate_support_material for @{$self->objects}; } @@ -510,7 +510,7 @@ EOF } } # generate support material - if ($Slic3r::Config->support_material && $layer_id > 0) { + if (($Slic3r::Config->support_material || $self->config->raft_layers > 0) && $layer_id > 0) { my (@supported_slices, @unsupported_slices) = (); foreach my $expolygon (@current_layer_slices) { my $intersection = intersection_ex( @@ -801,7 +801,7 @@ sub write_gcode { # extrude support material before other things because it might use a lower Z # and also because we avoid travelling on other things when printing it - if ($Slic3r::Config->support_material) { + if ($Slic3r::Config->support_material || $self->config->raft_layers > 0) { $gcode .= $gcodegen->move_z($layer->support_material_interface_z) if ($layer->support_interface_fills && @{ $layer->support_interface_fills->paths }); $gcode .= $gcodegen->set_extruder($self->extruders->[$Slic3r::Config->support_material_extruder-1]); diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index b1c02bbff..6f8575288 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -559,6 +559,8 @@ sub generate_support_material { my @current_support_regions = (); # expolygons we've started to support (i.e. below the empty interface layers) my @queue = (); # the number of items of this array determines the number of empty interface layers for my $i (reverse 0 .. $#{$self->layers}) { + next unless $Slic3r::Config->support_material || ($i <= $Slic3r::Config->raft_layers); # <= because we need to start from the first non-raft layer + my $layer = $self->layers->[$i]; my $lower_layer = $i > 0 ? $self->layers->[$i-1] : undef;