Live 3D toolpaths preview.
This commit is contained in:
parent
3648bbd6d4
commit
f2818ddbe0
4 changed files with 146 additions and 6 deletions
|
@ -15,6 +15,7 @@ use Slic3r::GUI::Plater;
|
||||||
use Slic3r::GUI::Plater::2D;
|
use Slic3r::GUI::Plater::2D;
|
||||||
use Slic3r::GUI::Plater::2DToolpaths;
|
use Slic3r::GUI::Plater::2DToolpaths;
|
||||||
use Slic3r::GUI::Plater::3D;
|
use Slic3r::GUI::Plater::3D;
|
||||||
|
use Slic3r::GUI::Plater::3DPreview;
|
||||||
use Slic3r::GUI::Plater::ObjectPartsPanel;
|
use Slic3r::GUI::Plater::ObjectPartsPanel;
|
||||||
use Slic3r::GUI::Plater::ObjectCutDialog;
|
use Slic3r::GUI::Plater::ObjectCutDialog;
|
||||||
use Slic3r::GUI::Plater::ObjectSettingsDialog;
|
use Slic3r::GUI::Plater::ObjectSettingsDialog;
|
||||||
|
|
|
@ -1069,8 +1069,12 @@ sub load_print_object_toolpaths {
|
||||||
|
|
||||||
my $obb = $object->bounding_box;
|
my $obb = $object->bounding_box;
|
||||||
my $bb = Slic3r::Geometry::BoundingBoxf3->new;
|
my $bb = Slic3r::Geometry::BoundingBoxf3->new;
|
||||||
$bb->merge_point(Slic3r::Pointf3->new_unscale(@{$obb->min_point}, 0));
|
foreach my $copy (@{ $object->_shifted_copies }) {
|
||||||
$bb->merge_point(Slic3r::Pointf3->new_unscale(@{$obb->max_point}, $object->size->z));
|
my $cbb = $obb->clone;
|
||||||
|
$cbb->translate(@$copy);
|
||||||
|
$bb->merge_point(Slic3r::Pointf3->new_unscale(@{$cbb->min_point}, 0));
|
||||||
|
$bb->merge_point(Slic3r::Pointf3->new_unscale(@{$cbb->max_point}, $object->size->z));
|
||||||
|
}
|
||||||
|
|
||||||
push @{$self->volumes}, Slic3r::GUI::3DScene::Volume->new(
|
push @{$self->volumes}, Slic3r::GUI::3DScene::Volume->new(
|
||||||
bounding_box => $bb,
|
bounding_box => $bb,
|
||||||
|
|
|
@ -11,7 +11,7 @@ use Wx qw(:button :cursor :dialog :filedialog :keycode :icon :font :id :listctrl
|
||||||
:panel :sizer :toolbar :window wxTheApp :notebook);
|
:panel :sizer :toolbar :window wxTheApp :notebook);
|
||||||
use Wx::Event qw(EVT_BUTTON EVT_COMMAND EVT_KEY_DOWN EVT_LIST_ITEM_ACTIVATED
|
use Wx::Event qw(EVT_BUTTON EVT_COMMAND EVT_KEY_DOWN EVT_LIST_ITEM_ACTIVATED
|
||||||
EVT_LIST_ITEM_DESELECTED EVT_LIST_ITEM_SELECTED EVT_MOUSE_EVENTS EVT_PAINT EVT_TOOL
|
EVT_LIST_ITEM_DESELECTED EVT_LIST_ITEM_SELECTED EVT_MOUSE_EVENTS EVT_PAINT EVT_TOOL
|
||||||
EVT_CHOICE EVT_TIMER);
|
EVT_CHOICE EVT_TIMER EVT_NOTEBOOK_PAGE_CHANGED);
|
||||||
use base 'Wx::Panel';
|
use base 'Wx::Panel';
|
||||||
|
|
||||||
use constant TB_ADD => &Wx::NewId;
|
use constant TB_ADD => &Wx::NewId;
|
||||||
|
@ -91,7 +91,7 @@ sub new {
|
||||||
$self->update;
|
$self->update;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Initialize 3D preview
|
# Initialize 3D plater
|
||||||
if ($Slic3r::GUI::have_OpenGL) {
|
if ($Slic3r::GUI::have_OpenGL) {
|
||||||
$self->{canvas3D} = Slic3r::GUI::Plater::3D->new($self->{preview_notebook}, $self->{objects}, $self->{model}, $self->{config});
|
$self->{canvas3D} = Slic3r::GUI::Plater::3D->new($self->{preview_notebook}, $self->{objects}, $self->{model}, $self->{config});
|
||||||
$self->{preview_notebook}->AddPage($self->{canvas3D}, '3D');
|
$self->{preview_notebook}->AddPage($self->{canvas3D}, '3D');
|
||||||
|
@ -112,9 +112,22 @@ sub new {
|
||||||
# Initialize toolpaths preview
|
# Initialize toolpaths preview
|
||||||
if ($Slic3r::GUI::have_OpenGL) {
|
if ($Slic3r::GUI::have_OpenGL) {
|
||||||
$self->{toolpaths2D} = Slic3r::GUI::Plater::2DToolpaths->new($self->{preview_notebook}, $self->{print});
|
$self->{toolpaths2D} = Slic3r::GUI::Plater::2DToolpaths->new($self->{preview_notebook}, $self->{print});
|
||||||
$self->{preview_notebook}->AddPage($self->{toolpaths2D}, 'Preview');
|
$self->{preview_notebook}->AddPage($self->{toolpaths2D}, 'Preview 2D');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Initialize 3D plater
|
||||||
|
if ($Slic3r::GUI::have_OpenGL) {
|
||||||
|
$self->{preview3D} = Slic3r::GUI::Plater::3DPreview->new($self->{preview_notebook}, $self->{print});
|
||||||
|
$self->{preview_notebook}->AddPage($self->{preview3D}, 'Preview 3D');
|
||||||
|
$self->{preview3D_page_idx} = $self->{preview_notebook}->GetPageCount-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
EVT_NOTEBOOK_PAGE_CHANGED($self, $self->{preview_notebook}, sub {
|
||||||
|
if ($self->{preview_notebook}->GetSelection == $self->{preview3D_page_idx}) {
|
||||||
|
$self->{preview3D}->reload_print;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
# toolbar for object manipulation
|
# toolbar for object manipulation
|
||||||
if (!&Wx::wxMSW) {
|
if (!&Wx::wxMSW) {
|
||||||
Wx::ToolTip::Enable(1);
|
Wx::ToolTip::Enable(1);
|
||||||
|
@ -245,7 +258,8 @@ sub new {
|
||||||
}
|
}
|
||||||
|
|
||||||
$_->SetDropTarget(Slic3r::GUI::Plater::DropTarget->new($self))
|
$_->SetDropTarget(Slic3r::GUI::Plater::DropTarget->new($self))
|
||||||
for grep defined($_), $self, $self->{canvas}, $self->{canvas3D}, $self->{list};
|
for grep defined($_),
|
||||||
|
$self, $self->{canvas}, $self->{canvas3D}, $self->{preview3D}, $self->{list};
|
||||||
|
|
||||||
EVT_COMMAND($self, -1, $THUMBNAIL_DONE_EVENT, sub {
|
EVT_COMMAND($self, -1, $THUMBNAIL_DONE_EVENT, sub {
|
||||||
my ($self, $event) = @_;
|
my ($self, $event) = @_;
|
||||||
|
@ -287,6 +301,9 @@ sub new {
|
||||||
$self->{canvas3D}->update_bed_size;
|
$self->{canvas3D}->update_bed_size;
|
||||||
$self->{canvas3D}->zoom_to_bed;
|
$self->{canvas3D}->zoom_to_bed;
|
||||||
}
|
}
|
||||||
|
if ($self->{preview3D}) {
|
||||||
|
$self->{preview3D}->set_bed_shape($self->{config}->bed_shape);
|
||||||
|
}
|
||||||
$self->update;
|
$self->update;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -543,6 +560,7 @@ sub remove {
|
||||||
|
|
||||||
# Prevent toolpaths preview from rendering while we modify the Print object
|
# Prevent toolpaths preview from rendering while we modify the Print object
|
||||||
$self->{toolpaths2D}->enabled(0) if $self->{toolpaths2D};
|
$self->{toolpaths2D}->enabled(0) if $self->{toolpaths2D};
|
||||||
|
$self->{preview3D}->enabled(0) if $self->{preview3D};
|
||||||
|
|
||||||
# if no object index is supplied, remove the selected one
|
# if no object index is supplied, remove the selected one
|
||||||
if (!defined $obj_idx) {
|
if (!defined $obj_idx) {
|
||||||
|
@ -567,6 +585,7 @@ sub reset {
|
||||||
|
|
||||||
# Prevent toolpaths preview from rendering while we modify the Print object
|
# Prevent toolpaths preview from rendering while we modify the Print object
|
||||||
$self->{toolpaths2D}->enabled(0) if $self->{toolpaths2D};
|
$self->{toolpaths2D}->enabled(0) if $self->{toolpaths2D};
|
||||||
|
$self->{preview3D}->enabled(0) if $self->{preview3D};
|
||||||
|
|
||||||
@{$self->{objects}} = ();
|
@{$self->{objects}} = ();
|
||||||
$self->{model}->clear_objects;
|
$self->{model}->clear_objects;
|
||||||
|
@ -855,6 +874,7 @@ sub schedule_background_process {
|
||||||
if (defined $self->{apply_config_timer}) {
|
if (defined $self->{apply_config_timer}) {
|
||||||
$self->{apply_config_timer}->Start(PROCESS_DELAY, 1); # 1 = one shot
|
$self->{apply_config_timer}->Start(PROCESS_DELAY, 1); # 1 = one shot
|
||||||
$self->{toolpaths2D}->reload_print;
|
$self->{toolpaths2D}->reload_print;
|
||||||
|
$self->{preview3D}->reload_print;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -934,6 +954,7 @@ sub stop_background_process {
|
||||||
$self->statusbar->StopBusy;
|
$self->statusbar->StopBusy;
|
||||||
$self->statusbar->SetStatusText("");
|
$self->statusbar->SetStatusText("");
|
||||||
$self->{toolpaths2D}->reload_print;
|
$self->{toolpaths2D}->reload_print;
|
||||||
|
$self->{preview3D}->reload_print;
|
||||||
|
|
||||||
if ($self->{process_thread}) {
|
if ($self->{process_thread}) {
|
||||||
Slic3r::debugf "Killing background process.\n";
|
Slic3r::debugf "Killing background process.\n";
|
||||||
|
@ -1058,6 +1079,7 @@ sub on_process_completed {
|
||||||
|
|
||||||
return if $error;
|
return if $error;
|
||||||
$self->{toolpaths2D}->reload_print;
|
$self->{toolpaths2D}->reload_print;
|
||||||
|
$self->{preview3D}->reload_print;
|
||||||
|
|
||||||
# if we have an export filename, start a new thread for exporting G-code
|
# if we have an export filename, start a new thread for exporting G-code
|
||||||
if ($self->{export_gcode_output_file}) {
|
if ($self->{export_gcode_output_file}) {
|
||||||
|
@ -1516,6 +1538,7 @@ sub refresh_canvases {
|
||||||
|
|
||||||
$self->{canvas}->Refresh;
|
$self->{canvas}->Refresh;
|
||||||
$self->{canvas3D}->update if $self->{canvas3D};
|
$self->{canvas3D}->update if $self->{canvas3D};
|
||||||
|
$self->{preview3D}->reload_print if $self->{preview3D};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub validate_config {
|
sub validate_config {
|
||||||
|
|
112
lib/Slic3r/GUI/Plater/3DPreview.pm
Normal file
112
lib/Slic3r/GUI/Plater/3DPreview.pm
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
package Slic3r::GUI::Plater::3DPreview;
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use utf8;
|
||||||
|
|
||||||
|
use Slic3r::Print::State ':steps';
|
||||||
|
use Wx qw(:misc :sizer :slider :statictext wxWHITE);
|
||||||
|
use Wx::Event qw(EVT_SLIDER EVT_KEY_DOWN);
|
||||||
|
use base qw(Wx::Panel Class::Accessor);
|
||||||
|
|
||||||
|
__PACKAGE__->mk_accessors(qw(print enabled canvas slider));
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my $class = shift;
|
||||||
|
my ($parent, $print) = @_;
|
||||||
|
|
||||||
|
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition);
|
||||||
|
|
||||||
|
# init GUI elements
|
||||||
|
my $canvas = Slic3r::GUI::3DScene->new($self);
|
||||||
|
$self->canvas($canvas);
|
||||||
|
my $slider = Wx::Slider->new(
|
||||||
|
$self, -1,
|
||||||
|
0, # default
|
||||||
|
0, # min
|
||||||
|
# we set max to a bogus non-zero value because the MSW implementation of wxSlider
|
||||||
|
# will skip drawing the slider if max <= min:
|
||||||
|
1, # max
|
||||||
|
wxDefaultPosition,
|
||||||
|
wxDefaultSize,
|
||||||
|
wxVERTICAL | wxSL_INVERSE,
|
||||||
|
);
|
||||||
|
$self->slider($slider);
|
||||||
|
|
||||||
|
my $z_label = $self->{z_label} = Wx::StaticText->new($self, -1, "", wxDefaultPosition,
|
||||||
|
[40,-1], wxALIGN_CENTRE_HORIZONTAL);
|
||||||
|
$z_label->SetFont($Slic3r::GUI::small_font);
|
||||||
|
|
||||||
|
my $vsizer = Wx::BoxSizer->new(wxVERTICAL);
|
||||||
|
$vsizer->Add($slider, 1, wxALL | wxEXPAND | wxALIGN_CENTER, 3);
|
||||||
|
$vsizer->Add($z_label, 0, wxALL | wxEXPAND | wxALIGN_CENTER, 3);
|
||||||
|
|
||||||
|
my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
||||||
|
$sizer->Add($canvas, 1, wxALL | wxEXPAND, 0);
|
||||||
|
$sizer->Add($vsizer, 0, wxTOP | wxBOTTOM | wxEXPAND, 5);
|
||||||
|
|
||||||
|
EVT_SLIDER($self, $slider, sub {
|
||||||
|
$self->set_z($self->{layers_z}[$slider->GetValue])
|
||||||
|
if $self->enabled;
|
||||||
|
});
|
||||||
|
|
||||||
|
$self->SetSizer($sizer);
|
||||||
|
$self->SetMinSize($self->GetSize);
|
||||||
|
$sizer->SetSizeHints($self);
|
||||||
|
|
||||||
|
# init canvas
|
||||||
|
$canvas->set_bed_shape($print->config->bed_shape);
|
||||||
|
$self->print($print);
|
||||||
|
$self->reload_print;
|
||||||
|
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub reload_print {
|
||||||
|
my ($self) = @_;
|
||||||
|
|
||||||
|
$self->canvas->reset_objects;
|
||||||
|
|
||||||
|
# we require that there's at least one object and the posSlice step
|
||||||
|
# is performed on all of them (this ensures that _shifted_copies was
|
||||||
|
# populated and we know the number of layers)
|
||||||
|
if (!$self->print->object_step_done(STEP_SLICE)) {
|
||||||
|
$self->enabled(0);
|
||||||
|
$self->slider->Hide;
|
||||||
|
$self->canvas->Refresh; # clears canvas
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0) {
|
||||||
|
my %z = (); # z => 1
|
||||||
|
foreach my $object (@{$self->{print}->objects}) {
|
||||||
|
foreach my $layer (@{$object->layers}, @{$object->support_layers}) {
|
||||||
|
$z{$layer->print_z} = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$self->enabled(1);
|
||||||
|
$self->{layers_z} = [ sort { $a <=> $b } keys %z ];
|
||||||
|
$self->{slider}->SetRange(0, scalar(@{$self->{layers_z}})-1);
|
||||||
|
if ((my $z_idx = $self->{slider}->GetValue) <= $#{$self->{layers_z}}) {
|
||||||
|
$self->set_z($self->{layers_z}[$z_idx]);
|
||||||
|
} else {
|
||||||
|
$self->{slider}->SetValue(0);
|
||||||
|
$self->set_z($self->{layers_z}[0]) if @{$self->{layers_z}};
|
||||||
|
}
|
||||||
|
$self->{slider}->Show;
|
||||||
|
$self->Layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($self->IsShown) {
|
||||||
|
foreach my $object (@{$self->print->objects}) {
|
||||||
|
$self->canvas->load_print_object_toolpaths($object);
|
||||||
|
}
|
||||||
|
$self->canvas->zoom_to_volumes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub set_bed_shape {
|
||||||
|
my ($self, $bed_shape) = @_;
|
||||||
|
$self->canvas->set_bed_shape($bed_shape);
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
Loading…
Reference in a new issue