From af03bed09484369ff9d725f72ed22fb0f01af21b Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 17 Feb 2022 14:32:08 +0100 Subject: [PATCH] Cut: Implemented update_clipper() --- src/slic3r/GUI/Gizmos/GLGizmoCut.cpp | 44 +++++++++++++++++------ src/slic3r/GUI/Gizmos/GLGizmoCut.hpp | 8 ++--- src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp | 6 ++++ src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 2 +- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp index 58484c8a53..208549bc45 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp @@ -126,6 +126,35 @@ void GLGizmoCut3D::shift_cut_z(double delta) set_center(new_cut_center); } +void GLGizmoCut3D::update_clipper() +{ + const Vec3d& angles = m_rotation_gizmo.get_rotation(); + Matrix3d m; + m = Eigen::AngleAxisd(angles[X], Vec3d::UnitX()) + * Eigen::AngleAxisd(angles[Y], Vec3d::UnitY()) + * Eigen::AngleAxisd(angles[Z], Vec3d::UnitZ()); + + Vec3d plane_center = m_move_gizmo.get_center(); + BoundingBoxf3 box = m_move_gizmo.bounding_box(); + + Vec3d min, max = min = plane_center = m_move_gizmo.get_center(); + min[Z] = box.min.z(); + max[Z] = box.max.z(); + + min -= plane_center; + max -= plane_center; + + Vec3d beg = m * min; + Vec3d end = m * max; + + beg += plane_center; + end += plane_center; + + double dist = (plane_center - beg).norm(); + + m_c->object_clipper()->set_range_and_pos(beg, end, dist); +} + void GLGizmoCut3D::set_center(const Vec3d& center) { m_move_gizmo.set_center_pos(center); @@ -216,7 +245,7 @@ void GLGizmoCut3D::render_rotation_input(int axis) ImGui::SameLine(); Vec3d rotation = m_rotation_gizmo.get_rotation(); - double value = rotation[axis] * (180. / M_PI); + double value = Geometry::rad2deg(rotation[axis]); if (value > 360) value -= 360; @@ -224,7 +253,7 @@ void GLGizmoCut3D::render_rotation_input(int axis) ImGui::InputDouble(("##rotate_" + m_axis_names[axis]).c_str(), &value, 0.0f, 0.0f, "%.2f", ImGuiInputTextFlags_CharsDecimal); ImGui::SameLine(); - rotation[axis] = (M_PI / 180.) * value; + rotation[axis] = Geometry::deg2rad(value); m_rotation_gizmo.set_rotation(rotation); } @@ -248,7 +277,7 @@ void GLGizmoCut3D::render_cut_plane() { const BoundingBoxf3 box = m_move_gizmo.bounding_box(); Vec3d plane_center = m_move_gizmo.get_center();// == Vec3d::Zero() ? box.center() : m_move_gizmo.get_center(); - // update_contours(); + m_c->object_clipper()->render_cut(); const float min_x = box.min.x() - GLGizmoCenterMove::Margin - plane_center.x(); @@ -383,6 +412,7 @@ void GLGizmoCut3D::on_update(const UpdateData& data) void GLGizmoCut3D::on_render() { + update_clipper(); render_cut_plane(); if (m_mode == CutMode::cutPlanar) { int move_group_id = m_move_gizmo.get_group_id(); @@ -435,7 +465,7 @@ void GLGizmoCut3D::on_render_input_window(float x, float y, float bottom_limit) ImGui::SameLine(m_label_width); for (Axis axis : {X, Y, Z}) render_rotation_input(axis); - m_imgui->text(_L("°")); + m_imgui->text(_L("°")); } else { ImGui::AlignTextToFramePadding(); @@ -510,12 +540,6 @@ void GLGizmoCut3D::on_render_input_window(float x, float y, float bottom_limit) bool GLGizmoCut3D::can_perform_cut() const { return true; - - const BoundingBoxf3 box = bounding_box(); - Vec3d plane_center = box.center(); - plane_center.z() = 0; - m_c->object_clipper()->set_range_and_pos(plane_center, - plane_center + m_max_z * Vec3d::UnitZ(), m_cut_z); } void GLGizmoCut3D::perform_cut(const Selection& selection) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp index b450b6ec7b..80b128cbed 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp @@ -113,16 +113,14 @@ public: bool gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_position, bool shift_down, bool alt_down, bool control_down); void shift_cut_z(double delta); + void update_clipper(); protected: bool on_init() override; - void on_load(cereal::BinaryInputArchive& ar) override { ar(m_cut_z, m_keep_upper, m_keep_lower, m_rotate_lower); } - void on_save(cereal::BinaryOutputArchive& ar) const override { ar(m_cut_z, m_keep_upper, m_keep_lower, m_rotate_lower); } + void on_load(cereal::BinaryInputArchive& ar) override { ar(/*m_cut_z, */m_keep_upper, m_keep_lower, m_rotate_lower); } + void on_save(cereal::BinaryOutputArchive& ar) const override { ar(/*m_cut_z, */m_keep_upper, m_keep_lower, m_rotate_lower); } std::string on_get_name() const override; void on_set_state() override; - bool on_is_activable() const override; - void on_start_dragging() override; - void on_update(const UpdateData& data) override; CommonGizmosDataID on_get_requirements() const override; void on_set_hover_id() override; void on_enable_grabber(unsigned int id) override; diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp index 48a54fbaee..c4828da8b2 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp @@ -458,9 +458,15 @@ void ObjectClipper::set_position_by_ratio(double pos, bool keep_normal) void ObjectClipper::set_range_and_pos(const Vec3d& origin, const Vec3d& end, double pos) { + std::cout << "origin:\t"<< origin.x() << "\t" << origin.y() << "\t"<< origin.z() << "\n"; + std::cout << "end:\t" << end.x() << "\t" << end.y() << "\t"<< end.z() << "\n"; + Vec3d normal = end-origin; double norm = normal.norm(); pos = std::clamp(pos, 0.0001, norm); + + std::cout << "NORM:\t" << norm << "\tPOS:\t" << pos << "\n\n"; + m_clp.reset(new ClippingPlane(normal, pos)); m_clp_ratio = pos/norm; get_pool()->get_canvas()->set_as_dirty(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index b2d543c5d7..c87a2ba45e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -446,7 +446,7 @@ bool GLGizmosManager::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_p else if (m_current == MmuSegmentation) return dynamic_cast(m_gizmos[MmuSegmentation].get())->gizmo_event(action, mouse_position, shift_down, alt_down, control_down); else if (m_current == Cut) - return dynamic_cast(m_gizmos[Cut].get())->gizmo_event(action, mouse_position, shift_down, alt_down, control_down); + return dynamic_cast(m_gizmos[Cut].get())->gizmo_event(action, mouse_position, shift_down, alt_down, control_down); else return false; }