diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index f13c6084b3..02275aeda3 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -31,7 +31,6 @@ set(SLIC3R_GUI_SOURCES GUI/GLCanvas3DManager.cpp GUI/Selection.hpp GUI/Selection.cpp - GUI/Gizmos/GLGizmos.hpp GUI/Gizmos/GLGizmosManager.cpp GUI/Gizmos/GLGizmosManager.hpp GUI/Gizmos/GLGizmosCommon.cpp diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 74abbebdd5..064f01cf2a 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1,5 +1,4 @@ #include "libslic3r/libslic3r.h" -#include "slic3r/GUI/Gizmos/GLGizmos.hpp" #include "GLCanvas3D.hpp" #include "admesh/stl.h" diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp index 3c82806caf..3c7e7a2366 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp @@ -1,7 +1,6 @@ #include "GLGizmoHollow.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" #include "slic3r/GUI/Camera.hpp" -#include "slic3r/GUI/Gizmos/GLGizmos.hpp" #include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" #include @@ -63,34 +62,6 @@ void GLGizmoHollow::set_sla_support_data(ModelObject*, const Selection&) if (m_c->hollowed_mesh()->get_hollowed_mesh()) m_holes_in_drilled_mesh = mo->sla_drain_holes; } - - /*if (m_c->recent_update) { - - if (m_state == On) - m_c->build_AABB_if_needed(); - - update_clipping_plane(m_c->m_clipping_plane_was_moved); - - // This is a temporary and not very nice hack, to make sure that - // if the cp was moved by the data returned by backend, it will - // remember its direction. FIXME: Refactor this mess and make - // the clipping plane itself part of the shared data. - if (! m_c->m_clipping_plane_was_moved && m_c->m_clipping_plane_distance == 0.25f) - m_c->m_clipping_plane_was_moved = true; - - - if (m_c->m_model_object) { - reload_cache(); - if (m_c->has_drilled_mesh()) - m_holes_in_drilled_mesh = m_c->m_model_object->sla_drain_holes; - } - } - - if (m_state == On) { - m_parent.toggle_model_objects_visibility(false); - m_parent.toggle_model_objects_visibility(true, m_c->m_model_object, m_c->m_active_instance); - m_parent.toggle_sla_auxiliaries_visibility(m_show_supports, m_c->m_model_object, m_c->m_active_instance); - }*/ } @@ -111,13 +82,10 @@ void GLGizmoHollow::on_render() const glsafe(::glEnable(GL_BLEND)); glsafe(::glEnable(GL_DEPTH_TEST)); - //m_z_shift = selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z(); - if (m_quadric != nullptr && selection.is_from_single_instance()) render_points(selection, false); m_selection_rectangle.render(m_parent); - //render_clipping_plane(selection); m_c->object_clipper()->render_cut(); m_c->supports_clipper()->render_cut(); @@ -125,83 +93,6 @@ void GLGizmoHollow::on_render() const } - -void GLGizmoHollow::render_clipping_plane(const Selection& selection) const -{ - return; -/* - if (m_c->m_clipping_plane_distance == 0.f) - return; - - // Get transformation of the instance - const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin()); - Geometry::Transformation trafo = vol->get_instance_transformation(); - trafo.set_offset(trafo.get_offset() + Vec3d(0., 0., m_z_shift)); - - // Get transformation of supports - Geometry::Transformation supports_trafo; - supports_trafo.set_offset(Vec3d(trafo.get_offset()(0), trafo.get_offset()(1), vol->get_sla_shift_z())); - supports_trafo.set_rotation(Vec3d(0., 0., trafo.get_rotation()(2))); - // I don't know why, but following seems to be correct. - supports_trafo.set_mirror(Vec3d(trafo.get_mirror()(0) * trafo.get_mirror()(1) * trafo.get_mirror()(2), - 1, - 1.)); - - // Now initialize the TMS for the object, perform the cut and save the result. - if (! m_c->m_object_clipper) { - m_c->m_object_clipper.reset(new MeshClipper); - m_c->m_object_clipper->set_mesh(*m_c->mesh()); - } - m_c->m_object_clipper->set_plane(*m_c->m_clipping_plane); - m_c->m_object_clipper->set_transformation(trafo); - - if (m_c->m_print_object_idx >= 0) { - const SLAPrintObject* print_object = m_parent.sla_print()->objects()[m_c->m_print_object_idx]; - - if (print_object->is_step_done(slaposSupportTree) && !print_object->get_mesh(slaposSupportTree).empty()) { - // If the supports are already calculated, save the timestamp of the respective step - // so we can later tell they were recalculated. - size_t timestamp = print_object->step_state_with_timestamp(slaposSupportTree).timestamp; - - if (! m_c->m_supports_clipper || (int)timestamp != m_c->m_old_timestamp) { - // The timestamp has changed. - m_c->m_supports_clipper.reset(new MeshClipper); - // The mesh should already have the shared vertices calculated. - m_c->m_supports_clipper->set_mesh(print_object->support_mesh()); - m_c->m_old_timestamp = timestamp; - } - m_c->m_supports_clipper->set_plane(*m_c->m_clipping_plane); - m_c->m_supports_clipper->set_transformation(supports_trafo); - } - else - // The supports are not valid. We better dump the cached data. - m_c->m_supports_clipper.reset(); - } - - // At this point we have the triangulated cuts for both the object and supports - let's render. - if (! m_c->m_object_clipper->get_triangles().empty()) { - ::glPushMatrix(); - ::glColor3f(1.0f, 0.37f, 0.0f); - ::glBegin(GL_TRIANGLES); - for (const Vec3f& point : m_c->m_object_clipper->get_triangles()) - ::glVertex3f(point(0), point(1), point(2)); - ::glEnd(); - ::glPopMatrix(); - } - - if (m_show_supports && m_c->m_supports_clipper && ! m_c->m_supports_clipper->get_triangles().empty()) { - ::glPushMatrix(); - ::glColor3f(1.0f, 0.f, 0.37f); - ::glBegin(GL_TRIANGLES); - for (const Vec3f& point : m_c->m_supports_clipper->get_triangles()) - ::glVertex3f(point(0), point(1), point(2)); - ::glEnd(); - ::glPopMatrix(); - } -*/ -} - - void GLGizmoHollow::on_render_for_picking() const { const Selection& selection = m_parent.get_selection(); @@ -272,7 +163,6 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) cons glFrontFace(GL_CW); // Matrices set, we can render the point mark now. - Eigen::Quaterniond q; q.setFromTwoVectors(Vec3d{0., 0., 1.}, instance_scaling_matrix_inverse * (-drain_hole.normal).cast()); Eigen::AngleAxisd aa(q); @@ -456,13 +346,9 @@ bool GLGizmoHollow::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_pos points_inside.push_back(points[idx].cast()); // Only select/deselect points that are actually visible -#if ENABLE_NON_STATIC_CANVAS_MANAGER for (size_t idx : m_c->raycaster()->raycaster()->get_unobscured_idxs( trafo, wxGetApp().plater()->get_camera(), points_inside, m_c->object_clipper()->get_clipping_plane())) -#else - for (size_t idx : m_c->m_mesh_raycaster->get_unobscured_idxs(trafo, m_parent.get_camera(), points_inside, m_c->m_clipping_plane.get())) -#endif // ENABLE_NON_STATIC_CANVAS_MANAGER { if (rectangle_status == GLSelectionRectangle::Deselect) unselect_point(points_idxs[idx]); @@ -519,8 +405,6 @@ bool GLGizmoHollow::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_pos double pos = m_c->object_clipper()->get_position(); pos = std::min(1., pos + 0.01); m_c->object_clipper()->set_position(pos, true); - //update_clipping_plane(/*m_c->m_clipping_plane_was_moved*/); - //m_c->m_clipping_plane_was_moved = true; return true; } @@ -528,7 +412,6 @@ bool GLGizmoHollow::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_pos double pos = m_c->object_clipper()->get_position(); pos = std::max(0., pos - 0.01); m_c->object_clipper()->set_position(pos, true); - //update_clipping_plane(true); return true; } @@ -607,19 +490,6 @@ GLGizmoHollow::get_config_options(const std::vector& keys) const return out; } -/* -ClippingPlane GLGizmoHollow::get_sla_clipping_plane() const -{ - if (! m_c->selection_info()->model_object() - || m_state == Off - || m_c->object_clipper()->get_position() == 0.) - return ClippingPlane::ClipsNothing(); - else { - const ClippingPlane& clp = *m_c->object_clipper()->get_clipping_plane(); - return ClippingPlane(-clp.get_normal(), clp.get_data()[3]); - } -} -*/ void GLGizmoHollow::on_render_input_window(float x, float y, float bottom_limit) { @@ -863,7 +733,6 @@ RENDER_AGAIN: // make sure supports are shown/hidden as appropriate bool show_sups = m_c->instances_hider()->are_supports_shown(); if (m_imgui->checkbox(m_desc["show_supports"], show_sups)) { - // m_parent.toggle_sla_auxiliaries_visibility(m_show_supports, mo, m_c->m_active_instance); m_c->instances_hider()->show_supports(show_sups); force_refresh = true; } @@ -937,51 +806,16 @@ CommonGizmosDataID GLGizmoHollow::on_get_requirements() const void GLGizmoHollow::on_set_state() { - // m_c->m_model_object pointer can be invalid (for instance because of undo/redo action), - // we should recover it from the object id - /*m_c->m_model_object = nullptr; - for (const auto mo : wxGetApp().model().objects) { - if (mo->id() == m_c->m_model_object_id) { - m_c->m_model_object = mo; - break; - } - }*/ - if (m_state == m_old_state) return; if (m_state == On && m_old_state != On) { // the gizmo was just turned on - //Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("SLA gizmo turned on"))); - //m_c->update_from_backend(m_parent, m_c->m_model_object); - //m_c->unstash_clipping_plane(); - //update_clipping_plane(/*m_c->m_clipping_plane_was_moved*/); - - //m_c->build_AABB_if_needed(); - // we'll now reload support points: if (m_c->selection_info()->model_object()) reload_cache(); - - /*m_parent.toggle_model_objects_visibility(false); - if (m_c->m_model_object) { - m_parent.toggle_model_objects_visibility(true, m_c->m_model_object, m_c->m_active_instance); - m_parent.toggle_sla_auxiliaries_visibility(m_show_supports, m_c->m_model_object, m_c->m_active_instance); - }*/ } - if (m_state == Off && m_old_state != Off) { // the gizmo was just turned Off - //Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("SLA gizmo turned off"))); + if (m_state == Off && m_old_state != Off) // the gizmo was just turned Off m_parent.post_event(SimpleEvent(EVT_GLCANVAS_FORCE_UPDATE)); - //m_parent.toggle_model_objects_visibility(true); - //m_c->stash_clipping_plane(); - //m_c->m_clipping_plane_distance = 0.f; - //update_clipping_plane(true); - // Release clippers and the AABB raycaster. - //m_c->m_object_clipper.reset(); - //m_c->m_supports_clipper.reset(); - //m_c->m_mesh_raycaster.reset(); - //m_c->m_cavity_mesh.reset(); - //m_c->m_volume_with_cavity.reset(); - } m_old_state = m_state; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp index 73d26b2da3..3ee83c3454 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp @@ -13,16 +13,11 @@ namespace Slic3r { namespace GUI { -class ClippingPlane; -class MeshClipper; -class MeshRaycaster; -//class CommonGizmosData; enum class SLAGizmoEventType : unsigned char; class GLGizmoHollow : public GLGizmoBase { private: - //mutable double m_z_shift = 0.; bool unproject_on_mesh(const Vec2d& mouse_pos, std::pair& pos_and_normal); GLUquadricObj* m_quadric; @@ -33,11 +28,10 @@ public: ~GLGizmoHollow() override; void set_sla_support_data(ModelObject* model_object, const Selection& selection); bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down); - void delete_selected_points(); - //ClippingPlane get_sla_clipping_plane() const; - - bool is_selection_rectangle_dragging() const { return m_selection_rectangle.is_dragging(); } - //void set_common_data_ptr(CommonGizmosData* ptr) { m_c = ptr; } + void delete_selected_points(); + bool is_selection_rectangle_dragging() const { + return m_selection_rectangle.is_dragging(); + } private: bool on_init() override; @@ -46,7 +40,6 @@ private: void on_render_for_picking() const override; void render_points(const Selection& selection, bool picking = false) const; - void render_clipping_plane(const Selection& selection) const; void hollow_mesh(bool postpone_error_messages = false); bool unsaved_changes() const; @@ -66,10 +59,6 @@ private: sla::DrainHoles m_holes_in_drilled_mesh; sla::DrainHoles m_holes_stash; - - //CommonGizmosData* m_c = nullptr; - - //std::unique_ptr m_clipping_plane; // This map holds all translated description texts, so they can be easily referenced during layout calculations // etc. When language changes, GUI is recreated and this class constructed again, so the change takes effect. diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 16ac6ec3c5..496568d51a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -2,7 +2,6 @@ #include "GLGizmoSlaSupports.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" #include "slic3r/GUI/Camera.hpp" -#include "slic3r/GUI/Gizmos/GLGizmos.hpp" #include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" #include @@ -15,7 +14,6 @@ #include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/GUI_ObjectSettings.hpp" #include "slic3r/GUI/GUI_ObjectList.hpp" -#include "slic3r/GUI/MeshUtils.hpp" #include "slic3r/GUI/Plater.hpp" #include "slic3r/GUI/PresetBundle.hpp" #include "libslic3r/SLAPrint.hpp" @@ -27,7 +25,6 @@ namespace GUI { GLGizmoSlaSupports::GLGizmoSlaSupports(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) : GLGizmoBase(parent, icon_filename, sprite_id) , m_quadric(nullptr) - , m_its(nullptr) { m_quadric = ::gluNewQuadric(); if (m_quadric != nullptr) @@ -76,24 +73,6 @@ void GLGizmoSlaSupports::set_sla_support_data(ModelObject* model_object, const S m_old_mo = mo; } - /* - if (m_c->recent_update) { - if (m_state == On) - m_c->build_AABB_if_needed(); - - update_clipping_plane(m_c->m_clipping_plane_was_moved); - - disable_editing_mode(); - if (m_c->m_model_object) - reload_cache(); - } - - if (m_state == On) { - m_parent.toggle_model_objects_visibility(false); - m_parent.toggle_model_objects_visibility(true, m_c->m_model_object, m_c->m_active_instance); - m_parent.toggle_sla_auxiliaries_visibility(! m_editing_mode, m_c->m_model_object, m_c->m_active_instance); - }*/ - // If we triggered autogeneration before, check backend and fetch results if they are there if (mo) { if (mo->sla_points_status == sla::PointsStatus::Generating) @@ -111,8 +90,7 @@ void GLGizmoSlaSupports::on_render() const // If current m_c->m_model_object does not match selection, ask GLCanvas3D to turn us off if (m_state == On && (mo != selection.get_model()->objects[selection.get_object_idx()] - || m_c->selection_info()->get_active_instance() != selection.get_instance_idx() - /*|| m_c->m_model_object_id != m_c->m_model_object->id()*/)) { + || m_c->selection_info()->get_active_instance() != selection.get_instance_idx())) { m_parent.post_event(SimpleEvent(EVT_GLCANVAS_RESETGIZMOS)); return; } @@ -120,116 +98,20 @@ void GLGizmoSlaSupports::on_render() const glsafe(::glEnable(GL_BLEND)); glsafe(::glEnable(GL_DEPTH_TEST)); -// m_z_shift = selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z(); - if (m_quadric != nullptr && selection.is_from_single_instance()) render_points(selection, false); m_selection_rectangle.render(m_parent); m_c->object_clipper()->render_cut(); m_c->supports_clipper()->render_cut(); - //render_clipping_plane(selection); glsafe(::glDisable(GL_BLEND)); } - -/*void GLGizmoSlaSupports::render_clipping_plane(const Selection& selection) const -{ - if (m_c->m_clipping_plane_distance == 0.f || m_c->m_mesh->empty()) - return; - - // Get transformation of the instance - const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin()); - Geometry::Transformation trafo = vol->get_instance_transformation(); - trafo.set_offset(trafo.get_offset() + Vec3d(0., 0., m_z_shift)); - - // Get transformation of supports - Geometry::Transformation supports_trafo; - supports_trafo.set_offset(Vec3d(trafo.get_offset()(0), trafo.get_offset()(1), vol->get_sla_shift_z())); - supports_trafo.set_rotation(Vec3d(0., 0., trafo.get_rotation()(2))); - // I don't know why, but following seems to be correct. - supports_trafo.set_mirror(Vec3d(trafo.get_mirror()(0) * trafo.get_mirror()(1) * trafo.get_mirror()(2), - 1, - 1.)); - - // Now initialize the TMS for the object, perform the cut and save the result. - if (! m_c->m_object_clipper) { - m_c->m_object_clipper.reset(new MeshClipper); - m_c->m_object_clipper->set_mesh(*m_c->mesh()); - } - m_c->m_object_clipper->set_plane(*m_c->m_clipping_plane); - m_c->m_object_clipper->set_transformation(trafo); - - - // Next, ask the backend if supports are already calculated. If so, we are gonna cut them too. - // First we need a pointer to the respective SLAPrintObject. The index into objects vector is - // cached so we don't have todo it on each render. We only search for the po if needed: - if (m_c->m_print_object_idx < 0 || (int)m_parent.sla_print()->objects().size() != m_c->m_print_objects_count) { - m_c->m_print_objects_count = m_parent.sla_print()->objects().size(); - m_c->m_print_object_idx = -1; - for (const SLAPrintObject* po : m_parent.sla_print()->objects()) { - ++m_c->m_print_object_idx; - if (po->model_object()->id() == m_c->m_model_object->id()) - break; - } - } - if (m_c->m_print_object_idx >= 0) { - const SLAPrintObject* print_object = m_parent.sla_print()->objects()[m_c->m_print_object_idx]; - - if (print_object->is_step_done(slaposSupportTree) && !print_object->get_mesh(slaposSupportTree).empty()) { - // If the supports are already calculated, save the timestamp of the respective step - // so we can later tell they were recalculated. - size_t timestamp = print_object->step_state_with_timestamp(slaposSupportTree).timestamp; - - if (! m_c->m_supports_clipper || (int)timestamp != m_c->m_old_timestamp) { - // The timestamp has changed. - m_c->m_supports_clipper.reset(new MeshClipper); - // The mesh should already have the shared vertices calculated. - m_c->m_supports_clipper->set_mesh(print_object->support_mesh()); - m_c->m_old_timestamp = timestamp; - } - m_c->m_supports_clipper->set_plane(*m_c->m_clipping_plane); - m_c->m_supports_clipper->set_transformation(supports_trafo); - } - else - // The supports are not valid. We better dump the cached data. - m_c->m_supports_clipper.reset(); - } - - // At this point we have the triangulated cuts for both the object and supports - let's render. - if (! m_c->m_object_clipper->get_triangles().empty()) { - ::glPushMatrix(); - ::glColor3f(1.0f, 0.37f, 0.0f); - ::glBegin(GL_TRIANGLES); - for (const Vec3f& point : m_c->m_object_clipper->get_triangles()) - ::glVertex3f(point(0), point(1), point(2)); - ::glEnd(); - ::glPopMatrix(); - } - - if (m_c->m_supports_clipper && ! m_c->m_supports_clipper->get_triangles().empty() && !m_editing_mode) { - // The supports are hidden in the editing mode, so it makes no sense to render the cuts. - ::glPushMatrix(); - ::glColor3f(1.0f, 0.f, 0.37f); - ::glBegin(GL_TRIANGLES); - for (const Vec3f& point : m_c->m_supports_clipper->get_triangles()) - ::glVertex3f(point(0), point(1), point(2)); - ::glEnd(); - ::glPopMatrix(); - } -}*/ - - void GLGizmoSlaSupports::on_render_for_picking() const { const Selection& selection = m_parent.get_selection(); -/* -#if ENABLE_RENDER_PICKING_PASS - m_z_shift = selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z(); -#endif -*/ glsafe(::glEnable(GL_DEPTH_TEST)); render_points(selection, true); } @@ -404,11 +286,7 @@ bool GLGizmoSlaSupports::unproject_on_mesh(const Vec2d& mouse_pos, std::pairraycaster()->raycaster()) return false; -#if ENABLE_NON_STATIC_CANVAS_MANAGER const Camera& camera = wxGetApp().plater()->get_camera(); -#else - const Camera& camera = m_parent.get_camera(); -#endif // ENABLE_NON_STATIC_CANVAS_MANAGER const Selection& selection = m_parent.get_selection(); const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); Geometry::Transformation trafo = volume->get_instance_transformation(); @@ -607,8 +485,6 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous double pos = m_c->object_clipper()->get_position(); pos = std::min(1., pos + 0.01); m_c->object_clipper()->set_position(pos, true); - //update_clipping_plane(/*m_c->m_clipping_plane_was_moved*/); - //m_c->m_clipping_plane_was_moved = true; return true; } @@ -616,12 +492,10 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous double pos = m_c->object_clipper()->get_position(); pos = std::max(0., pos - 0.01); m_c->object_clipper()->set_position(pos, true); - //update_clipping_plane(true); return true; } if (action == SLAGizmoEventType::ResetClippingPlane) { - //update_clipping_plane(); m_c->object_clipper()->set_position(-1., false); return true; } @@ -691,23 +565,7 @@ std::vector GLGizmoSlaSupports::get_config_options(const st return out; } -/* -ClippingPlane GLGizmoSlaSupports::get_sla_clipping_plane() const -{ - //if (!m_c->m_model_object || m_state == Off || m_c->m_clipping_plane_distance == 0.f) - // return ClippingPlane::ClipsNothing(); - //else - // return ClippingPlane(-m_c->m_clipping_plane->get_normal(), m_c->m_clipping_plane->get_data()[3]); - if (! m_c->selection_info()->model_object() - || m_state == Off - || m_c->object_clipper()->get_position() == 0.) - return ClippingPlane::ClipsNothing(); - else { - const ClippingPlane& clp = *m_c->object_clipper()->get_clipping_plane(); - return ClippingPlane(-clp.get_normal(), clp.get_data()[3]); - } -} -*/ + /* void GLGizmoSlaSupports::find_intersecting_facets(const igl::AABB* aabb, const Vec3f& normal, double offset, std::vector& idxs) const @@ -937,7 +795,6 @@ RENDER_AGAIN: else { if (m_imgui->button(m_desc.at("reset_direction"))) { wxGetApp().CallAfter([this](){ - //update_clipping_plane(); m_c->object_clipper()->set_position(-1., false); }); } @@ -1028,15 +885,6 @@ CommonGizmosDataID GLGizmoSlaSupports::on_get_requirements() const void GLGizmoSlaSupports::on_set_state() { const ModelObject* mo = m_c->selection_info()->model_object(); - // m_c->m_model_object pointer can be invalid (for instance because of undo/redo action), - // we should recover it from the object id - /*m_c->m_model_object = nullptr; - for (const auto mo : wxGetApp().model().objects) { - if (mo->id() == m_c->m_model_object_id) { - m_c->m_model_object = mo; - break; - } - }*/ if (m_state == m_old_state) return; @@ -1044,22 +892,10 @@ void GLGizmoSlaSupports::on_set_state() if (m_state == On && m_old_state != On) { // the gizmo was just turned on Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("SLA gizmo turned on"))); - //m_c->unstash_clipping_plane(); - //update_clipping_plane(m_c->m_clipping_plane_was_moved); - - //m_c->build_AABB_if_needed(); - - // we'll now reload support points: if (mo) reload_cache(); - /*m_parent.toggle_model_objects_visibility(false); - if (m_c->m_model_object) { - m_parent.toggle_model_objects_visibility(true, m_c->m_model_object, m_c->m_active_instance); - m_parent.toggle_sla_auxiliaries_visibility(! m_editing_mode, m_c->m_model_object, m_c->m_active_instance); - }*/ - // Set default head diameter from config. const DynamicPrintConfig& cfg = wxGetApp().preset_bundle->sla_prints.get_edited_preset().config; m_new_point_head_diameter = static_cast(cfg.option("support_head_front_diameter"))->value; @@ -1084,16 +920,8 @@ void GLGizmoSlaSupports::on_set_state() // we are actually shutting down disable_editing_mode(); // so it is not active next time the gizmo opens Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("SLA gizmo turned off"))); - //m_parent.toggle_model_objects_visibility(true); m_normal_cache.clear(); - //m_c->stash_clipping_plane(); - //m_c->m_clipping_plane_distance = 0.f; - //update_clipping_plane(true); - // Release clippers and the AABB raycaster. - //m_its = nullptr; - //m_c->m_object_clipper.reset(); - //m_c->m_supports_clipper.reset(); - //m_c->m_mesh_raycaster.reset(); + } } m_old_state = m_state; @@ -1318,7 +1146,6 @@ void GLGizmoSlaSupports::switch_to_editing_mode() m_editing_cache.emplace_back(sp); select_point(NoPoints); - //m_parent.toggle_sla_auxiliaries_visibility(false, m_c->m_model_object, m_c->m_active_instance); m_c->instances_hider()->show_supports(false); m_parent.set_as_dirty(); } @@ -1329,7 +1156,6 @@ void GLGizmoSlaSupports::disable_editing_mode() if (m_editing_mode) { m_editing_mode = false; wxGetApp().plater()->leave_gizmos_stack(); - //m_parent.toggle_sla_auxiliaries_visibility(true, m_c->m_model_object, m_c->m_active_instance); m_c->instances_hider()->show_supports(true); m_parent.set_as_dirty(); } @@ -1349,26 +1175,6 @@ bool GLGizmoSlaSupports::unsaved_changes() const return false; } -/* -void GLGizmoSlaSupports::update_clipping_plane(bool keep_normal) const -{ - if (! m_c->m_model_object) - return; - -#if ENABLE_NON_STATIC_CANVAS_MANAGER - Vec3d normal = (keep_normal && m_c->m_clipping_plane->get_normal() != Vec3d::Zero() ? - m_c->m_clipping_plane->get_normal() : -wxGetApp().plater()->get_camera().get_dir_forward()); -#else - Vec3d normal = (keep_normal && m_c->m_clipping_plane->get_normal() != Vec3d::Zero() ? - m_c->m_clipping_plane->get_normal() : -m_parent.get_camera().get_dir_forward()); -#endif // ENABLE_NON_STATIC_CANVAS_MANAGER - - const Vec3d& center = m_c->m_model_object->instances[m_c->m_active_instance]->get_offset() + Vec3d(0., 0., m_z_shift); - float dist = normal.dot(center); - *m_c->m_clipping_plane = ClippingPlane(normal, (dist - (-m_c->m_active_instance_bb_radius) - m_c->m_clipping_plane_distance * 2*m_c->m_active_instance_bb_radius)); - m_parent.set_as_dirty(); -}*/ - SlaGizmoHelpDialog::SlaGizmoHelpDialog() : wxDialog(nullptr, wxID_ANY, _(L("SLA gizmo keyboard shortcuts")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER) { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp index 2b7b1ae784..43454609a1 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp @@ -13,20 +13,12 @@ namespace Slic3r { namespace GUI { -class ClippingPlane; -class MeshClipper; -class MeshRaycaster; -//class CommonGizmosData; enum class SLAGizmoEventType : unsigned char; class GLGizmoSlaSupports : public GLGizmoBase { private: - //ModelObject* m_model_object = nullptr; - //ObjectID m_model_object_id = 0; - //int m_active_instance = -1; - //float m_active_instance_bb_radius; // to cache the bb - //mutable double m_z_shift = 0.f; + bool unproject_on_mesh(const Vec2d& mouse_pos, std::pair& pos_and_normal); const float RenderPointScale = 1.f; @@ -35,13 +27,6 @@ private: typedef Eigen::Map> MapMatrixXfUnaligned; typedef Eigen::Map> MapMatrixXiUnaligned; - //std::unique_ptr m_mesh_raycaster; - //const TriangleMesh* m_mesh; - const indexed_triangle_set* m_its; - //mutable int m_old_timestamp = -1; - //mutable int m_print_object_idx = -1; - //mutable int m_print_objects_count = -1; - class CacheEntry { public: CacheEntry() : @@ -81,8 +66,6 @@ public: bool is_selection_rectangle_dragging() const { return m_selection_rectangle.is_dragging(); } bool has_backend_supports() const; void reslice_SLA_supports(bool postpone_error_messages = false) const; - //void update_clipping_plane(bool keep_normal = false) const; - //void set_common_data_ptr(CommonGizmosData* ptr) { m_c = ptr; } private: bool on_init() override; @@ -90,9 +73,7 @@ private: void on_render() const override; void on_render_for_picking() const override; - //void render_selection_rectangle() const; void render_points(const Selection& selection, bool picking = false) const; - //void render_clipping_plane(const Selection& selection) const; bool unsaved_changes() const; bool m_lock_unique_islands = false; @@ -106,8 +87,6 @@ private: std::vector m_normal_cache; // to restore after discarding changes or undo/redo const ModelObject* m_old_mo = nullptr; - //std::unique_ptr m_clipping_plane; - // This map holds all translated description texts, so they can be easily referenced during layout calculations // etc. When language changes, GUI is recreated and this class constructed again, so the change takes effect. std::map m_desc; @@ -118,11 +97,6 @@ private: bool m_selection_empty = true; EState m_old_state = Off; // to be able to see that the gizmo has just been closed (see on_set_state) - //CommonGizmosData* m_c = nullptr; - - //mutable std::unique_ptr m_object_clipper; - //mutable std::unique_ptr m_supports_clipper; - std::vector get_config_options(const std::vector& keys) const; bool is_mesh_point_clipped(const Vec3d& point) const; bool is_point_in_hole(const Vec3f& pt) const; diff --git a/src/slic3r/GUI/Gizmos/GLGizmos.hpp b/src/slic3r/GUI/Gizmos/GLGizmos.hpp deleted file mode 100644 index 9f97c42b46..0000000000 --- a/src/slic3r/GUI/Gizmos/GLGizmos.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef slic3r_GLGizmos_hpp_ -#define slic3r_GLGizmos_hpp_ - -// this describes events being passed from GLCanvas3D to SlaSupport gizmo -namespace Slic3r { -namespace GUI { - -enum class SLAGizmoEventType : unsigned char { - LeftDown = 1, - LeftUp, - RightDown, - Dragging, - Delete, - SelectAll, - ShiftUp, - AltUp, - ApplyChanges, - DiscardChanges, - AutomaticGeneration, - ManualEditing, - MouseWheelUp, - MouseWheelDown, - ResetClippingPlane -}; - -} // namespace GUI -} // namespace Slic3r - -#include "slic3r/GUI/Gizmos/GLGizmoMove.hpp" -#include "slic3r/GUI/Gizmos/GLGizmoScale.hpp" -#include "slic3r/GUI/Gizmos/GLGizmoRotate.hpp" -#include "slic3r/GUI/Gizmos/GLGizmoFlatten.hpp" -#include "slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp" -#include "slic3r/GUI/Gizmos/GLGizmoCut.hpp" -#include "slic3r/GUI/Gizmos/GLGizmoHollow.hpp" - -#endif //slic3r_GLGizmos_hpp_ diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp index 54e561f2f8..ba0c310bf8 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp @@ -17,6 +17,24 @@ class GLCanvas3D; static constexpr float HoleStickOutLength = 1.f; +enum class SLAGizmoEventType : unsigned char { + LeftDown = 1, + LeftUp, + RightDown, + Dragging, + Delete, + SelectAll, + ShiftUp, + AltUp, + ApplyChanges, + DiscardChanges, + AutomaticGeneration, + ManualEditing, + MouseWheelUp, + MouseWheelDown, + ResetClippingPlane +}; + class CommonGizmosDataBase; diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 61d0bd5f4f..f9d832bb18 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -9,10 +9,14 @@ #include "slic3r/GUI/GUI_ObjectManipulation.hpp" #include "slic3r/GUI/PresetBundle.hpp" #include "slic3r/Utils/UndoRedo.hpp" -//#include "libslic3r/SLAPrint.hpp" -//#include "slic3r/GUI/MeshUtils.hpp" -#include "slic3r/GUI/Gizmos/GLGizmos.hpp" -//#include "slic3r/GUI/Camera.hpp" + +#include "slic3r/GUI/Gizmos/GLGizmoMove.hpp" +#include "slic3r/GUI/Gizmos/GLGizmoScale.hpp" +#include "slic3r/GUI/Gizmos/GLGizmoRotate.hpp" +#include "slic3r/GUI/Gizmos/GLGizmoFlatten.hpp" +#include "slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp" +#include "slic3r/GUI/Gizmos/GLGizmoCut.hpp" +#include "slic3r/GUI/Gizmos/GLGizmoHollow.hpp" #include @@ -402,15 +406,6 @@ ClippingPlane GLGizmosManager::get_sla_clipping_plane() const const ClippingPlane& clp = *m_common_gizmos_data->object_clipper()->get_clipping_plane(); return ClippingPlane(-clp.get_normal(), clp.get_data()[3]); } - - - /*if (!m_enabled || (m_current != SlaSupports && m_current != Hollow) || m_gizmos.empty()) - return ClippingPlane::ClipsNothing(); - - if (m_current == SlaSupports) - return dynamic_cast(m_gizmos[SlaSupports].get())->get_sla_clipping_plane(); - else - return dynamic_cast(m_gizmos[Hollow].get())->get_sla_clipping_plane();*/ } bool GLGizmosManager::wants_reslice_supports_on_undo() const @@ -1227,136 +1222,5 @@ bool GLGizmosManager::grabber_contains_mouse() const return (curr != nullptr) ? (curr->get_hover_id() != -1) : false; } - -/* -CommonGizmosData::CommonGizmosData() -{ - m_clipping_plane.reset(new ClippingPlane(Vec3d::Zero(), 0.)); -} - - - -bool CommonGizmosData::update_from_backend(GLCanvas3D& canvas, ModelObject* model_object) -{ - recent_update = false; - bool object_changed = false; - - if (m_model_object != model_object - || (model_object && m_model_object_id != model_object->id())) { - m_model_object = model_object; - m_print_object_idx = -1; - m_mesh_raycaster.reset(); - m_object_clipper.reset(); - m_supports_clipper.reset(); - m_old_mesh = nullptr; - m_mesh = nullptr; - m_backend_mesh_transformed.clear(); - - object_changed = true; - recent_update = true; - } - - if (m_model_object) { - int active_inst = canvas.get_selection().get_instance_idx(); - if (m_active_instance != active_inst) { - m_active_instance = active_inst; - m_active_instance_bb_radius = m_model_object->instance_bounding_box(m_active_instance).radius(); - recent_update = true; - } - } - - - if (! m_model_object || ! canvas.get_selection().is_from_single_instance()) - return false; - - int old_po_idx = m_print_object_idx; - - // First we need a pointer to the respective SLAPrintObject. The index into objects vector is - // cached so we don't have todo it on each render. We only search for the po if needed: - if (m_print_object_idx < 0 || (int)canvas.sla_print()->objects().size() != m_print_objects_count) { - m_print_objects_count = canvas.sla_print()->objects().size(); - m_print_object_idx = -1; - for (const SLAPrintObject* po : canvas.sla_print()->objects()) { - ++m_print_object_idx; - if (po->model_object()->id() == m_model_object->id()) - break; - } - } - - bool mesh_exchanged = false; - m_mesh = nullptr; - // Load either the model_object mesh, or one provided by the backend - // This mesh does not account for the possible Z up SLA offset. - // The backend mesh needs to be transformed and because a pointer to it is - // saved, a copy is stored as a member (FIXME) - if (m_print_object_idx >=0) { - const SLAPrintObject* po = canvas.sla_print()->objects()[m_print_object_idx]; - if (po->is_step_done(slaposDrillHoles)) { - m_backend_mesh_transformed = po->get_mesh_to_print(); - m_backend_mesh_transformed.transform(canvas.sla_print()->sla_trafo(*m_model_object).inverse()); - m_mesh = &m_backend_mesh_transformed; - m_has_drilled_mesh = true; - mesh_exchanged = true; - } - } - - if (! m_mesh) { - m_mesh = &m_model_object->volumes.front()->mesh(); - m_backend_mesh_transformed.clear(); - m_has_drilled_mesh = false; - } - - m_model_object_id = m_model_object->id(); - - if (m_mesh != m_old_mesh) { - // Update clipping plane position. - float new_clp_pos = m_clipping_plane_distance; - if (object_changed) { - new_clp_pos = 0.f; - m_clipping_plane_was_moved = false; - } else { - // After we got a drilled mesh, move the cp to 25%. This only applies when - // the hollowing gizmo is active and hollowing is enabled - if (m_clipping_plane_distance == 0.f && mesh_exchanged && m_has_drilled_mesh) { - const DynamicPrintConfig& cfg = - (m_model_object && m_model_object->config.has("hollowing_enable")) - ? m_model_object->config - : wxGetApp().preset_bundle->sla_prints.get_edited_preset().config; - - if (cfg.has("hollowing_enable") && cfg.opt_bool("hollowing_enable") - && canvas.get_gizmos_manager().get_current_type() == GLGizmosManager::Hollow) { - new_clp_pos = 0.25f; - m_clipping_plane_was_moved = false; // so it uses current camera direction - } - } - } - m_clipping_plane_distance = new_clp_pos; - m_clipping_plane_distance_stash = new_clp_pos; - - m_schedule_aabb_calculation = true; - recent_update = true; - return true; - } - if (! recent_update) - recent_update = m_print_object_idx < 0 && old_po_idx >= 0; - - return recent_update; -} - - -void CommonGizmosData::build_AABB_if_needed() -{ - if (! m_schedule_aabb_calculation) - return; - - wxBusyCursor wait; - m_mesh_raycaster.reset(new MeshRaycaster(*m_mesh)); - m_object_clipper.reset(); - m_supports_clipper.reset(); - m_old_mesh = m_mesh; - m_schedule_aabb_calculation = false; -}*/ - - } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp index 81fd991b7b..a31a96a264 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp @@ -3,7 +3,6 @@ #include "slic3r/GUI/GLTexture.hpp" #include "slic3r/GUI/GLToolbar.hpp" -//#include "libslic3r/ObjectID.hpp" #include "slic3r/GUI/Gizmos/GLGizmoBase.hpp" #include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" @@ -20,7 +19,6 @@ namespace GUI { class GLCanvas3D; class ClippingPlane; enum class SLAGizmoEventType : unsigned char; -//class CommonGizmosData; class CommonGizmosDataPool; class Rect @@ -234,63 +232,6 @@ private: -//class MeshRaycaster; -//class MeshClipper; - -// This class is only for sharing SLA related data between SLA gizmos -// and its synchronization with backend data. It should not be misused -// for anything else. -/*class CommonGizmosData { -public: - CommonGizmosData(); - const TriangleMesh* mesh() const { - return (! m_mesh ? nullptr : m_mesh); //(m_cavity_mesh ? m_cavity_mesh.get() : m_mesh)); - } - - bool update_from_backend(GLCanvas3D& canvas, ModelObject* model_object); - bool recent_update = false; - static constexpr float HoleStickOutLength = 1.f; - - ModelObject* m_model_object = nullptr; - const TriangleMesh* m_mesh; - std::unique_ptr m_mesh_raycaster; - std::unique_ptr m_object_clipper; - std::unique_ptr m_supports_clipper; - - //std::unique_ptr m_cavity_mesh; - //std::unique_ptr m_volume_with_cavity; - - int m_active_instance = -1; - float m_active_instance_bb_radius = 0; - ObjectID m_model_object_id = 0; - int m_print_object_idx = -1; - int m_print_objects_count = -1; - int m_old_timestamp = -1; - - float m_clipping_plane_distance = 0.f; - std::unique_ptr m_clipping_plane; - bool m_clipping_plane_was_moved = false; - - void stash_clipping_plane() { - m_clipping_plane_distance_stash = m_clipping_plane_distance; - } - - void unstash_clipping_plane() { - m_clipping_plane_distance = m_clipping_plane_distance_stash; - } - - bool has_drilled_mesh() const { return m_has_drilled_mesh; } - - void build_AABB_if_needed(); - -private: - const TriangleMesh* m_old_mesh; - TriangleMesh m_backend_mesh_transformed; - float m_clipping_plane_distance_stash = 0.f; - bool m_has_drilled_mesh = false; - bool m_schedule_aabb_calculation = false; -}; -*/ } // namespace GUI } // namespace Slic3r