Fix preview after rotation in plater

This commit is contained in:
Alessandro Ranellucci 2012-11-19 17:39:16 +01:00
parent 99c942b5ea
commit 5678cd562c
3 changed files with 19 additions and 14 deletions

View File

@ -416,6 +416,9 @@ sub rotate {
my ($obj_idx, $object) = $self->selected_object;
# we need thumbnail to be computed before allowing rotation
return if !$object->thumbnail;
if (!defined $angle) {
$angle = Wx::GetNumberFromUser("", "Enter the rotation angle:", "Rotate", $object->rotate, -364, 364, $self);
return if !$angle || $angle == -1;
@ -446,7 +449,7 @@ sub arrange {
my $total_parts = sum(map $_->instances_count, @{$self->{objects}}) or return;
my @size = ();
for my $a (X,Y) {
$size[$a] = max(map $_->rotated_size->[$a], @{$self->{objects}});
$size[$a] = max(map $_->size->[$a], @{$self->{objects}});
}
eval {
@ -756,7 +759,7 @@ sub recenter {
my $obj = $_;
map {
my $instance = $_;
$instance, [ map $instance->[$_] + $obj->rotated_size->[$_], X,Y ];
$instance, [ map $instance->[$_] + $obj->size->[$_], X,Y ];
} @{$obj->instances};
} @{$self->{objects}},
]);
@ -1059,6 +1062,7 @@ has 'scale' => (is => 'rw', default => sub { 1 });
has 'rotate' => (is => 'rw', default => sub { 0 });
has 'instances' => (is => 'rw', default => sub { [] }); # upward Y axis
has 'thumbnail' => (is => 'rw');
has 'thumbnail_scaling_factor' => (is => 'rw');
# statistics
has 'facets' => (is => 'rw');
@ -1111,6 +1115,7 @@ sub make_thumbnail {
my @points = map [ @$_[X,Y] ], @{$self->model_object->mesh->vertices};
my $convex_hull = Slic3r::Polygon->new(convex_hull(\@points));
$self->thumbnail_scaling_factor($params{scaling_factor});
for (@$convex_hull) {
@$_ = map $_ * $params{scaling_factor}, @$_;
}
@ -1132,6 +1137,8 @@ sub set_rotation {
if ($self->thumbnail) {
$self->thumbnail->rotate(Slic3r::Geometry::deg2rad($angle - $self->rotate));
$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);
}
@ -1150,14 +1157,6 @@ sub set_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;
use Wx qw(:dialog :id :misc :sizer :systemsettings);
use Wx::Event qw(EVT_BUTTON EVT_TEXT_ENTER);

View File

@ -20,7 +20,7 @@ our @EXPORT_OK = qw(
shortest_path collinear scale unscale merge_collinear_lines
rad2deg_dir bounding_box_center line_intersects_any douglas_peucker
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)
# Return true if the given bounding boxes @a and @b intersect
# in $d dimensions. Used by line_intersection().

View File

@ -126,9 +126,7 @@ sub bounding_box {
sub size {
my $self = shift;
my @extents = $self->bounding_box;
return [$extents[X2] - $extents[X1], $extents[Y2] - $extents[Y1]];
return [ Slic3r::Geometry::size_2D($self) ];
}
sub align_to_origin {