Connect infill segments and adjust spacing and flow rate to fill the area completely without leaving gaps. #89
This commit is contained in:
parent
4fe340cc56
commit
0aff5fab24
@ -117,6 +117,7 @@ sub extrude {
|
||||
* (($Slic3r::nozzle_diameter**2) / ($Slic3r::filament_diameter ** 2))
|
||||
* $Slic3r::flow_speed_ratio
|
||||
* $self->flow_ratio
|
||||
* ($path->flow_ratio || 1)
|
||||
* $Slic3r::extrusion_multiplier
|
||||
* $path->depth_layers;
|
||||
|
||||
|
@ -7,6 +7,9 @@ extends 'Slic3r::Polyline';
|
||||
# expressed in layers
|
||||
has 'depth_layers' => (is => 'ro', default => sub {1});
|
||||
|
||||
# multiplier for the flow rate
|
||||
has 'flow_ratio' => (is => 'rw');
|
||||
|
||||
# perimeter/fill/solid-fill/bridge/skirt
|
||||
has 'role' => (is => 'ro', required => 1);
|
||||
|
||||
|
@ -18,7 +18,7 @@ sub add {
|
||||
|
||||
sub endpoints {
|
||||
my $self = shift;
|
||||
return map $_->endpoints, @{$self->paths};
|
||||
return [ map $_->endpoints, @{$self->paths} ];
|
||||
}
|
||||
|
||||
sub shortest_path {
|
||||
@ -30,7 +30,7 @@ sub shortest_path {
|
||||
CYCLE: while (@{$self->paths}) {
|
||||
# find nearest point
|
||||
$start_at = $start_near
|
||||
? Slic3r::Point->new(Slic3r::Geometry::nearest_point($start_near, [ $self->endpoints ]))
|
||||
? Slic3r::Point->new(Slic3r::Geometry::nearest_point($start_near, $self->endpoints))
|
||||
: $self->endpoints->[0];
|
||||
|
||||
# loop through paths to find the one that starts or ends at the point found
|
||||
|
@ -60,6 +60,7 @@ sub make_fill {
|
||||
$union = diff_ex(
|
||||
[ map @$_, @$union ],
|
||||
[ map $_->p, @surfaces_with_bridge_angle ],
|
||||
1,
|
||||
);
|
||||
}
|
||||
|
||||
@ -67,6 +68,7 @@ sub make_fill {
|
||||
$union = diff_ex(
|
||||
[ map @$_, @$union ],
|
||||
[ map $_->p, @surfaces ],
|
||||
1,
|
||||
);
|
||||
|
||||
push @surfaces, map Slic3r::Surface->cast_from_expolygon($_,
|
||||
@ -103,6 +105,7 @@ sub make_fill {
|
||||
density => $density,
|
||||
flow_width => $flow_width,
|
||||
);
|
||||
my $params = shift @paths;
|
||||
|
||||
# save into layer
|
||||
push @{ $layer->fills }, Slic3r::ExtrusionPath::Collection->new(
|
||||
@ -111,10 +114,11 @@ sub make_fill {
|
||||
[ @$_ ],
|
||||
role => ($is_bridge ? 'bridge' : $is_solid ? 'solid-fill' : 'fill'),
|
||||
depth_layers => $surface->depth_layers,
|
||||
flow_ratio => $params->{flow_ratio},
|
||||
), @paths,
|
||||
],
|
||||
);
|
||||
$layer->fills->[-1]->cleanup;
|
||||
###$layer->fills->[-1]->cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ sub fill_surface {
|
||||
# paths must be rotated back
|
||||
$self->rotate_points_back(\@paths, $rotate_vector);
|
||||
|
||||
return @paths;
|
||||
return {}, @paths;
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -3,7 +3,7 @@ use Moo;
|
||||
|
||||
extends 'Slic3r::Fill::Base';
|
||||
|
||||
use Slic3r::Geometry qw(X1 Y1 X2 Y2 A B X);
|
||||
use Slic3r::Geometry qw(X1 Y1 X2 Y2 A B X Y scale epsilon);
|
||||
use XXX;
|
||||
|
||||
sub fill_surface {
|
||||
@ -16,28 +16,61 @@ sub fill_surface {
|
||||
$self->rotate_points($expolygon, $rotate_vector);
|
||||
|
||||
my $bounding_box = [ $expolygon->bounding_box ];
|
||||
my $flow_width_res = $params{flow_width} / $Slic3r::resolution;
|
||||
my $distance_between_lines = $flow_width_res / $params{density};
|
||||
$bounding_box->[X1] += scale 0.1;
|
||||
$bounding_box->[X2] -= scale 0.1;
|
||||
|
||||
my $min_spacing = scale $params{flow_width};
|
||||
my $distance_between_lines = $min_spacing / $params{density};
|
||||
my $line_oscillation = $distance_between_lines - $min_spacing;
|
||||
|
||||
my $number_of_lines = int(($bounding_box->[X2] - $bounding_box->[X1]) / $distance_between_lines) + 1;
|
||||
my $extra_space = ($bounding_box->[X2] - $bounding_box->[X1]) % $distance_between_lines;
|
||||
$distance_between_lines += $extra_space / ($number_of_lines - 1) if $number_of_lines > 1;
|
||||
my $flow_ratio = $distance_between_lines / ($min_spacing / $params{density});
|
||||
|
||||
my @paths = ();
|
||||
my $x = $bounding_box->[X1];
|
||||
my $is_line_pattern = $self->isa('Slic3r::Fill::Line');
|
||||
my $i = 0;
|
||||
while ($x < $bounding_box->[X2]) {
|
||||
for (my $i = 0; $i < $number_of_lines; $i++) {
|
||||
my $vertical_line = [ [$x, $bounding_box->[Y2]], [$x, $bounding_box->[Y1]] ];
|
||||
if ($is_line_pattern && $i % 2) {
|
||||
$vertical_line->[A][X] -= ($distance_between_lines - $flow_width_res);
|
||||
$vertical_line->[B][X] += ($distance_between_lines - $flow_width_res);
|
||||
$vertical_line->[A][X] -= $line_oscillation;
|
||||
$vertical_line->[B][X] += $line_oscillation;
|
||||
}
|
||||
push @paths, @{ $expolygon->clip_line($vertical_line) };
|
||||
$x += int($distance_between_lines);
|
||||
$i++;
|
||||
$x += $distance_between_lines;
|
||||
}
|
||||
|
||||
# connect lines
|
||||
{
|
||||
my $collection = Slic3r::ExtrusionPath::Collection->new(
|
||||
paths => [ map Slic3r::ExtrusionPath->cast([ @$_ ], role => 'bogus'), @paths ],
|
||||
);
|
||||
@paths = ();
|
||||
|
||||
my $can_connect = $is_line_pattern
|
||||
? sub { $_[X] <= (abs((($_[2][Y] - $bounding_box->[Y1])*(2 * $line_oscillation)/($bounding_box->[Y2] - $bounding_box->[Y1])) - $line_oscillation) + $distance_between_lines) && $_[Y] <= $distance_between_lines * 5 }
|
||||
: sub { ($_[X] <= $distance_between_lines) && ($_[Y] <= $distance_between_lines * 5) };
|
||||
|
||||
foreach my $path ($collection->shortest_path) {
|
||||
if (@paths) {
|
||||
my @distance = map abs($paths[-1][-1][$_] - $path->points->[0][$_]), (X,Y);
|
||||
|
||||
# TODO: we should also check that both points are on a fill_boundary to avoid
|
||||
# connecting paths on the boundaries of internal regions
|
||||
if ($can_connect->(@distance, $paths[-1][-1])) {
|
||||
push @{$paths[-1]}, @{$path->points};
|
||||
next;
|
||||
}
|
||||
}
|
||||
push @paths, [@{$path->points}];
|
||||
}
|
||||
}
|
||||
|
||||
# paths must be rotated back
|
||||
$self->rotate_points_back(\@paths, $rotate_vector);
|
||||
|
||||
return @paths;
|
||||
return { flow_ratio => $flow_ratio }, @paths;
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -272,6 +272,7 @@ sub discover_horizontal_shells {
|
||||
my $new_internal_solid = intersection_ex(
|
||||
$surfaces_p,
|
||||
[ map $_->p, grep $_->surface_type =~ /internal/, @neighbor_surfaces ],
|
||||
undef, 1,
|
||||
);
|
||||
next if !@$new_internal_solid;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user