2011-11-13 17:14:02 +00:00
|
|
|
|
package Slic3r::Fill::PlanePath;
|
|
|
|
|
use Moo;
|
|
|
|
|
|
|
|
|
|
extends 'Slic3r::Fill::Base';
|
2014-07-26 14:28:38 +00:00
|
|
|
|
with qw(Slic3r::Fill::WithDirection);
|
2011-11-13 17:14:02 +00:00
|
|
|
|
|
2012-12-31 13:11:15 +00:00
|
|
|
|
use Slic3r::Geometry qw(scale X1 Y1 X2 Y2);
|
2013-11-21 17:16:03 +00:00
|
|
|
|
use Slic3r::Geometry::Clipper qw(intersection_pl);
|
2011-11-13 17:14:02 +00:00
|
|
|
|
|
2014-12-22 09:47:09 +00:00
|
|
|
|
sub angles () { [0] }
|
2011-11-13 17:14:02 +00:00
|
|
|
|
sub multiplier () { 1 }
|
|
|
|
|
|
|
|
|
|
sub process_polyline {}
|
|
|
|
|
|
|
|
|
|
sub fill_surface {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
my ($surface, %params) = @_;
|
|
|
|
|
|
|
|
|
|
# rotate polygons
|
2012-04-09 20:04:57 +00:00
|
|
|
|
my $expolygon = $surface->expolygon->clone;
|
2011-11-13 17:14:02 +00:00
|
|
|
|
my $rotate_vector = $self->infill_direction($surface);
|
|
|
|
|
$self->rotate_points($expolygon, $rotate_vector);
|
|
|
|
|
|
2014-12-22 15:47:35 +00:00
|
|
|
|
my $distance_between_lines = scale($self->spacing) / $params{density} * $self->multiplier;
|
2011-11-13 17:14:02 +00:00
|
|
|
|
|
2014-12-22 10:16:01 +00:00
|
|
|
|
# align infill across layers using the object's bounding box
|
|
|
|
|
my $bb_polygon = $self->bounding_box->polygon;
|
|
|
|
|
$self->rotate_points($bb_polygon, $rotate_vector);
|
|
|
|
|
my $bounding_box = $bb_polygon->bounding_box;
|
2014-12-21 23:18:45 +00:00
|
|
|
|
|
2011-11-13 17:14:02 +00:00
|
|
|
|
(ref $self) =~ /::([^:]+)$/;
|
|
|
|
|
my $path = "Math::PlanePath::$1"->new;
|
2014-12-21 23:18:45 +00:00
|
|
|
|
|
2014-12-22 10:16:01 +00:00
|
|
|
|
my $translate = Slic3r::Point->new(0,0); # vector
|
|
|
|
|
if ($path->x_negative || $path->y_negative) {
|
|
|
|
|
# if the curve extends on both positive and negative coordinate space,
|
|
|
|
|
# center our expolygon around origin
|
|
|
|
|
$translate = $bounding_box->center->negative;
|
|
|
|
|
} else {
|
|
|
|
|
# if the curve does not extend in negative coordinate space,
|
|
|
|
|
# move expolygon entirely in positive coordinate space
|
|
|
|
|
$translate = $bounding_box->min_point->negative;
|
|
|
|
|
}
|
|
|
|
|
$expolygon->translate(@$translate);
|
|
|
|
|
$bounding_box->translate(@$translate);
|
|
|
|
|
|
2014-12-21 23:18:45 +00:00
|
|
|
|
my ($n_lo, $n_hi) = $path->rect_to_n_range(
|
|
|
|
|
map { $_ / $distance_between_lines }
|
2014-12-22 10:16:01 +00:00
|
|
|
|
@{$bounding_box->min_point},
|
|
|
|
|
@{$bounding_box->max_point},
|
2014-12-21 23:18:45 +00:00
|
|
|
|
);
|
2011-11-13 17:14:02 +00:00
|
|
|
|
|
2013-07-05 12:29:57 +00:00
|
|
|
|
my $polyline = Slic3r::Polyline->new(
|
2014-12-21 23:18:45 +00:00
|
|
|
|
map [ map { $_ * $distance_between_lines } $path->n_to_xy($_) ], ($n_lo..$n_hi)
|
2013-07-05 12:29:57 +00:00
|
|
|
|
);
|
2013-10-13 14:07:14 +00:00
|
|
|
|
return {} if @$polyline <= 1;
|
2011-11-13 17:14:02 +00:00
|
|
|
|
|
|
|
|
|
$self->process_polyline($polyline, $bounding_box);
|
|
|
|
|
|
2013-11-21 17:16:03 +00:00
|
|
|
|
my @paths = @{intersection_pl([$polyline], \@$expolygon)};
|
2011-11-13 17:14:02 +00:00
|
|
|
|
|
|
|
|
|
if (0) {
|
|
|
|
|
require "Slic3r/SVG.pm";
|
2012-11-01 10:34:53 +00:00
|
|
|
|
Slic3r::SVG::output("fill.svg",
|
2014-12-22 10:16:01 +00:00
|
|
|
|
no_arrows => 1,
|
|
|
|
|
polygons => \@$expolygon,
|
2014-12-22 10:37:28 +00:00
|
|
|
|
green_polygons => [ $bounding_box->polygon ],
|
|
|
|
|
polylines => [ $polyline ],
|
|
|
|
|
red_polylines => \@paths,
|
2011-11-13 17:14:02 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-21 23:18:45 +00:00
|
|
|
|
# paths must be repositioned and rotated back
|
2014-12-22 10:16:01 +00:00
|
|
|
|
$_->translate(@{$translate->negative}) for @paths;
|
2011-11-13 17:14:02 +00:00
|
|
|
|
$self->rotate_points_back(\@paths, $rotate_vector);
|
|
|
|
|
|
2014-12-22 15:47:35 +00:00
|
|
|
|
return @paths;
|
2011-11-13 17:14:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-21 22:43:53 +00:00
|
|
|
|
|
|
|
|
|
package Slic3r::Fill::ArchimedeanChords;
|
|
|
|
|
use Moo;
|
|
|
|
|
extends 'Slic3r::Fill::PlanePath';
|
|
|
|
|
use Math::PlanePath::ArchimedeanChords;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package Slic3r::Fill::Flowsnake;
|
|
|
|
|
use Moo;
|
|
|
|
|
extends 'Slic3r::Fill::PlanePath';
|
|
|
|
|
use Math::PlanePath::Flowsnake;
|
|
|
|
|
use Slic3r::Geometry qw(X);
|
|
|
|
|
|
|
|
|
|
# Sorry, this fill is currently broken.
|
|
|
|
|
|
|
|
|
|
sub process_polyline {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
my ($polyline, $bounding_box) = @_;
|
|
|
|
|
|
|
|
|
|
$_->[X] += $bounding_box->center->[X] for @$polyline;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package Slic3r::Fill::HilbertCurve;
|
|
|
|
|
use Moo;
|
|
|
|
|
extends 'Slic3r::Fill::PlanePath';
|
|
|
|
|
use Math::PlanePath::HilbertCurve;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package Slic3r::Fill::OctagramSpiral;
|
|
|
|
|
use Moo;
|
|
|
|
|
extends 'Slic3r::Fill::PlanePath';
|
|
|
|
|
use Math::PlanePath::OctagramSpiral;
|
|
|
|
|
|
|
|
|
|
sub multiplier () { sqrt(2) }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-11-13 17:14:02 +00:00
|
|
|
|
1;
|