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 {
|
||||
my $self = shift;
|
||||
my @shift = @_;
|
||||
|
@ -12,7 +12,7 @@ BEGIN {
|
||||
use Getopt::Long qw(:config no_auto_abbrev);
|
||||
use PDF::API2;
|
||||
use Slic3r;
|
||||
use Slic3r::Geometry qw(unscale X Y);
|
||||
use Slic3r::Geometry qw(scale unscale X Y);
|
||||
|
||||
use constant mm => 25.4 / 72;
|
||||
|
||||
@ -31,16 +31,21 @@ my %opt = ();
|
||||
# prepare config
|
||||
my $config = Slic3r::Config->new;
|
||||
$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
|
||||
my $sprint = Slic3r::Print::Simple->new;
|
||||
$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;
|
||||
|
||||
# compute sizes
|
||||
my $bb = $print->bounding_box;
|
||||
my $mediabox = [ map unscale($_)/mm, @{$bb->size} ];
|
||||
my $size = $bb->size;
|
||||
my $mediabox = [ map unscale($_)/mm, @{$size} ];
|
||||
|
||||
# init PDF
|
||||
my $pdf = PDF::API2->new();
|
||||
@ -48,13 +53,19 @@ my %opt = ();
|
||||
|
||||
# slice and build output geometry
|
||||
$_->slice for @{$print->objects};
|
||||
foreach my $layer (@{ $print->objects->[0]->layers }) {
|
||||
foreach my $object (@{ $print->objects }) {
|
||||
my $shift = $object->_shifted_copies->[0];
|
||||
$shift->translate(map $_/2, @$size);
|
||||
|
||||
foreach my $layer (@{ $object->layers }) {
|
||||
my $page = $pdf->page();
|
||||
$page->mediabox(@$mediabox);
|
||||
my $content = $page->gfx;
|
||||
$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;
|
||||
foreach my $hole (@{$expolygon->holes}) {
|
||||
@ -64,6 +75,7 @@ my %opt = ();
|
||||
$content->fill; # non-zero by default
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# write output file
|
||||
my $output_file = $opt{output_file};
|
||||
|
Loading…
Reference in New Issue
Block a user