Skip to content
This repository
Browse code

Enable retraction for support material too, but only when moving away…

… from support islands. #831
  • Loading branch information...
commit d5537e7797e24e34560f419d7ccb132b2cefcd92 1 parent bf603b0
Alessandro Ranellucci authored
5 lib/Slic3r/GCode.pm
@@ -163,10 +163,11 @@ sub extrude_path {
163 163 my $gcode = "";
164 164
165 165 # skip retract for support material
166   - if ($path->role != EXTR_ROLE_SUPPORTMATERIAL) {
  166 + {
167 167 # retract if distance from previous position is greater or equal to the one specified by the user
168 168 my $travel = Slic3r::Line->new($self->last_pos->clone, $path->points->[0]->clone);
169   - if ($travel->length >= scale $self->extruder->retract_before_travel) {
  169 + if ($travel->length >= scale $self->extruder->retract_before_travel
  170 + && ($path->role != EXTR_ROLE_SUPPORTMATERIAL || !$self->layer->support_islands_enclose_line($travel))) {
170 171 # move travel back to original layer coordinates.
171 172 # note that we're only considering the current object's islands, while we should
172 173 # build a more complete configuration space
8 lib/Slic3r/Layer.pm
... ... @@ -1,6 +1,7 @@
1 1 package Slic3r::Layer;
2 2 use Moo;
3 3
  4 +use List::Util qw(first);
4 5 use Slic3r::Geometry::Clipper qw(union_ex);
5 6
6 7 has 'id' => (is => 'rw', required => 1, trigger => 1); # sequential number of layer, 0-based
@@ -18,6 +19,7 @@ has 'flow' => (is => 'ro', default => sub { $Slic3r::flow });
18 19 has 'slices' => (is => 'rw');
19 20
20 21 # ordered collection of extrusion paths to fill surfaces for support material
  22 +has 'support_islands' => (is => 'rw');
21 23 has 'support_fills' => (is => 'rw');
22 24 has 'support_interface_fills' => (is => 'rw');
23 25
@@ -102,4 +104,10 @@ sub make_perimeters {
102 104 $_->make_perimeters for @{$self->regions};
103 105 }
104 106
  107 +sub support_islands_enclose_line {
  108 + my $self = shift;
  109 + my ($line) = @_;
  110 + return (first { $_->encloses_line($line) } @{$self->support_islands}) ? 1 : 0;
  111 +}
  112 +
105 113 1;
23 lib/Slic3r/Print/Object.pm
@@ -626,39 +626,40 @@ sub generate_support_material {
626 626 };
627 627 return @paths;
628 628 };
629   - my %layer_paths = ();
630   - my %layer_interface_paths = ();
  629 + my %layer_paths = ();
  630 + my %layer_interface_paths = ();
  631 + my %layer_islands = ();
631 632 my $process_layer = sub {
632 633 my ($layer_id) = @_;
633 634
634 635 my $layer = $self->layers->[$layer_id];
635 636 my $paths = [ $clip_pattern->($layer_id, $layers{$layer_id}, $layer->height) ];
636 637 my $interface_paths = [ $clip_pattern->($layer_id, $layers_interfaces{$layer_id}, $layer->support_material_interface_height) ];
637   - return ($paths, $interface_paths);
  638 + my $islands = union_ex([ map @$_, map @$_, $layers{$layer_id}, $layers_interfaces{$layer_id} ]);
  639 + return ($paths, $interface_paths, $islands);
638 640 };
639 641 Slic3r::parallelize(
640 642 items => [ keys %layers ],
641 643 thread_cb => sub {
642 644 my $q = shift;
643   - my $paths = {};
644   - my $interface_paths = {};
  645 + my $result = {};
645 646 while (defined (my $layer_id = $q->dequeue)) {
646   - ($paths->{$layer_id}, $interface_paths->{$layer_id}) = $process_layer->($layer_id);
  647 + $result->{$layer_id} = [ $process_layer->($layer_id) ];
647 648 }
648   - return [ $paths, $interface_paths ];
  649 + return $result;
649 650 },
650 651 collect_cb => sub {
651   - my $paths = shift;
652   - $layer_paths{$_} = $paths->[0]{$_} for keys %{$paths->[0]};
653   - $layer_interface_paths{$_} = $paths->[1]{$_} for keys %{$paths->[1]};
  652 + my $result = shift;
  653 + ($layer_paths{$_}, $layer_interface_paths{$_}, $layer_islands{$_}) = @{$result->{$_}} for keys %$result;
654 654 },
655 655 no_threads_cb => sub {
656   - ($layer_paths{$_}, $layer_interface_paths{$_}) = $process_layer->($_) for keys %layers;
  656 + ($layer_paths{$_}, $layer_interface_paths{$_}, $layer_islands{$_}) = $process_layer->($_) for keys %layers;
657 657 },
658 658 );
659 659
660 660 foreach my $layer_id (keys %layer_paths) {
661 661 my $layer = $self->layers->[$layer_id];
  662 + $layer->support_islands($layer_islands{$layer_id});
662 663 $layer->support_fills(Slic3r::ExtrusionPath::Collection->new);
663 664 $layer->support_interface_fills(Slic3r::ExtrusionPath::Collection->new);
664 665 push @{$layer->support_fills->paths}, @{$layer_paths{$layer_id}};

0 comments on commit d5537e7

Please sign in to comment.
Something went wrong with that request. Please try again.