Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --rotate-x and --rotate-y to slic3r.pl command line parsing #4938

Merged
merged 3 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion lib/Slic3r/Print/Simple.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ has 'rotate' => (
default => sub { 0 },
);

has 'rotate_x' => (
is => 'rw',
default => sub { 0 },
);

has 'rotate_y' => (
is => 'rw',
default => sub { 0 },
);

has 'duplicate_grid' => (
is => 'rw',
default => sub { [1,1] },
Expand Down Expand Up @@ -75,9 +85,24 @@ sub set_model {
my $need_arrange = $model->add_default_instances && ! $self->dont_arrange;

# apply scaling and rotation supplied from command line if any
foreach my $instance (map @{$_->instances}, @{$model->objects}) {
foreach my $model_object (@{$model->objects}) {
foreach my $instance (@{$model_object->instances}) {
$instance->set_scaling_factor($instance->scaling_factor * $self->scale);
$instance->set_rotation($instance->rotation + $self->rotate);
#$instance->set_x_rotation($instance->x_rotation + $self->rotate_x);
#$instance->set_y_rotation($instance->y_rotation + $self->rotate_y);
if ($self->rotate_x != 0 || $self->rotate_y != 0) {
$model_object->transform_by_instance($instance, 1);
if ($self->rotate_x != 0) {
$model_object->rotate($self->rotate_x, X);
}
if ($self->rotate_y != 0) {
$model_object->rotate($self->rotate_y, Y);
}
# realign object to Z = 0
$model_object->center_around_origin;
}
}
}

my $bed_shape = $self->_print->config->bed_shape;
Expand Down
8 changes: 7 additions & 1 deletion slic3r.pl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ BEGIN

'scale=f' => \$opt{scale},
'rotate=f' => \$opt{rotate},
'rotate-x=f' => \$opt{rotate_x},
'rotate-y=f' => \$opt{rotate_y},
'duplicate=i' => \$opt{duplicate},
'duplicate-grid=s' => \$opt{duplicate_grid},
'print-center=s' => \$opt{print_center},
Expand Down Expand Up @@ -259,6 +261,8 @@ BEGIN
my $sprint = Slic3r::Print::Simple->new(
scale => $opt{scale} // 1,
rotate => deg2rad($opt{rotate} // 0),
rotate_x => deg2rad($opt{rotate_x} // 0),
rotate_y => deg2rad($opt{rotate_y} // 0),
duplicate => $opt{duplicate} // 1,
duplicate_grid => $opt{duplicate_grid} // [1,1],
print_center => $opt{print_center},
Expand Down Expand Up @@ -561,7 +565,9 @@ sub usage {

Transform options:
--scale Factor for scaling input object (default: 1)
--rotate Rotation angle in degrees (0-360, default: 0)
--rotate Rotation angle in degrees around Z (default: 0)
--rotate-x Rotation angle in degrees around X (default: 0)
--rotate-y Rotation angle in degrees around Y (default: 0)
--duplicate Number of items with auto-arrange (1+, default: 1)
--duplicate-grid Number of items with grid arrangement (default: 1,1)
--duplicate-distance Distance in mm between copies (default: $config->{duplicate_distance})
Expand Down