mirror of https://github.com/vitalif/Slic3r
Merge branch 'master' into new-support2
commit
400573212a
|
@ -84,6 +84,12 @@ sub wkt {
|
|||
join ',', map "($_)", map { join ',', map "$_->[0] $_->[1]", @$_ } @$self;
|
||||
}
|
||||
|
||||
sub dump_perl {
|
||||
my $self = shift;
|
||||
return sprintf "[%s]",
|
||||
join ',', map "[$_]", map { join ',', map "[$_->[0],$_->[1]]", @$_ } @$self;
|
||||
}
|
||||
|
||||
sub offset {
|
||||
my $self = shift;
|
||||
return Slic3r::Geometry::Clipper::offset($self, @_);
|
||||
|
@ -173,6 +179,14 @@ sub translate {
|
|||
$self;
|
||||
}
|
||||
|
||||
sub align_to_origin {
|
||||
my $self = shift;
|
||||
|
||||
my $bb = $self->bounding_box;
|
||||
$self->translate(-$bb->x_min, -$bb->y_min);
|
||||
$self;
|
||||
}
|
||||
|
||||
sub rotate {
|
||||
my $self = shift;
|
||||
$_->rotate(@_) for @$self;
|
||||
|
|
|
@ -157,18 +157,13 @@ sub make_fill {
|
|||
next SURFACE unless $density > 0;
|
||||
}
|
||||
|
||||
my @paths;
|
||||
{
|
||||
my $f = $self->filler($filler);
|
||||
$f->layer_id($layerm->id);
|
||||
@paths = $f->fill_surface(
|
||||
$surface,
|
||||
density => $density,
|
||||
flow_spacing => $flow_spacing,
|
||||
dont_adjust => $is_bridge,
|
||||
);
|
||||
}
|
||||
my $params = shift @paths;
|
||||
my $f = $self->filler($filler);
|
||||
$f->layer_id($layerm->id);
|
||||
my ($params, @paths) = $f->fill_surface(
|
||||
$surface,
|
||||
density => $density,
|
||||
flow_spacing => $flow_spacing,
|
||||
);
|
||||
|
||||
# ugly hack(tm) to get the right amount of flow (GCode.pm should be fixed)
|
||||
$params->{flow_spacing} = $layerm->extruders->{infill}->bridge_flow->width if $is_bridge;
|
||||
|
|
|
@ -5,7 +5,7 @@ extends 'Slic3r::Fill::Base';
|
|||
|
||||
has 'cache' => (is => 'rw', default => sub {{}});
|
||||
|
||||
use Slic3r::Geometry qw(A B X Y scale unscale scaled_epsilon);
|
||||
use Slic3r::Geometry qw(A B X Y MIN scale unscale scaled_epsilon);
|
||||
|
||||
sub fill_surface {
|
||||
my $self = shift;
|
||||
|
@ -16,72 +16,66 @@ sub fill_surface {
|
|||
my $rotate_vector = $self->infill_direction($surface);
|
||||
$self->rotate_points($expolygon, $rotate_vector);
|
||||
|
||||
my ($expolygon_off) = $expolygon->offset_ex(scale $params{flow_spacing}/2);
|
||||
return {} if !$expolygon_off; # skip some very small polygons (which shouldn't arrive here)
|
||||
my $flow_spacing = $params{flow_spacing};
|
||||
my $min_spacing = scale $params{flow_spacing};
|
||||
my $line_spacing = $min_spacing / $params{density};
|
||||
my $line_oscillation = $line_spacing - $min_spacing;
|
||||
my $is_line_pattern = $self->isa('Slic3r::Fill::Line');
|
||||
my $bounding_box = $expolygon->bounding_box;
|
||||
|
||||
my $flow_spacing = $params{flow_spacing};
|
||||
my $min_spacing = scale $params{flow_spacing};
|
||||
my $distance_between_lines = $min_spacing / $params{density};
|
||||
my $line_oscillation = $distance_between_lines - $min_spacing;
|
||||
my $is_line_pattern = $self->isa('Slic3r::Fill::Line');
|
||||
# define flow spacing according to requested density
|
||||
if ($params{density} == 1 && !$params{dont_adjust}) {
|
||||
$line_spacing = $self->adjust_solid_spacing(
|
||||
width => $bounding_box->size->[X],
|
||||
distance => $line_spacing,
|
||||
);
|
||||
$flow_spacing = unscale $line_spacing;
|
||||
} else {
|
||||
# extend bounding box so that our pattern will be aligned with other layers
|
||||
# $bounding_box->[X1] and [Y1] represent the displacement between new bounding box offset and old one
|
||||
$bounding_box->extents->[X][MIN] -= $bounding_box->x_min;
|
||||
$bounding_box->extents->[Y][MIN] -= $bounding_box->y_min;
|
||||
}
|
||||
|
||||
my $cache_id = sprintf "d%s_s%.2f_a%.2f",
|
||||
$params{density}, $params{flow_spacing}, $rotate_vector->[0][0];
|
||||
|
||||
if (!$self->cache->{$cache_id}) {
|
||||
# compute bounding box
|
||||
my $bounding_box;
|
||||
{
|
||||
my $bb_polygon = $self->bounding_box->polygon;
|
||||
$bb_polygon->scale(sqrt 2);
|
||||
$self->rotate_points($bb_polygon, $rotate_vector);
|
||||
$bounding_box = $bb_polygon->bounding_box;
|
||||
# generate the basic pattern
|
||||
my $i = 0;
|
||||
my $x = $bounding_box->x_min;
|
||||
my $x_max = $bounding_box->x_max + scaled_epsilon;
|
||||
my @vertical_lines = ();
|
||||
while ($x <= $x_max) {
|
||||
my $vertical_line = Slic3r::Line->new([$x, $bounding_box->y_max], [$x, $bounding_box->y_min]);
|
||||
if ($is_line_pattern && $i % 2) {
|
||||
$vertical_line->[A][X] += $line_oscillation;
|
||||
$vertical_line->[B][X] -= $line_oscillation;
|
||||
}
|
||||
|
||||
# define flow spacing according to requested density
|
||||
if ($params{density} == 1 && !$params{dont_adjust}) {
|
||||
$distance_between_lines = $self->adjust_solid_spacing(
|
||||
width => $bounding_box->size->[X],
|
||||
distance => $distance_between_lines,
|
||||
);
|
||||
$flow_spacing = unscale $distance_between_lines;
|
||||
}
|
||||
|
||||
# generate the basic pattern
|
||||
my $x = $bounding_box->x_min;
|
||||
my @vertical_lines = ();
|
||||
for (my $i = 0; $x <= $bounding_box->x_max + scaled_epsilon; $i++) {
|
||||
my $vertical_line = Slic3r::Line->new([$x, $bounding_box->y_max], [$x, $bounding_box->y_min]);
|
||||
if ($is_line_pattern && $i % 2) {
|
||||
$vertical_line->[A][X] += $line_oscillation;
|
||||
$vertical_line->[B][X] -= $line_oscillation;
|
||||
}
|
||||
push @vertical_lines, $vertical_line;
|
||||
$x += $distance_between_lines;
|
||||
}
|
||||
|
||||
$self->cache->{$cache_id} = [@vertical_lines];
|
||||
push @vertical_lines, $vertical_line;
|
||||
$i++;
|
||||
$x += $line_spacing;
|
||||
}
|
||||
|
||||
# clip paths against a slightly offsetted expolygon, so that the first and last paths
|
||||
# are kept even if the expolygon has vertical sides
|
||||
my @paths = @{ Boost::Geometry::Utils::polygon_multi_linestring_intersection(
|
||||
+($expolygon->offset_ex(scaled_epsilon))[0], # TODO: we should use all the resulting expolygons and clip the linestrings to a multipolygon object
|
||||
[ @{ $self->cache->{$cache_id} } ],
|
||||
# the minimum offset for preventing edge lines from being clipped is scaled_epsilon;
|
||||
# however we use a larger offset to support expolygons with slightly skewed sides and
|
||||
# not perfectly straight
|
||||
my @paths = @{ Boost::Geometry::Utils::multi_polygon_multi_linestring_intersection(
|
||||
[ $expolygon->offset_ex($line_spacing*0.05) ],
|
||||
[ @vertical_lines ],
|
||||
) };
|
||||
|
||||
# connect lines
|
||||
unless ($params{dont_connect}) {
|
||||
my ($expolygon_off) = $expolygon->offset_ex(scale $params{flow_spacing}/2);
|
||||
my $collection = Slic3r::Polyline::Collection->new(
|
||||
polylines => [ map Slic3r::Polyline->new(@$_), @paths ],
|
||||
);
|
||||
@paths = ();
|
||||
|
||||
my $tolerance = 10 * scaled_epsilon;
|
||||
my $diagonal_distance = $distance_between_lines * 2;
|
||||
my $diagonal_distance = $line_spacing * 2;
|
||||
my $can_connect = $is_line_pattern
|
||||
? sub {
|
||||
($_[X] >= ($distance_between_lines - $line_oscillation) - $tolerance) && ($_[X] <= ($distance_between_lines + $line_oscillation) + $tolerance)
|
||||
($_[X] >= ($line_spacing - $line_oscillation) - $tolerance) && ($_[X] <= ($line_spacing + $line_oscillation) + $tolerance)
|
||||
&& $_[Y] <= $diagonal_distance
|
||||
}
|
||||
: sub { $_[X] <= $diagonal_distance && $_[Y] <= $diagonal_distance };
|
||||
|
|
|
@ -419,8 +419,10 @@ sub process_external_surfaces {
|
|||
|
||||
# detect bridge direction before merging grown surfaces otherwise adjacent bridges
|
||||
# would get merged into a single one while they need different directions
|
||||
# also, supply the original expolygon instead of the grown one, because in case
|
||||
# of very thin (but still working) anchors, the grown expolygon would go beyond them
|
||||
my $angle = $self->id > 0
|
||||
? $self->_detect_bridge_direction($grown)
|
||||
? $self->_detect_bridge_direction($surface->expolygon)
|
||||
: undef;
|
||||
|
||||
push @bottom, $surface->clone(expolygon => $grown, bridge_angle => $angle);
|
||||
|
@ -470,6 +472,7 @@ sub _detect_bridge_direction {
|
|||
my $self = shift;
|
||||
my ($expolygon) = @_;
|
||||
|
||||
my ($grown) = $expolygon->offset_ex(+$self->perimeter_flow->scaled_width);
|
||||
my @lower = @{$self->layer->object->layers->[ $self->id - 1 ]->slices}; # expolygons
|
||||
|
||||
# detect what edges lie on lower slices
|
||||
|
@ -477,7 +480,7 @@ sub _detect_bridge_direction {
|
|||
foreach my $lower (@lower) {
|
||||
# turn bridge contour and holes into polylines and then clip them
|
||||
# with each lower slice's contour
|
||||
my @clipped = map $_->split_at_first_point->clip_with_polygon($lower->contour), @$expolygon;
|
||||
my @clipped = map $_->split_at_first_point->clip_with_polygon($lower->contour), @$grown;
|
||||
if (@clipped == 2) {
|
||||
# If the split_at_first_point() call above happens to split the polygon inside the clipping area
|
||||
# we would get two consecutive polylines instead of a single one, so we use this ugly hack to
|
||||
|
@ -528,7 +531,7 @@ sub _detect_bridge_direction {
|
|||
|
||||
# detect anchors as intersection between our bridge expolygon and the lower slices
|
||||
my $anchors = intersection_ex(
|
||||
[ @$expolygon ],
|
||||
[ @$grown ],
|
||||
[ map @$_, @lower ],
|
||||
undef,
|
||||
1, # safety offset required to avoid Clipper from detecting empty intersection while Boost actually found some @edges
|
||||
|
@ -546,6 +549,7 @@ sub _detect_bridge_direction {
|
|||
|
||||
# generate lines in this direction
|
||||
my $bounding_box = Slic3r::Geometry::BoundingBox->new_from_points([ map @$_, map @$_, @$anchors ]);
|
||||
|
||||
my @lines = ();
|
||||
for (my $x = $bounding_box->x_min; $x <= $bounding_box->x_max; $x += $line_increment) {
|
||||
push @lines, [ [$x, $bounding_box->y_min], [$x, $bounding_box->y_max] ];
|
||||
|
|
56
t/fill.t
56
t/fill.t
|
@ -2,7 +2,7 @@ use Test::More;
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
plan tests => 10;
|
||||
plan tests => 32;
|
||||
|
||||
BEGIN {
|
||||
use FindBin;
|
||||
|
@ -11,6 +11,7 @@ BEGIN {
|
|||
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(scale X Y);
|
||||
use Slic3r::Geometry::Clipper qw(diff_ex);
|
||||
use Slic3r::Surface qw(:types);
|
||||
use Slic3r::Test;
|
||||
|
||||
|
@ -48,6 +49,59 @@ sub scale_points (@) { map [scale $_->[X], scale $_->[Y]], @_ }
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
my $test = sub {
|
||||
my ($expolygon, $flow_spacing) = @_;
|
||||
|
||||
my $filler = Slic3r::Fill::Rectilinear->new(
|
||||
bounding_box => $expolygon->bounding_box,
|
||||
angle => 0,
|
||||
);
|
||||
my $surface = Slic3r::Surface->new(
|
||||
surface_type => S_TYPE_BOTTOM,
|
||||
expolygon => $expolygon,
|
||||
);
|
||||
my ($params, @paths) = $filler->fill_surface($surface, flow_spacing => $flow_spacing, density => 1);
|
||||
|
||||
# check whether any part was left uncovered
|
||||
my @grown_paths = map Slic3r::Polyline->new(@$_)->grow(scale $params->{flow_spacing}/2), @paths;
|
||||
my $uncovered = diff_ex([ @$expolygon ], [ @grown_paths ], 1);
|
||||
|
||||
# ignore very small dots
|
||||
@$uncovered = grep $_->area > (scale $flow_spacing)**2, @$uncovered;
|
||||
|
||||
is scalar(@$uncovered), 0, 'solid surface is fully filled';
|
||||
|
||||
if (0 && @$uncovered) {
|
||||
require "Slic3r/SVG.pm";
|
||||
Slic3r::SVG::output(
|
||||
"uncovered.svg",
|
||||
expolygons => [$expolygon],
|
||||
red_expolygons => $uncovered,
|
||||
);
|
||||
exit;
|
||||
}
|
||||
};
|
||||
|
||||
my $expolygon = Slic3r::ExPolygon->new([
|
||||
[6883102, 9598327.01296997],
|
||||
[6883102, 20327272.01297],
|
||||
[3116896, 20327272.01297],
|
||||
[3116896, 9598327.01296997],
|
||||
]);
|
||||
$test->($expolygon, 0.55);
|
||||
|
||||
for (1..20) {
|
||||
$expolygon->scale(1.05);
|
||||
$test->($expolygon, 0.55);
|
||||
}
|
||||
|
||||
$expolygon = Slic3r::ExPolygon->new(
|
||||
[[59515297,5422499],[59531249,5578697],[59695801,6123186],[59965713,6630228],[60328214,7070685],[60773285,7434379],[61274561,7702115],[61819378,7866770],[62390306,7924789],[62958700,7866744],[63503012,7702244],[64007365,7434357],[64449960,7070398],[64809327,6634999],[65082143,6123325],[65245005,5584454],[65266967,5422499],[66267307,5422499],[66269190,8310081],[66275379,17810072],[66277259,20697500],[65267237,20697500],[65245004,20533538],[65082082,19994444],[64811462,19488579],[64450624,19048208],[64012101,18686514],[63503122,18415781],[62959151,18251378],[62453416,18198442],[62390147,18197355],[62200087,18200576],[61813519,18252990],[61274433,18415918],[60768598,18686517],[60327567,19047892],[59963609,19493297],[59695865,19994587],[59531222,20539379],[59515153,20697500],[58502480,20697500],[58502480,5422499]]
|
||||
);
|
||||
$test->($expolygon, 0.524341649025257);
|
||||
}
|
||||
|
||||
{
|
||||
my $collection = Slic3r::Polyline::Collection->new(polylines => [
|
||||
Slic3r::Polyline->new([0,15], [0,18], [0,20]),
|
||||
|
|
Loading…
Reference in New Issue