2011-10-06 11:43:32 +00:00
|
|
|
|
package Slic3r::Fill::Base;
|
|
|
|
|
use Moo;
|
|
|
|
|
|
2014-04-21 21:21:15 +00:00
|
|
|
|
use Slic3r::Geometry qw(PI rad2deg);
|
2011-10-06 11:43:32 +00:00
|
|
|
|
|
2012-10-30 13:25:48 +00:00
|
|
|
|
has 'layer_id' => (is => 'rw');
|
2014-04-21 21:21:15 +00:00
|
|
|
|
has 'angle' => (is => 'rw'); # in radians, ccw, 0 = East
|
2013-11-26 17:46:48 +00:00
|
|
|
|
has 'bounding_box' => (is => 'ro', required => 0); # Slic3r::Geometry::BoundingBox object
|
2011-10-06 11:43:32 +00:00
|
|
|
|
|
2012-04-16 09:55:14 +00:00
|
|
|
|
sub angles () { [0, PI/2] }
|
|
|
|
|
|
2011-10-06 11:43:32 +00:00
|
|
|
|
sub infill_direction {
|
|
|
|
|
my $self = shift;
|
2011-10-07 17:07:57 +00:00
|
|
|
|
my ($surface) = @_;
|
2011-10-06 11:43:32 +00:00
|
|
|
|
|
2013-12-24 11:03:30 +00:00
|
|
|
|
if (!defined $self->angle) {
|
|
|
|
|
warn "Using undefined infill angle";
|
|
|
|
|
$self->angle(0);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-06 11:43:32 +00:00
|
|
|
|
# set infill angle
|
2014-04-21 21:21:15 +00:00
|
|
|
|
my (@rotate);
|
|
|
|
|
$rotate[0] = $self->angle;
|
2013-11-26 17:46:48 +00:00
|
|
|
|
$rotate[1] = $self->bounding_box
|
2014-01-07 11:48:09 +00:00
|
|
|
|
? $self->bounding_box->center
|
|
|
|
|
: $surface->expolygon->bounding_box->center;
|
2014-04-21 21:21:15 +00:00
|
|
|
|
my $shift = $rotate[1]->clone;
|
2011-10-06 11:43:32 +00:00
|
|
|
|
|
2012-10-30 13:25:48 +00:00
|
|
|
|
if (defined $self->layer_id) {
|
2012-02-19 11:03:36 +00:00
|
|
|
|
# alternate fill direction
|
2013-03-17 00:10:40 +00:00
|
|
|
|
my $layer_num = $self->layer_id / $surface->thickness_layers;
|
2012-04-16 09:55:14 +00:00
|
|
|
|
my $angle = $self->angles->[$layer_num % @{$self->angles}];
|
2014-04-21 21:21:15 +00:00
|
|
|
|
$rotate[0] = $self->angle + $angle if $angle;
|
2011-10-06 11:43:32 +00:00
|
|
|
|
}
|
2012-02-19 11:03:36 +00:00
|
|
|
|
|
2011-10-07 17:07:57 +00:00
|
|
|
|
# use bridge angle
|
2014-04-21 21:21:15 +00:00
|
|
|
|
if ($surface->bridge_angle >= 0) {
|
|
|
|
|
Slic3r::debugf "Filling bridge with angle %d\n", rad2deg($surface->bridge_angle);
|
|
|
|
|
$rotate[0] = $surface->bridge_angle;
|
2011-10-07 17:07:57 +00:00
|
|
|
|
}
|
2011-10-06 11:43:32 +00:00
|
|
|
|
|
2014-04-21 21:21:15 +00:00
|
|
|
|
$rotate[0] += PI/2;
|
|
|
|
|
$shift->rotate(@rotate);
|
|
|
|
|
return [\@rotate, $shift];
|
2011-10-06 11:43:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-18 14:48:26 +00:00
|
|
|
|
# this method accepts any object that implements rotate() and translate()
|
2011-10-06 11:43:32 +00:00
|
|
|
|
sub rotate_points {
|
|
|
|
|
my $self = shift;
|
2011-11-13 17:14:02 +00:00
|
|
|
|
my ($expolygon, $rotate_vector) = @_;
|
2011-10-06 11:43:32 +00:00
|
|
|
|
|
2013-04-18 15:34:21 +00:00
|
|
|
|
# rotate points
|
2014-04-21 21:21:15 +00:00
|
|
|
|
my ($rotate, $shift) = @$rotate_vector;
|
|
|
|
|
$rotate = [ -$rotate->[0], $rotate->[1] ];
|
|
|
|
|
$expolygon->rotate(@$rotate);
|
|
|
|
|
$expolygon->translate(@$shift);
|
2011-10-06 11:43:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub rotate_points_back {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
my ($paths, $rotate_vector) = @_;
|
2014-04-21 21:21:15 +00:00
|
|
|
|
|
|
|
|
|
my ($rotate, $shift) = @$rotate_vector;
|
|
|
|
|
$shift = [ map -$_, @$shift ];
|
2011-10-06 11:43:32 +00:00
|
|
|
|
|
2013-07-16 15:13:01 +00:00
|
|
|
|
$_->translate(@$shift) for @$paths;
|
2014-04-21 21:21:15 +00:00
|
|
|
|
$_->rotate(@$rotate) for @$paths;
|
2011-10-06 11:43:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-17 19:29:06 +00:00
|
|
|
|
sub adjust_solid_spacing {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
my %params = @_;
|
|
|
|
|
|
|
|
|
|
my $number_of_lines = int($params{width} / $params{distance}) + 1;
|
|
|
|
|
return $params{distance} if $number_of_lines <= 1;
|
|
|
|
|
|
|
|
|
|
my $extra_space = $params{width} % $params{distance};
|
|
|
|
|
return $params{distance} + $extra_space / ($number_of_lines - 1);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-06 11:43:32 +00:00
|
|
|
|
1;
|