Performance improvements in reloading the 3D scene.

Now the 3D scene loading is postponed until the page is visible.
This commit is contained in:
bubnikv 2017-05-31 17:05:11 +02:00
parent 556f40bf00
commit ee5ee5f432
4 changed files with 57 additions and 40 deletions

View file

@ -1210,29 +1210,31 @@ sub async_apply_config {
# apply new config
my $invalidated = $self->{print}->apply_config($self->GetFrame->config);
# Just redraw the 3D canvas without reloading the scene.
# $self->{canvas3D}->Refresh if ($invalidated && $self->{canvas3D}->layer_editing_enabled);
$self->{canvas3D}->Refresh if ($self->{canvas3D}->layer_editing_enabled);
# Hide the slicing results if the current slicing status is no more valid.
$self->{"print_info_box_show"}->(0) if $invalidated;
return if !$Slic3r::GUI::Settings->{_}{background_processing};
if ($Slic3r::GUI::Settings->{_}{background_processing}) {
if ($invalidated) {
# kill current thread if any
$self->stop_background_process;
} else {
$self->resume_background_process;
}
# schedule a new process thread in case it wasn't running
$self->start_background_process;
}
# Reset preview canvases. If the print has been invalidated, the preview canvases will be cleared.
# Otherwise they will be just refreshed.
if ($invalidated) {
$self->{toolpaths2D}->reload_print if $self->{toolpaths2D};
$self->{preview3D}->reload_print if $self->{preview3D};
}
}
sub start_background_process {
my ($self) = @_;
@ -1696,7 +1698,7 @@ sub on_thumbnail_made {
my ($obj_idx) = @_;
$self->{objects}[$obj_idx]->transform_thumbnail($self->{model}, $obj_idx);
$self->refresh_canvases;
$self->{canvas}->Refresh;
}
# this method gets called whenever print center is changed or the objects' bounding box changes
@ -1721,7 +1723,9 @@ sub update {
$self->resume_background_process;
}
$self->refresh_canvases;
$self->{canvas}->Refresh;
$self->{canvas3D}->reload_scene if $self->{canvas3D};
$self->{preview3D}->reload_print if $self->{preview3D};
}
# When a number of extruders changes, the UI needs to be updated to show a single filament selection combo box per extruder.
@ -1785,18 +1789,10 @@ sub on_config_change {
} elsif ($opt_key =~ '^wipe_tower' || $opt_key eq 'single_extruder_multi_material') {
$update_scheduled = 1;
} elsif ($opt_key eq 'serial_port') {
if ($config->get('serial_port')) {
$self->{btn_print}->Show;
} else {
$self->{btn_print}->Hide;
}
$self->{btn_print}->Show($config->get('serial_port'));
$self->Layout;
} elsif ($opt_key eq 'octoprint_host') {
if ($config->get('octoprint_host')) {
$self->{btn_send_gcode}->Show;
} else {
$self->{btn_send_gcode}->Hide;
}
$self->{btn_send_gcode}->Show($config->get('octoprint_host'));
$self->Layout;
} elsif ($opt_key eq 'variable_layer_height') {
if ($config->get('variable_layer_height') != 1) {
@ -1839,7 +1835,9 @@ sub list_item_deselected {
if ($self->{list}->GetFirstSelected == -1) {
$self->select_object(undef);
$self->refresh_canvases;
$self->{canvas}->Refresh;
#FIXME VBOs are being refreshed just to change a selection color?
$self->{canvas3D}->reload_scene if $self->{canvas3D};
}
}
@ -1849,7 +1847,9 @@ sub list_item_selected {
my $obj_idx = $event->GetIndex;
$self->select_object($obj_idx);
$self->refresh_canvases;
$self->{canvas}->Refresh;
#FIXME VBOs are being refreshed just to change a selection color?
$self->{canvas3D}->reload_scene if $self->{canvas3D};
}
sub list_item_activated {
@ -2061,14 +2061,6 @@ sub selected_object {
return ($obj_idx, $self->{objects}[$obj_idx]),
}
sub refresh_canvases {
my ($self) = @_;
$self->{canvas}->Refresh;
$self->{canvas3D}->reload_scene if $self->{canvas3D};
$self->{preview3D}->reload_print if $self->{preview3D};
}
sub validate_config {
my $self = shift;

View file

@ -100,11 +100,18 @@ sub set_on_model_update {
}
sub reload_scene {
my ($self) = @_;
my ($self, $force) = @_;
$self->reset_objects;
$self->update_bed_size;
if (! $self->IsShown && ! $force) {
$self->{reload_delayed} = 1;
return;
}
$self->{reload_delayed} = 0;
foreach my $obj_idx (0..$#{$self->{model}->objects}) {
my @volume_idxs = $self->load_object($self->{model}, $self->{print}, $obj_idx);
if ($self->{objects}[$obj_idx]->selected) {
@ -133,4 +140,10 @@ sub update_bed_size {
$self->set_bed_shape($self->{config}->bed_shape);
}
# Called by the Platter wxNotebook when this page is activated.
sub OnActivate {
my ($self) = @_;
$self->reload_scene(1) if ($self->{reload_delayed});
}
1;

View file

@ -131,10 +131,16 @@ sub new {
}
sub reload_print {
my ($self) = @_;
my ($self, $force) = @_;
$self->canvas->reset_objects;
$self->_loaded(0);
if (! $self->IsShown && ! $force) {
$self->{reload_delayed} = 1;
return;
}
$self->load_print;
}
@ -289,4 +295,10 @@ sub set_number_extruders {
}
}
# Called by the Platter wxNotebook when this page is activated.
sub OnActivate {
my ($self) = @_;
$self->reload_scene(1) if ($self->{reload_delayed});
}
1;