From 7ca02bda0f7ab911a97e435475e05f1b113246d1 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Mon, 19 Jun 2017 14:26:19 +0200 Subject: [PATCH] Fix of a "split" function issue. 1) Load a multi-part stl 2) Rotate it by 90 degrees 3) Split it. Before this fix, the split object jumped away from the print bed. This sound similar to https://github.com/prusa3d/Slic3r/issues/309 --- lib/Slic3r/GUI/Plater.pm | 2 ++ xs/src/libslic3r/Model.cpp | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 3a024f938..66b40b277 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1158,6 +1158,8 @@ sub split_object { $self->resume_background_process; return; } + + $_->center_around_origin for (@model_objects); $self->remove($obj_idx); $current_object = $obj_idx = undef; diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 6714966e7..0cc15f81f 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -496,7 +496,7 @@ void ModelObject::center_around_origin() // apply rotation and scaling to vector as well before translating instance, // in order to leave final position unaltered Vectorf3 v = vector.negative(); - v.rotate(i->rotation, i->offset); + v.rotate(i->rotation); v.scale(i->scaling_factor); i->offset.translate(v.x, v.y); } @@ -639,19 +639,22 @@ void ModelObject::split(ModelObjectPtrs* new_objects) ModelVolume* volume = this->volumes.front(); TriangleMeshPtrs meshptrs = volume->mesh.split(); - for (TriangleMeshPtrs::iterator mesh = meshptrs.begin(); mesh != meshptrs.end(); ++mesh) { - (*mesh)->repair(); + for (TriangleMesh *mesh : meshptrs) { + // Snap the mesh to Z=0. + float z0 = FLT_MAX; + + mesh->repair(); ModelObject* new_object = m_model->add_object(*this, false); new_object->input_file = ""; - ModelVolume* new_volume = new_object->add_volume(**mesh); + ModelVolume* new_volume = new_object->add_volume(*mesh); new_volume->name = volume->name; new_volume->config = volume->config; new_volume->modifier = volume->modifier; new_volume->material_id(volume->material_id()); new_objects->push_back(new_object); - delete *mesh; + delete mesh; } return;