From 9e6234fe3964696740caf3c9743076a5f43bf681 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 21 Aug 2018 15:56:40 +0200 Subject: [PATCH] Lay flat - limit number of active surfaces to 255 (to avoid problems with picking pass) --- xs/src/slic3r/GUI/GLGizmo.cpp | 7 ++++++- xs/src/slic3r/GUI/GLGizmo.hpp | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/xs/src/slic3r/GUI/GLGizmo.cpp b/xs/src/slic3r/GUI/GLGizmo.cpp index fd4d205fb..9ef12c813 100644 --- a/xs/src/slic3r/GUI/GLGizmo.cpp +++ b/xs/src/slic3r/GUI/GLGizmo.cpp @@ -709,7 +709,8 @@ void GLGizmoFlatten::update_planes() // We will calculate area of the polygon and discard ones that are too small // The limit is more forgiving in case the normal is in the direction of the coordinate axes const float minimal_area = (std::abs(normal.x) > 0.999f || std::abs(normal.y) > 0.999f || std::abs(normal.z) > 0.999f) ? 1.f : 20.f; - float area = 0.f; + float& area = m_planes[polygon_id].area; + area = 0.f; for (unsigned int i = 0; i < polygon.size(); i++) // Shoelace formula area += polygon[i].x*polygon[i+1 < polygon.size() ? i+1 : 0 ].y - polygon[i+1 < polygon.size() ? i+1 : 0].x*polygon[i].y; area = std::abs(area/2.f); @@ -771,6 +772,10 @@ void GLGizmoFlatten::update_planes() } } + // We'll sort the planes by area and only keep the 255 largest ones (because of the picking pass limitations): + std::sort(m_planes.rbegin(), m_planes.rend(), [](const PlaneData& a, const PlaneData& b) { return a.area < b.area; }); + m_planes.resize(std::min((int)m_planes.size(), 255)); + // Planes are finished - let's save what we calculated it from: m_source_data.bounding_boxes.clear(); for (const auto& vol : m_model_object->volumes) diff --git a/xs/src/slic3r/GUI/GLGizmo.hpp b/xs/src/slic3r/GUI/GLGizmo.hpp index 2c82f73f3..aad31349c 100644 --- a/xs/src/slic3r/GUI/GLGizmo.hpp +++ b/xs/src/slic3r/GUI/GLGizmo.hpp @@ -161,6 +161,7 @@ private: struct PlaneData { std::vector vertices; Pointf3 normal; + float area; }; struct SourceDataSummary { std::vector bounding_boxes; // bounding boxes of convex hulls of individual volumes