diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index e69929150..7893455da 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -963,7 +963,7 @@ void ModelObject::center_around_origin(bool include_modifiers) void ModelObject::ensure_on_bed(bool allow_negative_z) { const double min_z = get_min_z(); - if (!allow_negative_z || min_z > 0.0) + if (!allow_negative_z || min_z > SINKING_Z_THRESHOLD) translate_instances({ 0.0, 0.0, -min_z }); } #else diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 0f64d2c98..1d4de4783 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -1129,6 +1129,10 @@ void check_model_ids_validity(const Model &model); void check_model_ids_equal(const Model &model1, const Model &model2); #endif /* NDEBUG */ +#if ENABLE_ALLOW_NEGATIVE_Z +static const float SINKING_Z_THRESHOLD = -0.001f; +#endif // ENABLE_ALLOW_NEGATIVE_Z + } // namespace Slic3r namespace cereal diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index a32f8bb43..61b7e34fc 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -536,7 +536,7 @@ bool GLVolume::is_sinking() const #endif // DISABLE_ALLOW_NEGATIVE_Z_FOR_SLA return false; const BoundingBoxf3& box = transformed_convex_hull_bounding_box(); - return box.min(2) < -EPSILON && box.max(2) >= -EPSILON; + return box.min.z() < SINKING_Z_THRESHOLD && box.max.z() >= SINKING_Z_THRESHOLD; } bool GLVolume::is_below_printbed() const diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index e8e4caed9..daf8c5991 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3413,7 +3413,7 @@ void GLCanvas3D::do_move(const std::string& snapshot_type) #if ENABLE_ALLOW_NEGATIVE_Z const double shift_z = m->get_instance_min_z(i.second); #if DISABLE_ALLOW_NEGATIVE_Z_FOR_SLA - if (current_printer_technology() == ptSLA || shift_z > 0.0) { + if (current_printer_technology() == ptSLA || shift_z > SINKING_Z_THRESHOLD) { #else if (shift_z > 0.0) { #endif // DISABLE_ALLOW_NEGATIVE_Z_FOR_SLA @@ -3463,7 +3463,7 @@ void GLCanvas3D::do_rotate(const std::string& snapshot_type) for (int i = 0; i < static_cast(m_model->objects.size()); ++i) { const ModelObject* obj = m_model->objects[i]; for (int j = 0; j < static_cast(obj->instances.size()); ++j) { - min_zs[{ i, j }] = obj->instance_bounding_box(j).min(2); + min_zs[{ i, j }] = obj->instance_bounding_box(j).min.z(); } } } @@ -3508,7 +3508,7 @@ void GLCanvas3D::do_rotate(const std::string& snapshot_type) #if ENABLE_ALLOW_NEGATIVE_Z double shift_z = m->get_instance_min_z(i.second); // leave sinking instances as sinking - if (min_zs.empty() || min_zs.find({ i.first, i.second })->second >= 0.0 || shift_z > 0.0) { + if (min_zs.empty() || min_zs.find({ i.first, i.second })->second >= SINKING_Z_THRESHOLD || shift_z > SINKING_Z_THRESHOLD) { Vec3d shift(0.0, 0.0, -shift_z); #else Vec3d shift(0.0, 0.0, -m->get_instance_min_z(i.second)); @@ -3541,7 +3541,7 @@ void GLCanvas3D::do_scale(const std::string& snapshot_type) for (int i = 0; i < static_cast(m_model->objects.size()); ++i) { const ModelObject* obj = m_model->objects[i]; for (int j = 0; j < static_cast(obj->instances.size()); ++j) { - min_zs[{ i, j }] = obj->instance_bounding_box(j).min(2); + min_zs[{ i, j }] = obj->instance_bounding_box(j).min.z(); } } } @@ -3583,7 +3583,7 @@ void GLCanvas3D::do_scale(const std::string& snapshot_type) #if ENABLE_ALLOW_NEGATIVE_Z double shift_z = m->get_instance_min_z(i.second); // leave sinking instances as sinking - if (min_zs.empty() || min_zs.find({ i.first, i.second })->second >= 0.0 || shift_z > 0.0) { + if (min_zs.empty() || min_zs.find({ i.first, i.second })->second >= SINKING_Z_THRESHOLD || shift_z > SINKING_Z_THRESHOLD) { Vec3d shift(0.0, 0.0, -shift_z); #else Vec3d shift(0.0, 0.0, -m->get_instance_min_z(i.second)); diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index cdffbc88d..701a6daa9 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -360,7 +360,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : if (0 <= idx && idx < static_cast(objects.size())) { const ModelObject* mo = wxGetApp().model().objects[idx]; const double min_z = mo->bounding_box().min.z(); - if (std::abs(min_z) > EPSILON) { + if (std::abs(min_z) > SINKING_Z_THRESHOLD) { Plater::TakeSnapshot snapshot(wxGetApp().plater(), _L("Drop to bed")); change_position_value(2, m_cache.position.z() - min_z); } @@ -702,7 +702,11 @@ void ObjectManipulation::update_reset_buttons_visibility() } show_rotation = !rotation.isApprox(Vec3d::Zero()); show_scale = !scale.isApprox(Vec3d::Ones()); +#if ENABLE_ALLOW_NEGATIVE_Z + show_drop_to_bed = std::abs(min_z) > SINKING_Z_THRESHOLD; +#else show_drop_to_bed = (std::abs(min_z) > EPSILON); +#endif // ENABLE_ALLOW_NEGATIVE_Z } wxGetApp().CallAfter([this, show_rotation, show_scale, show_drop_to_bed] { diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index ca87e244b..2e07d75c1 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3247,7 +3247,7 @@ void Plater::priv::reload_from_disk() ModelVolume* old_volume = old_model_object->volumes[sel_v.volume_idx]; #if ENABLE_ALLOW_NEGATIVE_Z - bool sinking = old_model_object->bounding_box().min.z() < 0.0; + bool sinking = old_model_object->bounding_box().min.z() < SINKING_Z_THRESHOLD; #endif // ENABLE_ALLOW_NEGATIVE_Z bool has_source = !old_volume->source.input_file.empty() && boost::algorithm::iequals(fs::path(old_volume->source.input_file).filename().string(), fs::path(path).filename().string()); @@ -4101,7 +4101,7 @@ bool Plater::priv::layers_height_allowed() const int obj_idx = get_selected_object_idx(); #if ENABLE_ALLOW_NEGATIVE_Z - return 0 <= obj_idx && obj_idx < (int)model.objects.size() && model.objects[obj_idx]->bounding_box().max.z() > 0.0 && + return 0 <= obj_idx && obj_idx < (int)model.objects.size() && model.objects[obj_idx]->bounding_box().max.z() > SINKING_Z_THRESHOLD && config->opt_bool("variable_layer_height") && view3D->is_layers_editing_allowed(); #else return 0 <= obj_idx && obj_idx < (int)model.objects.size() && config->opt_bool("variable_layer_height") && view3D->is_layers_editing_allowed(); @@ -6051,7 +6051,7 @@ void Plater::changed_objects(const std::vector& object_idxs) for (size_t obj_idx : object_idxs) { #if ENABLE_ALLOW_NEGATIVE_Z if (obj_idx < p->model.objects.size()) { - if (p->model.objects[obj_idx]->bounding_box().min.z() >= 0.0) + if (p->model.objects[obj_idx]->bounding_box().min.z() >= SINKING_Z_THRESHOLD) // re - align to Z = 0 p->model.objects[obj_idx]->ensure_on_bed(); }