Preserve position when splitting objects in plater

This commit is contained in:
Alessandro Ranellucci 2012-09-21 15:35:32 +02:00
parent c2b7f40f40
commit f638558167
2 changed files with 9 additions and 6 deletions

View file

@ -6,7 +6,7 @@ use utf8;
use File::Basename qw(basename dirname);
use List::Util qw(max sum);
use Math::ConvexHull qw(convex_hull);
use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2);
use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 MIN MAX);
use Slic3r::Geometry::Clipper qw(JT_ROUND);
use threads::shared qw(shared_clone);
use Wx qw(:bitmap :brush :button :cursor :dialog :filedialog :font :keycode :icon :id :listctrl :misc :panel :pen :sizer :toolbar :window);
@ -456,6 +456,7 @@ sub split_object {
my ($obj_idx, $current_object) = $self->selected_object;
my $current_copies_num = $current_object->instances_count;
my $mesh = $current_object->get_mesh;
$mesh->align_to_origin;
my @new_meshes = $mesh->split_mesh;
if (@new_meshes == 1) {
@ -469,18 +470,20 @@ sub split_object {
$self->remove($obj_idx);
foreach my $mesh (@new_meshes) {
my @extents = $mesh->extents;
my $object = Slic3r::GUI::Plater::Object->new(
name => basename($current_object->input_file),
input_file => $current_object->input_file,
input_file_object_id => undef,
mesh => $mesh,
instances => [ map [0,0], 1..$current_copies_num ],
instances => [ map [$extents[X][MIN], $extents[Y][MIN]], 1..$current_copies_num ],
);
push @{ $self->{objects} }, $object;
$self->object_loaded($#{ $self->{objects} }, no_arrange => 1);
}
$self->arrange;
$self->recenter;
$self->{canvas}->Refresh;
}
sub export_gcode {

View file

@ -355,7 +355,7 @@ sub align_to_origin {
# calculate the displacements needed to
# have lowest value for each axis at coordinate 0
my @extents = $self->bounding_box;
my @extents = $self->extents;
$self->move(map -$extents[$_][MIN], X,Y,Z);
}
@ -379,7 +379,7 @@ sub duplicate {
$self->BUILD;
}
sub bounding_box {
sub extents {
my $self = shift;
my @extents = (map [undef, undef], X,Y,Z);
foreach my $vertex (@{$self->vertices}) {
@ -394,7 +394,7 @@ sub bounding_box {
sub size {
my $self = shift;
my @extents = $self->bounding_box;
my @extents = $self->extents;
return map $extents[$_][MAX] - $extents[$_][MIN], (X,Y,Z);
}