mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 04:31:15 -06:00 
			
		
		
		
	Use the same bridging logic for "reverse bridges" (top surfaces)
This commit is contained in:
		
							parent
							
								
									6ec7069f8e
								
							
						
					
					
						commit
						580f42c1de
					
				
					 2 changed files with 48 additions and 40 deletions
				
			
		|  | @ -4,7 +4,7 @@ use Moo; | ||||||
| use Math::Clipper ':all'; | use Math::Clipper ':all'; | ||||||
| use Slic3r::Geometry qw(polygon_lines points_coincide angle3points polyline_lines nearest_point | use Slic3r::Geometry qw(polygon_lines points_coincide angle3points polyline_lines nearest_point | ||||||
|     line_length collinear X Y A B PI); |     line_length collinear X Y A B PI); | ||||||
| use Slic3r::Geometry::Clipper qw(safety_offset union_ex PFT_EVENODD); | use Slic3r::Geometry::Clipper qw(union_ex diff_ex intersection_ex PFT_EVENODD); | ||||||
| use XXX; | use XXX; | ||||||
| 
 | 
 | ||||||
| # a sequential number of layer, starting at 0 | # a sequential number of layer, starting at 0 | ||||||
|  | @ -347,28 +347,29 @@ sub remove_small_perimeters { | ||||||
| # make bridges printable | # make bridges printable | ||||||
| sub process_bridges { | sub process_bridges { | ||||||
|     my $self = shift; |     my $self = shift; | ||||||
|     return if $self->id == 0; |  | ||||||
|      |      | ||||||
|     # a bottom surface on a layer > 0 is either a bridge or a overhang  |     # a bottom surface on a layer > 0 is either a bridge or a overhang  | ||||||
|     # or a combination of both |     # or a combination of both; any top surface is a candidate for | ||||||
|  |     # reverse bridge processing | ||||||
|  |      | ||||||
|  |     my @solid_surfaces = grep { | ||||||
|  |         ($_->surface_type eq 'bottom' && $self->id > 0) || $_->surface_type eq 'top' | ||||||
|  |     } @{$self->surfaces} or return; | ||||||
|      |      | ||||||
|     my @bottom_surfaces     = grep $_->surface_type eq 'bottom',   @{$self->surfaces} or return; |  | ||||||
|     my @supporting_surfaces = grep $_->surface_type =~ /internal/, @{$self->surfaces}; |     my @supporting_surfaces = grep $_->surface_type =~ /internal/, @{$self->surfaces}; | ||||||
|      |      | ||||||
|     SURFACE: foreach my $surface (@bottom_surfaces) { |     SURFACE: foreach my $surface (@solid_surfaces) { | ||||||
|         # since we can't print concave bridges, we transform the surface |         # ignore holes in bridges; | ||||||
|         # in a convex polygon; this will print thin membranes eventually |  | ||||||
|         my $surface_p = $surface->contour->p; |  | ||||||
|          |  | ||||||
|         # offset the surface a bit to avoid approximation issues when doing the |         # offset the surface a bit to avoid approximation issues when doing the | ||||||
|         # intersection below (this is to make sure we overlap with supporting |         # intersection below (this is to make sure we overlap with supporting | ||||||
|         # surfaces, otherwise a little gap will result from intersection) |         # surfaces, otherwise a little gap will result from intersection) | ||||||
|         $surface_p = safety_offset([$surface_p])->[0]; |         my $contour = $surface->expolygon->contour->safety_offset; | ||||||
|  |         my $description = $surface->surface_type eq 'bottom' ? 'bridge/overhang' : 'reverse bridge'; | ||||||
|          |          | ||||||
|             #use Slic3r::SVG; |             #use Slic3r::SVG; | ||||||
|             #Slic3r::SVG::output(undef, "bridge.svg", |             #Slic3r::SVG::output(undef, "bridge.svg", | ||||||
|             #    green_polygons  => [ map $_->p, @supporting_surfaces ], |             #    green_polygons  => [ map $_->p, @supporting_surfaces ], | ||||||
|             #    red_polygons    => [ $surface_p ], |             #    red_polygons    => [ $contour ], | ||||||
|             #); |             #); | ||||||
|          |          | ||||||
|         # find all supported edges (as polylines, thus keeping notion of  |         # find all supported edges (as polylines, thus keeping notion of  | ||||||
|  | @ -376,7 +377,7 @@ sub process_bridges { | ||||||
|         my @supported_polylines = (); |         my @supported_polylines = (); | ||||||
|         { |         { | ||||||
|             my @current_polyline = (); |             my @current_polyline = (); | ||||||
|             EDGE: foreach my $edge (Slic3r::Geometry::polygon_lines($surface_p)) { |             EDGE: foreach my $edge ($contour->lines) { | ||||||
|                 for my $supporting_surface (@supporting_surfaces) { |                 for my $supporting_surface (@supporting_surfaces) { | ||||||
|                     local $Slic3r::Geometry::epsilon = 1E+7; |                     local $Slic3r::Geometry::epsilon = 1E+7; | ||||||
|                     if (Slic3r::Geometry::polygon_has_subsegment($supporting_surface->contour->p, $edge)) { |                     if (Slic3r::Geometry::polygon_has_subsegment($supporting_surface->contour->p, $edge)) { | ||||||
|  | @ -394,12 +395,12 @@ sub process_bridges { | ||||||
|          |          | ||||||
|         # defensive programming, this shouldn't happen |         # defensive programming, this shouldn't happen | ||||||
|         if (@supported_polylines == 0) { |         if (@supported_polylines == 0) { | ||||||
|             Slic3r::debugf "Found bridge/overhang with no supports on layer %d; ignoring\n", $self->id; |             Slic3r::debugf "Found $description with no supports on layer %d; ignoring\n", $self->id; | ||||||
|             next SURFACE; |             next SURFACE; | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         if (@supported_polylines == 1) { |         if (@supported_polylines == 1) { | ||||||
|             Slic3r::debugf "Found bridge/overhang with only one support on layer %d; ignoring\n", $self->id; |             Slic3r::debugf "Found $description with only one support on layer %d; ignoring\n", $self->id; | ||||||
|             next SURFACE; |             next SURFACE; | ||||||
|         } |         } | ||||||
|          |          | ||||||
|  | @ -437,17 +438,15 @@ sub process_bridges { | ||||||
|         # now, extend our bridge by taking a portion of supporting surfaces |         # now, extend our bridge by taking a portion of supporting surfaces | ||||||
|         { |         { | ||||||
|             # offset the bridge by the specified amount of mm |             # offset the bridge by the specified amount of mm | ||||||
|             my $bridge_offset = ${ offset([$surface_p], $Slic3r::bridge_overlap / $Slic3r::resolution, $Slic3r::resolution * 100, JT_MITER, 2) }[0]; |             my $bridge_offset = ${ offset([$contour], $Slic3r::bridge_overlap / $Slic3r::resolution, $Slic3r::resolution * 100, JT_MITER, 2) }[0]; | ||||||
|              |              | ||||||
|             # calculate the new bridge |             # calculate the new bridge | ||||||
|             my $clipper = Math::Clipper->new; |             my $intersection = intersection_ex( | ||||||
|             $clipper->add_subject_polygon($surface_p); |                 [ $contour, map $_->p, @supporting_neighbor_surfaces ], | ||||||
|             $clipper->add_subject_polygons([ map $_->p, @supporting_neighbor_surfaces ]); |                 [ $bridge_offset ], | ||||||
|             $clipper->add_clip_polygon($bridge_offset); |              ); | ||||||
|             my $intersection = $clipper->execute(CT_INTERSECTION, PFT_NONZERO, PFT_NONZERO); |             push @{$self->bridges}, map Slic3r::Surface::Bridge->cast_from_expolygon($_, | ||||||
|              |                 surface_type => $surface->surface_type, | ||||||
|             push @{$self->bridges}, map Slic3r::Surface::Bridge->cast_from_polygon($_, |  | ||||||
|                 surface_type => 'bottom', |  | ||||||
|                 bridge_angle => $bridge_angle, |                 bridge_angle => $bridge_angle, | ||||||
|             ), @$intersection; |             ), @$intersection; | ||||||
|         } |         } | ||||||
|  | @ -463,18 +462,26 @@ sub detect_perimeter_surfaces { | ||||||
|     if (!@{$self->bridges}) { |     if (!@{$self->bridges}) { | ||||||
|         push @{$self->perimeter_surfaces}, @{$self->surfaces}; |         push @{$self->perimeter_surfaces}, @{$self->surfaces}; | ||||||
|     } else { |     } else { | ||||||
|         my $clipper = Math::Clipper->new; |         my $union = union_ex([ | ||||||
|         $clipper->add_subject_polygons([ map $_->p, grep $_->surface_type =~ /internal/, @{$self->surfaces} ]); |             (map $_->p, grep $_->surface_type =~ /internal/, @{$self->surfaces}), | ||||||
|         $clipper->add_clip_polygons([ map $_->p, @{$self->bridges} ]); |             (map $_->p, @{$self->bridges}), | ||||||
|         my $union = $clipper->ex_execute(CT_UNION, PFT_NONZERO, PFT_NONZERO); |         ]); | ||||||
|          |          | ||||||
|  |         # schedule perimeters for internal surfaces merged with bridges | ||||||
|         push @{$self->perimeter_surfaces},  |         push @{$self->perimeter_surfaces},  | ||||||
|             map Slic3r::Surface->cast_from_expolygon($_, surface_type => 'internal'),  |             map Slic3r::Surface->cast_from_expolygon($_, surface_type => 'internal'),  | ||||||
|             @$union; |             @$union; | ||||||
|          |          | ||||||
|         push @{$self->perimeter_surfaces},  |         # schedule perimeters for the remaining surfaces | ||||||
|             grep $_->surface_type !~ /internal/ && ($_->surface_type ne 'bottom' || $self->id == 0),  |         foreach my $type (qw(top bottom)) { | ||||||
|             @{$self->surfaces}; |             my $diff = diff_ex( | ||||||
|  |                 [ map $_->p, grep $_->surface_type eq $type, @{$self->surfaces} ], | ||||||
|  |                 [ map @$_, @$union ], | ||||||
|  |             ); | ||||||
|  |             push @{$self->perimeter_surfaces},  | ||||||
|  |                 map Slic3r::Surface->cast_from_expolygon($_, surface_type => $type),  | ||||||
|  |                 @$diff; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -482,29 +489,25 @@ sub detect_perimeter_surfaces { | ||||||
| sub split_bridges_fills { | sub split_bridges_fills { | ||||||
|     my $self = shift; |     my $self = shift; | ||||||
|      |      | ||||||
|     my $clipper = Math::Clipper->new; |  | ||||||
|     foreach my $surfaces (@{$self->fill_surfaces}) { |     foreach my $surfaces (@{$self->fill_surfaces}) { | ||||||
|         my @surfaces = @$surfaces; |         my @surfaces = @$surfaces; | ||||||
|         @$surfaces = (); |         @$surfaces = (); | ||||||
|          |          | ||||||
|         # intersect fill_surfaces with bridges to get actual bridges |         # intersect fill_surfaces with bridges to get actual bridges | ||||||
|         foreach my $bridge (@{$self->bridges}) { |         foreach my $bridge (@{$self->bridges}) { | ||||||
|             $clipper->clear; |             my $intersection = intersection_ex( | ||||||
|             $clipper->add_subject_polygons([ map $_->p, @surfaces ]); |                 [ map $_->p, @surfaces ], | ||||||
|             $clipper->add_clip_polygon($bridge->contour->p); |                 [ $bridge->contour->p ], | ||||||
|             my $intersection = $clipper->ex_execute(CT_INTERSECTION, PFT_NONZERO, PFT_NONZERO); |             ); | ||||||
|             push @$surfaces, map Slic3r::Surface::Bridge->cast_from_expolygon($_, |             push @$surfaces, map Slic3r::Surface::Bridge->cast_from_expolygon($_, | ||||||
|                 surface_type => 'bottom', |                 surface_type => $bridge->surface_type, | ||||||
|                 bridge_angle => $bridge->bridge_angle, |                 bridge_angle => $bridge->bridge_angle, | ||||||
|             ), @$intersection; |             ), @$intersection; | ||||||
|         } |         } | ||||||
|          |          | ||||||
|         # difference between fill_surfaces and bridges are the other surfaces |         # difference between fill_surfaces and bridges are the other surfaces | ||||||
|         foreach my $surface (@surfaces) { |         foreach my $surface (@surfaces) { | ||||||
|             $clipper->clear; |             my $difference = diff_ex([ $surface->p ], [ map $_->contour->p, @{$self->bridges} ]); | ||||||
|             $clipper->add_subject_polygons([ $surface->p ]); |  | ||||||
|             $clipper->add_clip_polygons([ map $_->contour->p, @{$self->bridges} ]); |  | ||||||
|             my $difference = $clipper->ex_execute(CT_DIFFERENCE, PFT_NONZERO, PFT_NONZERO); |  | ||||||
|             push @$surfaces, map Slic3r::Surface->cast_from_expolygon($_, |             push @$surfaces, map Slic3r::Surface->cast_from_expolygon($_, | ||||||
|                 surface_type => $surface->surface_type), @$difference; |                 surface_type => $surface->surface_type), @$difference; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -70,4 +70,9 @@ sub area { | ||||||
|     return Slic3r::Geometry::Clipper::area($self); |     return Slic3r::Geometry::Clipper::area($self); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | sub safety_offset { | ||||||
|  |     my $self = shift; | ||||||
|  |     return (ref $self)->new(Slic3r::Geometry::Clipper::safety_offset([$self])->[0]); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| 1; | 1; | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alessandro Ranellucci
						Alessandro Ranellucci