Refactored Model.cpp/hpp to C++x11 loops,
simplified the mesh / bbox handling.
This commit is contained in:
bubnikv 2017-06-13 11:35:24 +02:00
parent 21ddcb8487
commit 5cae4cc614
13 changed files with 314 additions and 500 deletions

View file

@ -547,7 +547,8 @@ sub mouse_wheel_event {
$zoom /= 10;
$zoom = $self->_zoom / (1-$zoom);
# Don't allow to zoom too far outside the scene.
my $zoom_min = $self->get_zoom_to_bounding_box_factor($self->max_bounding_box) * 0.4;
my $zoom_min = $self->get_zoom_to_bounding_box_factor($self->max_bounding_box);
$zoom_min *= 0.4 if defined $zoom_min;
$zoom = $zoom_min if defined $zoom_min && $zoom < $zoom_min;
$self->_zoom($zoom);

View file

@ -290,7 +290,7 @@ sub _load_stl {
$dialog->Destroy;
my $model = Slic3r::Model->read_from_file($input_file);
my $mesh = $model->raw_mesh;
my $mesh = $model->mesh;
my $expolygons = $mesh->horizontal_projection;
if (@$expolygons == 0) {

View file

@ -707,7 +707,7 @@ sub load_file {
local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
my $model = eval { Slic3r::Model->read_from_file($input_file) };
my $model = eval { Slic3r::Model->read_from_file($input_file, 0) };
Slic3r::GUI::show_error($self, $@) if $@;
my @obj_idx = ();
@ -1007,7 +1007,6 @@ sub rotate {
$self->reset_thumbnail($obj_idx);
}
$model_object->update_bounding_box;
# update print and start background processing
$self->{print}->add_model_object($model_object, $obj_idx);
@ -1032,7 +1031,6 @@ sub mirror {
}
$model_object->mirror($axis);
$model_object->update_bounding_box;
# realign object to Z = 0
$model_object->center_around_origin;
@ -1112,7 +1110,6 @@ sub changescale {
$_->set_scaling_factor($scale) for @{ $model_object->instances };
$object->transform_thumbnail($self->{model}, $obj_idx);
}
$model_object->update_bounding_box;
# update print and start background processing
$self->stop_background_process;
@ -1133,6 +1130,7 @@ sub arrange {
# ignore arrange failures on purpose: user has visual feedback and we don't need to warn him
# when parts don't fit in print bed
# Force auto center of the aligned grid of of objects on the print bed.
$self->update(1);
}
@ -2198,6 +2196,7 @@ sub make_thumbnail {
# make method idempotent
$self->thumbnail->clear;
# raw_mesh is the non-transformed (non-rotated, non-scaled, non-translated) sum of non-modifier object volumes.
my $mesh = $model->objects->[$obj_idx]->raw_mesh;
#FIXME The "correct" variant could be extremely slow.
# if ($mesh->facets_count <= 5000) {

View file

@ -246,7 +246,6 @@ sub mouse_event {
unscale($point->[X] - $self->{drag_start_pos}[X]),
unscale($point->[Y] - $self->{drag_start_pos}[Y]),
));
$model_object->update_bounding_box;
$self->Refresh;
} elsif ($event->Moving) {
my $cursor = wxSTANDARD_CURSOR;

View file

@ -6,8 +6,8 @@ use List::Util qw(first max any);
use Slic3r::Geometry qw(X Y Z move_points);
sub read_from_file {
my $class = shift;
my ($input_file) = @_;
my ($class, $input_file, $add_default_instances) = @_;
$add_default_instances //= 1;
my $model = $input_file =~ /\.stl$/i ? Slic3r::Model->load_stl(Slic3r::encode_path($input_file), basename($input_file))
: $input_file =~ /\.obj$/i ? Slic3r::Model->load_obj(Slic3r::encode_path($input_file), basename($input_file))
@ -19,6 +19,7 @@ sub read_from_file {
if $model->objects_count == 0;
$_->set_input_file($input_file) for @{$model->objects};
$model->add_default_instances if $add_default_instances;
return $model;
}