Skip to content

Commit

Permalink
Lay flat - limit number of active surfaces to 255 (to avoid problems …
Browse files Browse the repository at this point in the history
…with picking pass)
  • Loading branch information
lukasmatena committed Aug 21, 2018
1 parent 86b67bb commit 9e6234f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion xs/src/slic3r/GUI/GLGizmo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions xs/src/slic3r/GUI/GLGizmo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class GLGizmoFlatten : public GLGizmoBase
struct PlaneData {
std::vector<Pointf3> vertices;
Pointf3 normal;
float area;
};
struct SourceDataSummary {
std::vector<BoundingBoxf3> bounding_boxes; // bounding boxes of convex hulls of individual volumes
Expand Down

0 comments on commit 9e6234f

Please sign in to comment.