mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 01:07:57 -06:00
Disabled the new Slic3r version check until we have a server set up
for the Slic3r Prusa Edition. Hopefully a fix of https://github.com/prusa3d/Slic3r/issues/258 by moving the 2D thumbnail generation to the main thread and forcing the simple 2D convex hull for even the small objects.
This commit is contained in:
parent
02ab92ea65
commit
f408f08850
5 changed files with 118 additions and 136 deletions
|
@ -34,7 +34,6 @@ use constant TB_SETTINGS => &Wx::NewId;
|
|||
use constant TB_LAYER_EDITING => &Wx::NewId;
|
||||
|
||||
# package variables to avoid passing lexicals to threads
|
||||
our $THUMBNAIL_DONE_EVENT : shared = Wx::NewEventType;
|
||||
our $PROGRESS_BAR_EVENT : shared = Wx::NewEventType;
|
||||
our $ERROR_EVENT : shared = Wx::NewEventType;
|
||||
# Emitted from the worker thread when the G-code export is finished.
|
||||
|
@ -307,14 +306,6 @@ sub new {
|
|||
for grep defined($_),
|
||||
$self, $self->{canvas}, $self->{canvas3D}, $self->{preview3D}, $self->{list};
|
||||
|
||||
EVT_COMMAND($self, -1, $THUMBNAIL_DONE_EVENT, sub {
|
||||
my ($self, $event) = @_;
|
||||
my ($obj_idx) = @{$event->GetData};
|
||||
return if !$self->{objects}[$obj_idx]; # object was deleted before thumbnail generation completed
|
||||
|
||||
$self->on_thumbnail_made($obj_idx);
|
||||
});
|
||||
|
||||
EVT_COMMAND($self, -1, $PROGRESS_BAR_EVENT, sub {
|
||||
my ($self, $event) = @_;
|
||||
my ($percent, $message) = @{$event->GetData};
|
||||
|
@ -803,7 +794,7 @@ sub load_model_objects {
|
|||
$self->{list}->SetItem($obj_idx, 1, $model_object->instances_count);
|
||||
$self->{list}->SetItem($obj_idx, 2, ($model_object->instances->[0]->scaling_factor * 100) . "%");
|
||||
|
||||
$self->make_thumbnail($obj_idx);
|
||||
$self->reset_thumbnail($obj_idx);
|
||||
}
|
||||
$self->arrange if $need_arrange;
|
||||
$self->update;
|
||||
|
@ -988,10 +979,7 @@ sub rotate {
|
|||
|
||||
my $model_object = $self->{model}->objects->[$obj_idx];
|
||||
my $model_instance = $model_object->instances->[0];
|
||||
|
||||
# we need thumbnail to be computed before allowing rotation
|
||||
return if !$object->thumbnail;
|
||||
|
||||
|
||||
if (!defined $angle) {
|
||||
my $axis_name = $axis == X ? 'X' : $axis == Y ? 'Y' : 'Z';
|
||||
my $default = $axis == Z ? rad2deg($model_instance->rotation) : 0;
|
||||
|
@ -1016,7 +1004,7 @@ sub rotate {
|
|||
|
||||
# realign object to Z = 0
|
||||
$model_object->center_around_origin;
|
||||
$self->make_thumbnail($obj_idx);
|
||||
$self->reset_thumbnail($obj_idx);
|
||||
}
|
||||
|
||||
$model_object->update_bounding_box;
|
||||
|
@ -1048,7 +1036,7 @@ sub mirror {
|
|||
|
||||
# realign object to Z = 0
|
||||
$model_object->center_around_origin;
|
||||
$self->make_thumbnail($obj_idx);
|
||||
$self->reset_thumbnail($obj_idx);
|
||||
|
||||
# update print and start background processing
|
||||
$self->stop_background_process;
|
||||
|
@ -1068,9 +1056,6 @@ sub changescale {
|
|||
my $model_object = $self->{model}->objects->[$obj_idx];
|
||||
my $model_instance = $model_object->instances->[0];
|
||||
|
||||
# we need thumbnail to be computed before allowing scaling
|
||||
return if !$object->thumbnail;
|
||||
|
||||
my $object_size = $model_object->bounding_box->size;
|
||||
my $bed_size = Slic3r::Polygon->new_scale(@{$self->{config}->bed_shape})->bounding_box->size;
|
||||
|
||||
|
@ -1101,7 +1086,7 @@ sub changescale {
|
|||
#FIXME Scale the layer height profile when $axis == Z?
|
||||
#FIXME Scale the layer height ranges $axis == Z?
|
||||
# object was already aligned to Z = 0, so no need to realign it
|
||||
$self->make_thumbnail($obj_idx);
|
||||
$self->reset_thumbnail($obj_idx);
|
||||
} else {
|
||||
my $scale;
|
||||
if ($tosize) {
|
||||
|
@ -1621,12 +1606,6 @@ sub reload_from_disk {
|
|||
}
|
||||
|
||||
$self->remove($obj_idx);
|
||||
|
||||
# Trigger thumbnail generation again, because the remove() method altered
|
||||
# object indexes before background thumbnail generation called its completion
|
||||
# event, so the on_thumbnail_made callback is called with the wrong $obj_idx.
|
||||
# When porting to C++ we'll probably have cleaner ways to do this.
|
||||
$self->make_thumbnail($_-1) for @new_obj_idx;
|
||||
}
|
||||
|
||||
sub export_object_stl {
|
||||
|
@ -1674,36 +1653,9 @@ sub _get_export_file {
|
|||
return $output_file;
|
||||
}
|
||||
|
||||
sub make_thumbnail {
|
||||
my $self = shift;
|
||||
my ($obj_idx) = @_;
|
||||
|
||||
my $plater_object = $self->{objects}[$obj_idx];
|
||||
$plater_object->thumbnail(Slic3r::ExPolygon::Collection->new);
|
||||
my $cb = sub {
|
||||
$plater_object->make_thumbnail($self->{model}, $obj_idx);
|
||||
|
||||
if ($Slic3r::have_threads) {
|
||||
Wx::PostEvent($self, Wx::PlThreadEvent->new(-1, $THUMBNAIL_DONE_EVENT, shared_clone([ $obj_idx ])));
|
||||
Slic3r::thread_cleanup();
|
||||
threads->exit;
|
||||
} else {
|
||||
$self->on_thumbnail_made($obj_idx);
|
||||
}
|
||||
};
|
||||
|
||||
@_ = ();
|
||||
$Slic3r::have_threads
|
||||
? threads->create(sub { $cb->(); Slic3r::thread_cleanup(); })->detach
|
||||
: $cb->();
|
||||
}
|
||||
|
||||
sub on_thumbnail_made {
|
||||
my $self = shift;
|
||||
my ($obj_idx) = @_;
|
||||
|
||||
$self->{objects}[$obj_idx]->transform_thumbnail($self->{model}, $obj_idx);
|
||||
$self->{canvas}->Refresh;
|
||||
sub reset_thumbnail {
|
||||
my ($self, $obj_idx) = @_;
|
||||
$self->{objects}[$obj_idx]->thumbnail(undef);
|
||||
}
|
||||
|
||||
# this method gets called whenever print center is changed or the objects' bounding box changes
|
||||
|
@ -1727,7 +1679,8 @@ sub update {
|
|||
} else {
|
||||
$self->resume_background_process;
|
||||
}
|
||||
|
||||
|
||||
$self->{canvas}->reload_scene if $self->{canvas};
|
||||
$self->{canvas3D}->reload_scene if $self->{canvas3D};
|
||||
$self->{preview3D}->reload_print if $self->{preview3D};
|
||||
}
|
||||
|
@ -1942,7 +1895,7 @@ sub object_settings_dialog {
|
|||
if ($dlg->PartsChanged) {
|
||||
# recenter and re-align to Z = 0
|
||||
$model_object->center_around_origin;
|
||||
$self->make_thumbnail($obj_idx);
|
||||
$self->reset_thumbnail($obj_idx);
|
||||
}
|
||||
|
||||
# update print
|
||||
|
@ -1950,6 +1903,7 @@ sub object_settings_dialog {
|
|||
$self->stop_background_process;
|
||||
$self->{print}->reload_object($obj_idx);
|
||||
$self->schedule_background_process;
|
||||
$self->{canvas}->reload_scene if $self->{canvas};
|
||||
$self->{canvas3D}->reload_scene if $self->{canvas3D};
|
||||
} else {
|
||||
$self->resume_background_process;
|
||||
|
@ -2245,18 +2199,19 @@ sub make_thumbnail {
|
|||
$self->thumbnail->clear;
|
||||
|
||||
my $mesh = $model->objects->[$obj_idx]->raw_mesh;
|
||||
if ($mesh->facets_count <= 5000) {
|
||||
# remove polygons with area <= 1mm
|
||||
my $area_threshold = Slic3r::Geometry::scale 1;
|
||||
$self->thumbnail->append(
|
||||
grep $_->area >= $area_threshold,
|
||||
@{ $mesh->horizontal_projection }, # horizontal_projection returns scaled expolygons
|
||||
);
|
||||
$self->thumbnail->simplify(0.5);
|
||||
} else {
|
||||
#FIXME The "correct" variant could be extremely slow.
|
||||
# if ($mesh->facets_count <= 5000) {
|
||||
# # remove polygons with area <= 1mm
|
||||
# my $area_threshold = Slic3r::Geometry::scale 1;
|
||||
# $self->thumbnail->append(
|
||||
# grep $_->area >= $area_threshold,
|
||||
# @{ $mesh->horizontal_projection }, # horizontal_projection returns scaled expolygons
|
||||
# );
|
||||
# $self->thumbnail->simplify(0.5);
|
||||
# } else {
|
||||
my $convex_hull = Slic3r::ExPolygon->new($mesh->convex_hull);
|
||||
$self->thumbnail->append($convex_hull);
|
||||
}
|
||||
# }
|
||||
|
||||
return $self->thumbnail;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue