Bugfix in utils/pdf-slices.pl, wrong shift caused slices to be outside the media box
This commit is contained in:
parent
26bdbf0210
commit
f9661b02a6
@ -218,6 +218,17 @@ sub center_instances_around_point {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub align_instances_to_origin {
|
||||||
|
my ($self) = @_;
|
||||||
|
|
||||||
|
my $bb = $self->bounding_box;
|
||||||
|
return if !defined $bb;
|
||||||
|
|
||||||
|
my $new_center = $bb->size;
|
||||||
|
$new_center->translate(-$new_center->x/2, -$new_center->y/2); #//
|
||||||
|
$self->center_instances_around_point($new_center);
|
||||||
|
}
|
||||||
|
|
||||||
sub translate {
|
sub translate {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my @shift = @_;
|
my @shift = @_;
|
||||||
|
@ -12,7 +12,7 @@ BEGIN {
|
|||||||
use Getopt::Long qw(:config no_auto_abbrev);
|
use Getopt::Long qw(:config no_auto_abbrev);
|
||||||
use PDF::API2;
|
use PDF::API2;
|
||||||
use Slic3r;
|
use Slic3r;
|
||||||
use Slic3r::Geometry qw(unscale X Y);
|
use Slic3r::Geometry qw(scale unscale X Y);
|
||||||
|
|
||||||
use constant mm => 25.4 / 72;
|
use constant mm => 25.4 / 72;
|
||||||
|
|
||||||
@ -31,16 +31,21 @@ my %opt = ();
|
|||||||
# prepare config
|
# prepare config
|
||||||
my $config = Slic3r::Config->new;
|
my $config = Slic3r::Config->new;
|
||||||
$config->set('layer_height', $opt{layer_height}) if $opt{layer_height};
|
$config->set('layer_height', $opt{layer_height}) if $opt{layer_height};
|
||||||
|
$config->set('print_center', [0,0]);
|
||||||
|
|
||||||
|
# read model
|
||||||
|
my $model = Slic3r::Model->read_from_file(my $input_file = $ARGV[0]);
|
||||||
|
|
||||||
# init print object
|
# init print object
|
||||||
my $sprint = Slic3r::Print::Simple->new;
|
my $sprint = Slic3r::Print::Simple->new;
|
||||||
$sprint->apply_config($config);
|
$sprint->apply_config($config);
|
||||||
$sprint->set_model(Slic3r::Model->read_from_file(my $input_file = $ARGV[0]));
|
$sprint->set_model($model);
|
||||||
my $print = $sprint->_print;
|
my $print = $sprint->_print;
|
||||||
|
|
||||||
# compute sizes
|
# compute sizes
|
||||||
my $bb = $print->bounding_box;
|
my $bb = $print->bounding_box;
|
||||||
my $mediabox = [ map unscale($_)/mm, @{$bb->size} ];
|
my $size = $bb->size;
|
||||||
|
my $mediabox = [ map unscale($_)/mm, @{$size} ];
|
||||||
|
|
||||||
# init PDF
|
# init PDF
|
||||||
my $pdf = PDF::API2->new();
|
my $pdf = PDF::API2->new();
|
||||||
@ -48,20 +53,27 @@ my %opt = ();
|
|||||||
|
|
||||||
# slice and build output geometry
|
# slice and build output geometry
|
||||||
$_->slice for @{$print->objects};
|
$_->slice for @{$print->objects};
|
||||||
foreach my $layer (@{ $print->objects->[0]->layers }) {
|
foreach my $object (@{ $print->objects }) {
|
||||||
my $page = $pdf->page();
|
my $shift = $object->_shifted_copies->[0];
|
||||||
$page->mediabox(@$mediabox);
|
$shift->translate(map $_/2, @$size);
|
||||||
my $content = $page->gfx;
|
|
||||||
$content->fillcolor($color, 1);
|
|
||||||
|
|
||||||
foreach my $expolygon (@{$layer->slices}) {
|
foreach my $layer (@{ $object->layers }) {
|
||||||
$content->poly(map { unscale($_->x)/mm, unscale($_->y)/mm } @{$expolygon->contour}); #)
|
my $page = $pdf->page();
|
||||||
$content->close;
|
$page->mediabox(@$mediabox);
|
||||||
foreach my $hole (@{$expolygon->holes}) {
|
my $content = $page->gfx;
|
||||||
$content->poly(map { unscale($_->x)/mm, unscale($_->y)/mm } @$hole); #)
|
$content->fillcolor($color, 1);
|
||||||
|
|
||||||
|
foreach my $expolygon (@{$layer->slices}) {
|
||||||
|
$expolygon = $expolygon->clone;
|
||||||
|
$expolygon->translate(@$shift);
|
||||||
|
$content->poly(map { unscale($_->x)/mm, unscale($_->y)/mm } @{$expolygon->contour}); #)
|
||||||
$content->close;
|
$content->close;
|
||||||
|
foreach my $hole (@{$expolygon->holes}) {
|
||||||
|
$content->poly(map { unscale($_->x)/mm, unscale($_->y)/mm } @$hole); #)
|
||||||
|
$content->close;
|
||||||
|
}
|
||||||
|
$content->fill; # non-zero by default
|
||||||
}
|
}
|
||||||
$content->fill; # non-zero by default
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user