diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 25fb1c1ff..e4402d646 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1201,7 +1201,7 @@ sub object_cut_dialog { if (my @new_objects = $dlg->NewModelObjects) { $self->remove($obj_idx); - $self->load_model_objects(@new_objects); + $self->load_model_objects(grep defined($_), @new_objects); $self->arrange; } } diff --git a/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm b/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm index a2d740f91..4d9819a50 100644 --- a/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm +++ b/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm @@ -125,7 +125,8 @@ sub new { sub perform_cut { my ($self) = @_; - my ($upper_object, $lower_object) = $self->{model_object}->cut($self->{cut_options}{z}); + my ($new_model, $upper_object, $lower_object) = $self->{model_object}->cut($self->{cut_options}{z}); + $self->{new_model} = $new_model; $self->{new_model_objects} = []; if ($self->{cut_options}{keep_upper} && defined $upper_object) { push @{$self->{new_model_objects}}, $upper_object; diff --git a/lib/Slic3r/Model.pm b/lib/Slic3r/Model.pm index 3a0d60547..24f17016c 100644 --- a/lib/Slic3r/Model.pm +++ b/lib/Slic3r/Model.pm @@ -553,14 +553,12 @@ sub print_info { sub cut { my ($self, $z) = @_; - # clone this one - my $upper = $self->model->add_object($self); - my $lower = $self->model->add_object($self); - - foreach my $instance (@{$self->instances}) { - $upper->add_instance(offset => Slic3r::Pointf->new(@{$instance->offset})); - $lower->add_instance(offset => Slic3r::Pointf->new(@{$instance->offset})); - } + # clone this one to duplicate instances, materials etc. + my $model = Slic3r::Model->new; + my $upper = $model->add_object($self); + my $lower = $model->add_object($self); + $upper->clear_volumes; + $lower->clear_volumes; foreach my $volume (@{$self->volumes}) { if ($volume->modifier) { @@ -584,7 +582,7 @@ sub cut { ); } if ($lower_mesh->facets_count > 0) { - $lower->add_volume( + $lower->add_volume( material_id => $volume->material_id, mesh => $lower_mesh, modifier => $volume->modifier, @@ -595,7 +593,7 @@ sub cut { $upper = undef if !@{$upper->volumes}; $lower = undef if !@{$lower->volumes}; - return ($upper, $lower); + return ($model, $upper, $lower); } package Slic3r::Model::Volume;