From b05aa00089ed6097b1467caaf594456936af0919 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 7 Nov 2018 14:01:03 +0100 Subject: [PATCH] Fixed update of ModelVolume offset after GLVolume manipulation --- src/libslic3r/Model.cpp | 24 ++++++++++++------------ src/slic3r/GUI/GLCanvas3D.cpp | 27 +++++++++++++++++++-------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index dac6f7713..20bf9e367 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -1246,7 +1246,7 @@ size_t ModelVolume::split(unsigned int max_extruders) void ModelVolume::translate(const Vec3d& displacement) { #if ENABLE_MODELVOLUME_TRANSFORM - m_transformation.set_offset(m_transformation.get_offset() + displacement); + set_offset(get_offset() + displacement); #else mesh.translate((float)displacement(0), (float)displacement(1), (float)displacement(2)); m_convex_hull.translate((float)displacement(0), (float)displacement(1), (float)displacement(2)); @@ -1256,7 +1256,7 @@ void ModelVolume::translate(const Vec3d& displacement) void ModelVolume::scale(const Vec3d& scaling_factors) { #if ENABLE_MODELVOLUME_TRANSFORM - m_transformation.set_scaling_factor(m_transformation.get_scaling_factor().cwiseProduct(scaling_factors)); + set_scaling_factor(get_scaling_factor().cwiseProduct(scaling_factors)); #else mesh.scale(scaling_factors); m_convex_hull.scale(scaling_factors); @@ -1281,7 +1281,7 @@ void ModelVolume::rotate(double angle, Axis axis) void ModelVolume::rotate(double angle, const Vec3d& axis) { #if ENABLE_MODELVOLUME_TRANSFORM - m_transformation.set_rotation(m_transformation.get_rotation() + Geometry::extract_euler_angles(Eigen::Quaterniond(Eigen::AngleAxisd(angle, axis)).toRotationMatrix())); + set_rotation(get_rotation() + Geometry::extract_euler_angles(Eigen::Quaterniond(Eigen::AngleAxisd(angle, axis)).toRotationMatrix())); #else mesh.rotate(angle, axis); m_convex_hull.rotate(angle, axis); @@ -1291,14 +1291,14 @@ void ModelVolume::rotate(double angle, const Vec3d& axis) void ModelVolume::mirror(Axis axis) { #if ENABLE_MODELVOLUME_TRANSFORM - Vec3d mirror = m_transformation.get_mirror(); + Vec3d mirror = get_mirror(); switch (axis) { case X: { mirror(0) *= -1.0; break; } case Y: { mirror(1) *= -1.0; break; } case Z: { mirror(2) *= -1.0; break; } } - m_transformation.set_mirror(mirror); + set_mirror(mirror); #else mesh.mirror(axis); m_convex_hull.mirror(axis); @@ -1375,10 +1375,10 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes for (unsigned int i = 0; i < 3; ++i) { #if ENABLE_MODELVOLUME_TRANSFORM - if (std::abs(m_transformation.get_scaling_factor((Axis)i)-1.0) > EPSILON) + if (std::abs(get_scaling_factor((Axis)i)-1.0) > EPSILON) { - bbox.min(i) *= m_transformation.get_scaling_factor((Axis)i); - bbox.max(i) *= m_transformation.get_scaling_factor((Axis)i); + bbox.min(i) *= get_scaling_factor((Axis)i); + bbox.max(i) *= get_scaling_factor((Axis)i); #else if (std::abs(this->m_scaling_factor(i) - 1.0) > EPSILON) { @@ -1391,8 +1391,8 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes // Translate the bounding box. if (! dont_translate) { #if ENABLE_MODELVOLUME_TRANSFORM - bbox.min += m_transformation.get_offset(); - bbox.max += m_transformation.get_offset(); + bbox.min += get_offset(); + bbox.max += get_offset(); #else bbox.min += this->m_offset; bbox.max += this->m_offset; @@ -1416,9 +1416,9 @@ void ModelInstance::transform_polygon(Polygon* polygon) const { #if ENABLE_MODELVOLUME_TRANSFORM // CHECK_ME -> Is the following correct or it should take in account all three rotations ? - polygon->rotate(m_transformation.get_rotation(Z)); // rotate around polygon origin + polygon->rotate(get_rotation(Z)); // rotate around polygon origin // CHECK_ME -> Is the following correct ? - polygon->scale(m_transformation.get_scaling_factor(X), m_transformation.get_scaling_factor(Y)); // scale around polygon origin + polygon->scale(get_scaling_factor(X), get_scaling_factor(Y)); // scale around polygon origin #else // CHECK_ME -> Is the following correct or it should take in account all three rotations ? polygon->rotate(this->m_rotation(2)); // rotate around polygon origin diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 1cd5fe6fc..bcfff43db 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -6274,35 +6274,45 @@ void GLCanvas3D::_on_move() if (m_model == nullptr) return; - std::set> done; // prevent moving instances twice + std::set> done; // keeps track of moved instances bool object_moved = false; Vec3d wipe_tower_origin = Vec3d::Zero(); + Selection::EMode selection_mode = m_selection.get_mode(); + for (const GLVolume* v : m_volumes.volumes) { int object_idx = v->object_idx(); int instance_idx = v->instance_idx(); + int volume_idx = v->volume_idx(); - // prevent moving instances twice std::pair done_id(object_idx, instance_idx); - if (done.find(done_id) != done.end()) - continue; - if (object_idx < 1000) + if ((0 <= object_idx) && (object_idx < (int)m_model->objects.size())) { done.insert(done_id); - // Move instances. + // Move instances/volumes ModelObject* model_object = m_model->objects[object_idx]; if (model_object != nullptr) { #if ENABLE_MODELVOLUME_TRANSFORM - model_object->instances[instance_idx]->set_offset(v->get_instance_offset()); + if (selection_mode == Selection::Instance) + { + model_object->instances[instance_idx]->set_offset(v->get_instance_offset()); + object_moved = true; + } + else if (selection_mode == Selection::Volume) + { + model_object->volumes[volume_idx]->set_offset(v->get_volume_offset()); + object_moved = true; + } + if (object_moved) #else model_object->instances[instance_idx]->set_offset(v->get_offset()); + object_moved = true; #endif // ENABLE_MODELVOLUME_TRANSFORM model_object->invalidate_bounding_box(); - object_moved = true; } } else if (object_idx == 1000) @@ -6314,6 +6324,7 @@ void GLCanvas3D::_on_move() #endif // ENABLE_MODELVOLUME_TRANSFORM } + // Fixes sinking/flying instances for (const std::pair& i : done) { ModelObject* m = m_model->objects[i.first];