diff --git a/src/libslic3r/BoundingBox.hpp b/src/libslic3r/BoundingBox.hpp index 5e9575b015..9f1d16b27a 100644 --- a/src/libslic3r/BoundingBox.hpp +++ b/src/libslic3r/BoundingBox.hpp @@ -147,6 +147,16 @@ public: return this->min.x() < other.max.x() && this->max.x() > other.min.x() && this->min.y() < other.max.y() && this->max.y() > other.min.y() && this->min.z() < other.max.z() && this->max.z() > other.min.z(); } + + // Shares some boundary. + bool shares_boundary(const BoundingBox3Base& other) const { + return is_approx(this->min.x(), other.max.x()) || + is_approx(this->max.x(), other.min.x()) || + is_approx(this->min.y(), other.max.y()) || + is_approx(this->max.y(), other.min.y()) || + is_approx(this->min.z(), other.max.z()) || + is_approx(this->max.z(), other.min.z()); + } }; // Will prevent warnings caused by non existing definition of template in hpp diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 6878c0c6b1..9d061dfef1 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -425,18 +425,21 @@ bool Model::looks_like_multipart_object() const { if (this->objects.size() <= 1) return false; - double zmin = std::numeric_limits::max(); + + BoundingBoxf3 tbb; + for (const ModelObject *obj : this->objects) { if (obj->volumes.size() > 1 || obj->config.keys().size() > 1) return false; - for (const ModelVolume *vol : obj->volumes) { - double zmin_this = vol->mesh().bounding_box().min(2); - if (zmin == std::numeric_limits::max()) - zmin = zmin_this; - else if (std::abs(zmin - zmin_this) > EPSILON) - // The volumes don't share zmin. - return true; - } + + BoundingBoxf3 bb_this = obj->volumes[0]->mesh().bounding_box(); + BoundingBoxf3 tbb_this = obj->instances[0]->transform_bounding_box(bb_this); + + if (!tbb.defined) + tbb = tbb_this; + else if (tbb.intersects(tbb_this) || tbb.shares_boundary(tbb_this)) + // The volumes has intersects bounding boxes or share some boundary + return true; } return false; }