diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index f916fbdcd6..21b13cbc2b 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -1,3 +1,4 @@ +#include "libslic3r.h" #include "Exception.hpp" #include "Model.hpp" #include "ModelArrange.hpp" @@ -889,35 +890,22 @@ BoundingBoxf3 ModelObject::instance_bounding_box(size_t instance_idx, bool dont_ // Calculate 2D convex hull of of a projection of the transformed printable volumes into the XY plane. // This method is cheap in that it does not make any unnecessary copy of the volume meshes. // This method is used by the auto arrange function. +#if ENABLE_ALLOW_NEGATIVE_Z +Polygon ModelObject::convex_hull_2d(const Transform3d& trafo_instance) const +{ + Points pts; + for (const ModelVolume* v : volumes) { + if (v->is_model_part()) + append(pts, its_convex_hull_2d_above(v->mesh().its, (trafo_instance * v->get_matrix()).cast(), 0.0f).points); + } + return Geometry::convex_hull(std::move(pts)); +} +#else Polygon ModelObject::convex_hull_2d(const Transform3d &trafo_instance) const { Points pts; for (const ModelVolume *v : this->volumes) if (v->is_model_part()) { -#if ENABLE_ALLOW_NEGATIVE_Z - const Transform3d trafo = trafo_instance * v->get_matrix(); - const TriangleMesh& hull_3d = v->get_convex_hull(); - const indexed_triangle_set& its = hull_3d.its; - if (its.vertices.empty()) { - // Using the STL faces. - const stl_file& stl = hull_3d.stl; - for (const stl_facet& facet : stl.facet_start) { - for (size_t j = 0; j < 3; ++j) { - const Vec3d p = trafo * facet.vertex[j].cast(); - if (p.z() >= 0.0) - pts.emplace_back(coord_t(scale_(p.x())), coord_t(scale_(p.y()))); - } - } - } - else { - // Using the shared vertices should be a bit quicker than using the STL faces. - for (size_t i = 0; i < its.vertices.size(); ++i) { - const Vec3d p = trafo * its.vertices[i].cast(); - if (p.z() >= 0.0) - pts.emplace_back(coord_t(scale_(p.x())), coord_t(scale_(p.y()))); - } - } -#else Transform3d trafo = trafo_instance * v->get_matrix(); const indexed_triangle_set &its = v->mesh().its; if (its.vertices.empty()) { @@ -935,10 +923,10 @@ Polygon ModelObject::convex_hull_2d(const Transform3d &trafo_instance) const pts.emplace_back(coord_t(scale_(p.x())), coord_t(scale_(p.y()))); } } -#endif // ENABLE_ALLOW_NEGATIVE_Z } return Geometry::convex_hull(std::move(pts)); } +#endif // ENABLE_ALLOW_NEGATIVE_Z void ModelObject::center_around_origin(bool include_modifiers) {