mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	Do each island completely if avoid_crossing_perimeters is enabled. #278
This commit is contained in:
		
							parent
							
								
									f10a4787b2
								
							
						
					
					
						commit
						dac168eff0
					
				
					 4 changed files with 57 additions and 17 deletions
				
			
		|  | @ -60,6 +60,11 @@ sub split_at_first_point { | ||||||
|     return $self->split_at_index(0); |     return $self->split_at_index(0); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | sub first_point { | ||||||
|  |     my $self = shift; | ||||||
|  |     return $self->polygon->[0]; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| package Slic3r::ExtrusionLoop::Packed; | package Slic3r::ExtrusionLoop::Packed; | ||||||
| sub unpack { | sub unpack { | ||||||
|     my $self = shift; |     my $self = shift; | ||||||
|  |  | ||||||
|  | @ -86,9 +86,9 @@ sub points { | ||||||
|     return $self->polyline; |     return $self->polyline; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| sub endpoints { | sub first_point { | ||||||
|     my $self = shift; |     my $self = shift; | ||||||
|     return ($self->points->[0], $self->points->[-1]); |     return $self->polyline->[0]; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| sub is_printable { 1 } | sub is_printable { 1 } | ||||||
|  |  | ||||||
|  | @ -3,9 +3,12 @@ use Moo; | ||||||
| 
 | 
 | ||||||
| has 'paths' => (is => 'rw', default => sub { [] }); | has 'paths' => (is => 'rw', default => sub { [] }); | ||||||
| 
 | 
 | ||||||
| sub endpoints { | # no-op | ||||||
|  | sub unpack { $_[0] } | ||||||
|  | 
 | ||||||
|  | sub first_point { | ||||||
|     my $self = shift; |     my $self = shift; | ||||||
|     return [ map $_->endpoints, @{$self->paths} ]; |     return $self->paths->[0]->unpack->polyline->[0]; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| sub chained_path { | sub chained_path { | ||||||
|  |  | ||||||
|  | @ -850,21 +850,53 @@ sub write_gcode { | ||||||
|                 my $layerm = $layer->regions->[$region_id]; |                 my $layerm = $layer->regions->[$region_id]; | ||||||
|                 my $region = $self->regions->[$region_id]; |                 my $region = $self->regions->[$region_id]; | ||||||
|                  |                  | ||||||
|                 # extrude perimeters |                 my @islands = (); | ||||||
|                 if (@{ $layerm->perimeters }) { |                 if ($Slic3r::Config->avoid_crossing_perimeters) { | ||||||
|                     $gcode .= $gcodegen->set_extruder($region->extruders->{perimeter}); |                     push @islands, map +{ perimeters => [], fills => [] }, @{$layer->slices}; | ||||||
|                     $gcode .= $gcodegen->extrude($_, 'perimeter') for @{ $layerm->perimeters }; |                     PERIMETER: foreach my $perimeter (@{$layerm->perimeters}) { | ||||||
|  |                         $perimeter = $perimeter->unpack; | ||||||
|  |                         for my $i (0 .. $#{$layer->slices}-1) { | ||||||
|  |                             if ($layer->slices->[$i]->contour->encloses_point($perimeter->first_point)) { | ||||||
|  |                                 push @{ $islands[$i]{perimeters} }, $perimeter; | ||||||
|  |                                 next PERIMETER; | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                         push @{ $islands[-1]{perimeters} }, $perimeter; # optimization | ||||||
|  |                     } | ||||||
|  |                     FILL: foreach my $fill (@{$layerm->fills}) { | ||||||
|  |                         for my $i (0 .. $#{$layer->slices}-1) { | ||||||
|  |                             $fill = $fill->unpack; | ||||||
|  |                             if ($layer->slices->[$i]->contour->encloses_point($fill->first_point)) { | ||||||
|  |                                 push @{ $islands[$i]{fills} }, $fill; | ||||||
|  |                                 next FILL; | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                         push @{ $islands[-1]{fills} }, $fill; # optimization | ||||||
|  |                     } | ||||||
|  |                 } else { | ||||||
|  |                     push @islands, { | ||||||
|  |                         perimeters  => $layerm->perimeters, | ||||||
|  |                         fills       => $layerm->fills, | ||||||
|  |                     }; | ||||||
|                 } |                 } | ||||||
|                  |                  | ||||||
|                 # extrude fills |                 foreach my $island (@islands) { | ||||||
|                 if (@{ $layerm->fills }) { |                     # extrude perimeters | ||||||
|                     $gcode .= $gcodegen->set_extruder($region->extruders->{infill}); |                     if (@{ $island->{perimeters} }) { | ||||||
|                     for my $fill (@{ $layerm->fills }) { |                         $gcode .= $gcodegen->set_extruder($region->extruders->{perimeter}); | ||||||
|                         if ($fill->isa('Slic3r::ExtrusionPath::Collection')) { |                         $gcode .= $gcodegen->extrude($_, 'perimeter') for @{ $island->{perimeters} }; | ||||||
|                             $gcode .= $gcodegen->extrude($_, 'fill')  |                     } | ||||||
|                                 for $fill->chained_path($gcodegen->last_pos); |                      | ||||||
|                         } else { |                     # extrude fills | ||||||
|                             $gcode .= $gcodegen->extrude($fill, 'fill') ; |                     if (@{ $island->{fills} }) { | ||||||
|  |                         $gcode .= $gcodegen->set_extruder($region->extruders->{infill}); | ||||||
|  |                         for my $fill (@{ $island->{fills} }) { | ||||||
|  |                             if ($fill->isa('Slic3r::ExtrusionPath::Collection')) { | ||||||
|  |                                 $gcode .= $gcodegen->extrude($_, 'fill')  | ||||||
|  |                                     for $fill->chained_path($gcodegen->last_pos); | ||||||
|  |                             } else { | ||||||
|  |                                 $gcode .= $gcodegen->extrude($fill, 'fill') ; | ||||||
|  |                             } | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alessandro Ranellucci
						Alessandro Ranellucci