Fix preview after rotation in plater
This commit is contained in:
parent
99c942b5ea
commit
5678cd562c
@ -416,6 +416,9 @@ sub rotate {
|
|||||||
|
|
||||||
my ($obj_idx, $object) = $self->selected_object;
|
my ($obj_idx, $object) = $self->selected_object;
|
||||||
|
|
||||||
|
# we need thumbnail to be computed before allowing rotation
|
||||||
|
return if !$object->thumbnail;
|
||||||
|
|
||||||
if (!defined $angle) {
|
if (!defined $angle) {
|
||||||
$angle = Wx::GetNumberFromUser("", "Enter the rotation angle:", "Rotate", $object->rotate, -364, 364, $self);
|
$angle = Wx::GetNumberFromUser("", "Enter the rotation angle:", "Rotate", $object->rotate, -364, 364, $self);
|
||||||
return if !$angle || $angle == -1;
|
return if !$angle || $angle == -1;
|
||||||
@ -446,7 +449,7 @@ sub arrange {
|
|||||||
my $total_parts = sum(map $_->instances_count, @{$self->{objects}}) or return;
|
my $total_parts = sum(map $_->instances_count, @{$self->{objects}}) or return;
|
||||||
my @size = ();
|
my @size = ();
|
||||||
for my $a (X,Y) {
|
for my $a (X,Y) {
|
||||||
$size[$a] = max(map $_->rotated_size->[$a], @{$self->{objects}});
|
$size[$a] = max(map $_->size->[$a], @{$self->{objects}});
|
||||||
}
|
}
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
@ -756,7 +759,7 @@ sub recenter {
|
|||||||
my $obj = $_;
|
my $obj = $_;
|
||||||
map {
|
map {
|
||||||
my $instance = $_;
|
my $instance = $_;
|
||||||
$instance, [ map $instance->[$_] + $obj->rotated_size->[$_], X,Y ];
|
$instance, [ map $instance->[$_] + $obj->size->[$_], X,Y ];
|
||||||
} @{$obj->instances};
|
} @{$obj->instances};
|
||||||
} @{$self->{objects}},
|
} @{$self->{objects}},
|
||||||
]);
|
]);
|
||||||
@ -1059,6 +1062,7 @@ has 'scale' => (is => 'rw', default => sub { 1 });
|
|||||||
has 'rotate' => (is => 'rw', default => sub { 0 });
|
has 'rotate' => (is => 'rw', default => sub { 0 });
|
||||||
has 'instances' => (is => 'rw', default => sub { [] }); # upward Y axis
|
has 'instances' => (is => 'rw', default => sub { [] }); # upward Y axis
|
||||||
has 'thumbnail' => (is => 'rw');
|
has 'thumbnail' => (is => 'rw');
|
||||||
|
has 'thumbnail_scaling_factor' => (is => 'rw');
|
||||||
|
|
||||||
# statistics
|
# statistics
|
||||||
has 'facets' => (is => 'rw');
|
has 'facets' => (is => 'rw');
|
||||||
@ -1111,6 +1115,7 @@ sub make_thumbnail {
|
|||||||
|
|
||||||
my @points = map [ @$_[X,Y] ], @{$self->model_object->mesh->vertices};
|
my @points = map [ @$_[X,Y] ], @{$self->model_object->mesh->vertices};
|
||||||
my $convex_hull = Slic3r::Polygon->new(convex_hull(\@points));
|
my $convex_hull = Slic3r::Polygon->new(convex_hull(\@points));
|
||||||
|
$self->thumbnail_scaling_factor($params{scaling_factor});
|
||||||
for (@$convex_hull) {
|
for (@$convex_hull) {
|
||||||
@$_ = map $_ * $params{scaling_factor}, @$_;
|
@$_ = map $_ * $params{scaling_factor}, @$_;
|
||||||
}
|
}
|
||||||
@ -1132,6 +1137,8 @@ sub set_rotation {
|
|||||||
if ($self->thumbnail) {
|
if ($self->thumbnail) {
|
||||||
$self->thumbnail->rotate(Slic3r::Geometry::deg2rad($angle - $self->rotate));
|
$self->thumbnail->rotate(Slic3r::Geometry::deg2rad($angle - $self->rotate));
|
||||||
$self->thumbnail->align_to_origin;
|
$self->thumbnail->align_to_origin;
|
||||||
|
my $z_size = $self->size->[Z];
|
||||||
|
$self->size([ (map $_ / $self->thumbnail_scaling_factor, @{$self->thumbnail->size}), $z_size ]);
|
||||||
}
|
}
|
||||||
$self->rotate($angle);
|
$self->rotate($angle);
|
||||||
}
|
}
|
||||||
@ -1150,14 +1157,6 @@ sub set_scale {
|
|||||||
$self->scale($scale);
|
$self->scale($scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub rotated_size {
|
|
||||||
my $self = shift;
|
|
||||||
|
|
||||||
return Slic3r::Polygon->new([0,0], [$self->size->[X], 0], [@{$self->size}], [0, $self->size->[Y]])
|
|
||||||
->rotate(Slic3r::Geometry::deg2rad($self->rotate))
|
|
||||||
->size;
|
|
||||||
}
|
|
||||||
|
|
||||||
package Slic3r::GUI::Plater::ObjectInfoDialog;
|
package Slic3r::GUI::Plater::ObjectInfoDialog;
|
||||||
use Wx qw(:dialog :id :misc :sizer :systemsettings);
|
use Wx qw(:dialog :id :misc :sizer :systemsettings);
|
||||||
use Wx::Event qw(EVT_BUTTON EVT_TEXT_ENTER);
|
use Wx::Event qw(EVT_BUTTON EVT_TEXT_ENTER);
|
||||||
|
@ -20,7 +20,7 @@ our @EXPORT_OK = qw(
|
|||||||
shortest_path collinear scale unscale merge_collinear_lines
|
shortest_path collinear scale unscale merge_collinear_lines
|
||||||
rad2deg_dir bounding_box_center line_intersects_any douglas_peucker
|
rad2deg_dir bounding_box_center line_intersects_any douglas_peucker
|
||||||
polyline_remove_short_segments normal triangle_normal polygon_is_convex
|
polyline_remove_short_segments normal triangle_normal polygon_is_convex
|
||||||
scaled_epsilon bounding_box_3D size_3D
|
scaled_epsilon bounding_box_3D size_3D size_2D
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@ -689,6 +689,14 @@ sub bounding_box_center {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub size_2D {
|
||||||
|
my @bounding_box = bounding_box(@_);
|
||||||
|
return (
|
||||||
|
($bounding_box[X2] - $bounding_box[X1]),
|
||||||
|
($bounding_box[Y2] - $bounding_box[Y1]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
# bounding_box_intersect($d, @a, @b)
|
# bounding_box_intersect($d, @a, @b)
|
||||||
# Return true if the given bounding boxes @a and @b intersect
|
# Return true if the given bounding boxes @a and @b intersect
|
||||||
# in $d dimensions. Used by line_intersection().
|
# in $d dimensions. Used by line_intersection().
|
||||||
|
@ -126,9 +126,7 @@ sub bounding_box {
|
|||||||
|
|
||||||
sub size {
|
sub size {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
return [ Slic3r::Geometry::size_2D($self) ];
|
||||||
my @extents = $self->bounding_box;
|
|
||||||
return [$extents[X2] - $extents[X1], $extents[Y2] - $extents[Y1]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub align_to_origin {
|
sub align_to_origin {
|
||||||
|
Loading…
Reference in New Issue
Block a user