diff --git a/lib/Slic3r/GUI/Plater/3D.pm b/lib/Slic3r/GUI/Plater/3D.pm index a2b72033b..c80da919f 100644 --- a/lib/Slic3r/GUI/Plater/3D.pm +++ b/lib/Slic3r/GUI/Plater/3D.pm @@ -8,7 +8,9 @@ use Slic3r::Geometry qw(); use Slic3r::Geometry::Clipper qw(); use Wx qw(:misc :pen :brush :sizer :font :cursor wxTAB_TRAVERSAL); use Wx::Event qw(); -use base 'Slic3r::GUI::PreviewCanvas'; +use base qw(Slic3r::GUI::PreviewCanvas Class::Accessor); + +__PACKAGE__->mk_accessors(qw(_volumes _volumes_inv)); sub new { my $class = shift; @@ -29,8 +31,8 @@ sub new { my $obj_idx = undef; if ($volume_idx != -1) { - $obj_idx = $self->{_volumes_inv}{$volume_idx}; - $self->volumes->[$_]->selected(1) for @{$self->{_volumes}{$obj_idx}}; + $obj_idx = $self->_volumes_inv->{$volume_idx}; + $self->volumes->[$_]->selected(1) for @{$self->_volumes->{$obj_idx}}; $self->Refresh; } $self->{on_select_object}->($obj_idx) @@ -39,14 +41,14 @@ sub new { $self->on_hover(sub { my ($volume_idx) = @_; - my $obj_idx = $self->{_volumes_inv}{$volume_idx}; - $self->volumes->[$_]->hover(1) for @{$self->{_volumes}{$obj_idx}}; + my $obj_idx = $self->_volumes_inv->{$volume_idx}; + $self->volumes->[$_]->hover(1) for @{$self->_volumes->{$obj_idx}}; }); $self->on_move(sub { my ($volume_idx) = @_; my $volume = $self->volumes->[$volume_idx]; - my $obj_idx = $self->{_volumes_inv}{$volume_idx}; + my $obj_idx = $self->_volumes_inv->{$volume_idx}; my $model_object = $self->{model}->get_object($obj_idx); $model_object ->instances->[$volume->instance_idx] @@ -84,8 +86,8 @@ sub set_on_instance_moved { sub update { my ($self) = @_; - $self->{_volumes} = {}; # obj_idx => [ volume_idx, volume_idx ] - $self->{_volumes_inv} = {}; # volume_idx => obj_idx + $self->_volumes({}); # obj_idx => [ volume_idx, volume_idx ] + $self->_volumes_inv({}); # volume_idx => obj_idx $self->reset_objects; $self->update_bed_size; @@ -95,8 +97,8 @@ sub update { my @volume_idxs = $self->load_object($model_object, 1); # store mapping between canvas volumes and model objects - $self->{_volumes}{$obj_idx} = [ @volume_idxs ]; - $self->{_volumes_inv}{$_} = $obj_idx for @volume_idxs; + $self->_volumes->{$obj_idx} = [ @volume_idxs ]; + $self->_volumes_inv->{$_} = $obj_idx for @volume_idxs; if ($self->{objects}[$obj_idx]->selected) { $self->select_volume($_) for @volume_idxs; diff --git a/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm b/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm index 24a580ab4..e332ba65a 100644 --- a/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm +++ b/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm @@ -87,6 +87,7 @@ sub new { my $canvas; if ($Slic3r::GUI::have_OpenGL) { $canvas = $self->{canvas} = Slic3r::GUI::PreviewCanvas->new($self); + $canvas->enable_cutting(1); $canvas->load_object($self->{model_object}); $canvas->set_auto_bed_shape; $canvas->SetSize([500,500]); diff --git a/lib/Slic3r/GUI/PreviewCanvas.pm b/lib/Slic3r/GUI/PreviewCanvas.pm index 9bba47cc3..8cbd7e16f 100644 --- a/lib/Slic3r/GUI/PreviewCanvas.pm +++ b/lib/Slic3r/GUI/PreviewCanvas.pm @@ -13,6 +13,7 @@ use Slic3r::Geometry::Clipper qw(offset_ex intersection_pl); use Wx::GLCanvas qw(:all); __PACKAGE__->mk_accessors( qw(_quat _dirty init + enable_cutting enable_picking enable_moving on_hover @@ -256,7 +257,7 @@ sub zoom_to_volume { my ($self, $volume_idx) = @_; my $volume = $self->volumes->[$volume_idx]; - my $bb = $volume->bounding_box; + my $bb = $volume->transformed_bounding_box; $self->zoom_to_bounding_box($bb); } @@ -269,7 +270,7 @@ sub volumes_bounding_box { my ($self) = @_; my $bb = Slic3r::Geometry::BoundingBoxf3->new; - $bb->merge($_->bounding_box) for @{$self->volumes}; + $bb->merge($_->transformed_bounding_box) for @{$self->volumes}; return $bb; } @@ -375,11 +376,12 @@ sub load_object { my $color = [ @{COLORS->[ $color_idx % scalar(@{&COLORS}) ]} ]; push @$color, $volume->modifier ? 0.5 : 1; push @{$self->volumes}, my $v = Slic3r::GUI::PreviewCanvas::Volume->new( + bounding_box => $mesh->bounding_box, group_id => $group_id, instance_idx => $instance_idx, - mesh => $mesh, color => $color, ); + $v->mesh($mesh) if $self->enable_cutting; push @volumes_idx, $#{$self->volumes}; { @@ -419,6 +421,7 @@ sub SetCuttingPlane { my @verts = (); foreach my $volume (@{$self->volumes}) { foreach my $volume (@{$self->volumes}) { + next if !$volume->mesh; my $expolygons = $volume->mesh->slice([ $z - $volume->origin->z ])->[0]; $expolygons = offset_ex([ map @$_, @$expolygons ], scale 0.1); @@ -940,7 +943,8 @@ sub draw_volumes { package Slic3r::GUI::PreviewCanvas::Volume; use Moo; -has 'mesh' => (is => 'ro', required => 1); +has 'mesh' => (is => 'rw', required => 0); # only required for cut contours +has 'bounding_box' => (is => 'ro', required => 1); has 'color' => (is => 'ro', required => 1); has 'group_id' => (is => 'ro', required => 1); has 'instance_idx' => (is => 'ro', default => sub { 0 }); @@ -950,10 +954,10 @@ has 'norms' => (is => 'rw'); has 'selected' => (is => 'rw', default => sub { 0 }); has 'hover' => (is => 'rw', default => sub { 0 }); -sub bounding_box { +sub transformed_bounding_box { my ($self) = @_; - my $bb = $self->mesh->bounding_box; + my $bb = $self->bounding_box; $bb->translate(@{$self->origin}); return $bb; }