From 7ddb64783b6094e3b1c5a8006e977c5308a6b841 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 24 Jul 2020 17:45:49 +0200 Subject: [PATCH] TriangleSelector: edge limit is derived from cursor size --- src/libslic3r/TriangleSelector.cpp | 10 ++++++++-- src/libslic3r/TriangleSelector.hpp | 5 +++-- src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.hpp | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/TriangleSelector.cpp b/src/libslic3r/TriangleSelector.cpp index 6e3f9f518..50d775ed8 100644 --- a/src/libslic3r/TriangleSelector.cpp +++ b/src/libslic3r/TriangleSelector.cpp @@ -35,14 +35,20 @@ void TriangleSelector::Triangle::set_division(int sides_to_split, int special_si void TriangleSelector::select_patch(const Vec3f& hit, int facet_start, const Vec3f& source, const Vec3f& dir, - float radius_sqr, FacetSupportType new_state) + float radius, FacetSupportType new_state) { assert(facet_start < m_orig_size_indices); assert(is_approx(dir.norm(), 1.f)); // Save current cursor center, squared radius and camera direction, // so we don't have to pass it around. - m_cursor = {hit, source, dir, radius_sqr}; + m_cursor = {hit, source, dir, radius*radius}; + + // In case user changed cursor size since last time, update triangle edge limit. + if (m_old_cursor_radius != radius) { + set_edge_limit(radius / 5.f); + m_old_cursor_radius = radius; + } // Now start with the facet the pointer points to and check all adjacent facets. std::vector facets_to_check{facet_start}; diff --git a/src/libslic3r/TriangleSelector.hpp b/src/libslic3r/TriangleSelector.hpp index 877bc122c..fb90cff76 100644 --- a/src/libslic3r/TriangleSelector.hpp +++ b/src/libslic3r/TriangleSelector.hpp @@ -1,7 +1,7 @@ #ifndef libslic3r_TriangleSelector_hpp_ #define libslic3r_TriangleSelector_hpp_ -#define PRUSASLICER_TRIANGLE_SELECTOR_DEBUG +// #define PRUSASLICER_TRIANGLE_SELECTOR_DEBUG #include "Point.hpp" @@ -28,7 +28,7 @@ public: int facet_start, // facet that point belongs to const Vec3f& source, // camera position (mesh coords) const Vec3f& dir, // direction of the ray (mesh coords) - float radius_sqr, // squared radius of the cursor + float radius, // radius of the cursor FacetSupportType new_state); // enforcer or blocker? // Get facets currently in the given state. @@ -130,6 +130,7 @@ protected: }; Cursor m_cursor; + float m_old_cursor_radius; // Private functions: bool select_triangle(int facet_idx, FacetSupportType type, diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp index 13c9cfef8..3769e9660 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp @@ -404,7 +404,7 @@ bool GLGizmoFdmSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous // FIXME: The scaling of the mesh can be non-uniform. const Vec3d sf = Geometry::Transformation(trafo_matrix).get_scaling_factor(); const float avg_scaling = (sf(0) + sf(1) + sf(2))/3.; - const float limit = std::pow(m_cursor_radius/avg_scaling , 2.f); + const float limit = m_cursor_radius/avg_scaling; // Calculate direction from camera to the hit (in mesh coords): Vec3f camera_pos = (trafo_matrix.inverse() * camera.get_position()).cast(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.hpp b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.hpp index 2d1442164..ce24ea8d2 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.hpp @@ -56,7 +56,7 @@ private: GLUquadricObj* m_quadric; float m_cursor_radius = 2.f; - static constexpr float CursorRadiusMin = 0.f; + static constexpr float CursorRadiusMin = 0.4f; // cannot be zero static constexpr float CursorRadiusMax = 8.f; static constexpr float CursorRadiusStep = 0.2f;