diff --git a/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm b/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm index 35c1af28b..ed4f2135b 100644 --- a/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm +++ b/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm @@ -366,7 +366,7 @@ sub on_btn_load { $new_volume->set_input_file_vol_idx($vol_idx); # apply the same translation we applied to the object - $new_volume->mesh->translate(@{$self->{model_object}->origin_translation}); + $new_volume->translate(@{$self->{model_object}->origin_translation}); # set a default extruder value, since user can't add it manually $new_volume->config->set_ifndef('extruder', 0); @@ -405,11 +405,11 @@ sub on_btn_lambda { $params->{"slab_h"}, ); # box sets the base coordinate at 0,0, move to center of plate - $mesh->translate( - -$size->x*1.5/2.0, - -$size->y*1.5/2.0, #** - 0, - ); + #$mesh->translate( + # -$size->x*1.5/2.0, + # -$size->y*1.5/2.0, #** + # 0, + #); } else { return; } @@ -418,7 +418,7 @@ sub on_btn_lambda { if (!$Slic3r::GUI::Settings->{_}{autocenter}) { #TODO what we really want to do here is just align the # center of the modifier to the center of the part. - $mesh->translate($center->x, $center->y, 0); + #$mesh->translate($center->x, $center->y, 0); } $mesh->repair; @@ -497,7 +497,7 @@ sub _update { my $itemData = $self->get_selection; if ($itemData && $itemData->{type} eq 'volume') { my $volume = $self->{model_object}->volumes->[$itemData->{volume_id}]; - $volume->mesh->translate(@{ $volume->mesh->bounding_box->min_point->vector_to($self->{move_target}) }); + $volume->translate(@{ $volume->mesh->bounding_box->min_point->vector_to($self->{move_target}) }); } $self->{parts_changed} = 1; diff --git a/slic3r.pl b/slic3r.pl index f09699492..1854f09d0 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -158,7 +158,7 @@ if (@ARGV) { # slicing from command line my $model = Slic3r::Model->read_from_file($file); $model->add_default_instances; my $mesh = $model->mesh; - $mesh->translate(0, 0, -$mesh->bounding_box->z_min); + $mesh->align_to_bed(); my $upper = Slic3r::TriangleMesh->new; my $lower = Slic3r::TriangleMesh->new; $mesh->cut(Z, $opt{cut}, $upper, $lower); @@ -179,8 +179,8 @@ if (@ARGV) { # slicing from command line my $model = Slic3r::Model->read_from_file($file); $model->add_default_instances; my $mesh = $model->mesh; + $mesh->align_to_bed(); my $bb = $mesh->bounding_box; - $mesh->translate(0, 0, -$bb->z_min); my $x_parts = ceil(($bb->size->x - epsilon)/$grid_x); my $y_parts = ceil(($bb->size->y - epsilon)/$grid_y); #-- diff --git a/utils/wireframe.pl b/utils/wireframe.pl index f49b66e56..6bd66433c 100644 --- a/utils/wireframe.pl +++ b/utils/wireframe.pl @@ -42,7 +42,7 @@ my %opt = ( $model->add_default_instances; $model->center_instances_around_point(Slic3r::Pointf->new(100,100)); my $mesh = $model->mesh; - $mesh->translate(0, 0, -$mesh->bounding_box->z_min); + $mesh->align_to_bed(); # get slices my @z = (); diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 1d0dfaf97..7d1845944 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -1141,13 +1141,8 @@ ModelInstance::swap(ModelInstance &other) void ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const { - mesh->rotate_z(this->rotation); // rotate around mesh origin - - mesh->scale(this->scaling_factor); // scale around mesh origin - if (!dont_translate) { - mesh->translate(this->offset.x, this->offset.y, 0); - } - + TransformationMatrix trafo = this->get_trafo_matrix(dont_translate); + mesh->transform(trafo); } TransformationMatrix ModelInstance::get_trafo_matrix(bool dont_translate) const diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index 5797f9a01..13d146f7d 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -3,6 +3,7 @@ #include "ClipperUtils.hpp" #include "Geometry.hpp" #include "Log.hpp" +#include "TransformationMatrix.hpp" #include #include #include @@ -936,28 +937,28 @@ PrintObject::_slice_region(size_t region_id, std::vector z, bool modifier // compose mesh TriangleMesh mesh; + + // we ignore the per-instance transformations currently and only + // consider the first one + TransformationMatrix trafo = object.instances[0]->get_trafo_matrix(); + + // align mesh to Z = 0 (it should be already aligned actually) and apply XY shift + trafo.translate( + -unscale(this->_copies_shift.x), + -unscale(this->_copies_shift.y), + -object.bounding_box().min.z + ); + for (const auto& i : region_volumes) { const ModelVolume &volume = *(object.volumes[i]); if (volume.modifier != modifier) continue; - mesh.merge(volume.mesh); + mesh.merge(volume.get_transformed_mesh(&trafo)); } if (mesh.facets_count() == 0) return layers; - // transform mesh - // we ignore the per-instance transformations currently and only - // consider the first one - object.instances[0]->transform_mesh(&mesh, true); - - // align mesh to Z = 0 (it should be already aligned actually) and apply XY shift - mesh.translate( - -unscale(this->_copies_shift.x), - -unscale(this->_copies_shift.y), - -object.bounding_box().min.z - ); - // perform actual slicing TriangleMeshSlicer(&mesh).slice(z, &layers); return layers; diff --git a/xs/src/libslic3r/SLAPrint.cpp b/xs/src/libslic3r/SLAPrint.cpp index f6fd69844..84ce3568f 100644 --- a/xs/src/libslic3r/SLAPrint.cpp +++ b/xs/src/libslic3r/SLAPrint.cpp @@ -16,6 +16,8 @@ SLAPrint::slice() TriangleMesh mesh = this->model->mesh(); mesh.repair(); + mesh.align_to_bed(); + // align to origin taking raft into account this->bb = mesh.bounding_box(); if (this->config.raft_layers > 0) { @@ -24,8 +26,6 @@ SLAPrint::slice() this->bb.max.x += this->config.raft_offset.value; this->bb.max.y += this->config.raft_offset.value; } - mesh.translate(0, 0, -bb.min.z); - this->bb.translate(0, 0, -bb.min.z); // if we are generating a raft, first_layer_height will not affect mesh slicing const float lh = this->config.layer_height.value;