2011-10-06 11:43:32 +00:00
|
|
|
package Slic3r::Fill::Base;
|
|
|
|
use Moo;
|
|
|
|
|
2012-10-30 13:15:48 +00:00
|
|
|
use Slic3r::Geometry qw(PI);
|
2011-10-06 11:43:32 +00:00
|
|
|
|
2012-10-30 13:25:48 +00:00
|
|
|
has 'layer_id' => (is => 'rw');
|
2012-07-27 19:13:03 +00:00
|
|
|
has 'angle' => (is => 'rw', default => sub { $Slic3r::Config->fill_angle });
|
2013-04-18 15:34:21 +00:00
|
|
|
has 'bounding_box' => (is => 'ro', required => 1);
|
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
|
|
|
|
|
|
|
# set infill angle
|
|
|
|
my (@rotate, @shift);
|
2012-06-23 20:43:23 +00:00
|
|
|
$rotate[0] = Slic3r::Geometry::deg2rad($self->angle);
|
2013-04-18 15:34:21 +00:00
|
|
|
$rotate[1] = Slic3r::Geometry::bounding_box_center($self->bounding_box);
|
2011-10-06 11:43:32 +00:00
|
|
|
@shift = @{$rotate[1]};
|
|
|
|
|
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}];
|
2012-06-23 20:43:23 +00:00
|
|
|
$rotate[0] = Slic3r::Geometry::deg2rad($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
|
2012-02-19 11:03:36 +00:00
|
|
|
if (defined $surface->bridge_angle) {
|
2011-10-07 17:07:57 +00:00
|
|
|
Slic3r::debugf "Filling bridge with angle %d\n", $surface->bridge_angle;
|
|
|
|
$rotate[0] = Slic3r::Geometry::deg2rad($surface->bridge_angle);
|
|
|
|
}
|
2011-10-06 11:43:32 +00:00
|
|
|
|
|
|
|
@shift = @{ +(Slic3r::Geometry::rotate_points(@rotate, \@shift))[0] };
|
|
|
|
return [\@rotate, \@shift];
|
|
|
|
}
|
|
|
|
|
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
|
2013-04-18 15:36:06 +00:00
|
|
|
$expolygon->rotate(@{$rotate_vector->[0]});
|
|
|
|
$expolygon->translate(@{$rotate_vector->[1]});
|
2011-10-06 11:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub rotate_points_back {
|
|
|
|
my $self = shift;
|
|
|
|
my ($paths, $rotate_vector) = @_;
|
2013-04-18 15:36:06 +00:00
|
|
|
my @rotate = (-$rotate_vector->[0][0], $rotate_vector->[0][1]);
|
|
|
|
my $shift = [ map -$_, @{$rotate_vector->[1]} ];
|
2011-10-06 11:43:32 +00:00
|
|
|
|
2013-04-18 15:36:06 +00:00
|
|
|
@$paths = map [ Slic3r::Geometry::rotate_points(@rotate, @$_) ],
|
|
|
|
map [ Slic3r::Geometry::move_points($shift, @$_) ], @$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;
|