From 265ba879e3550a67cc98df8695ce6e64e0bf1128 Mon Sep 17 00:00:00 2001 From: SoftFever <103989404+SoftFever@users.noreply.github.com> Date: Mon, 16 Oct 2023 22:00:31 +0800 Subject: [PATCH] new grabber --- src/libslic3r/Model.hpp | 1 + src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp | 85 ++----- src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.hpp | 1 - src/slic3r/GUI/Gizmos/GLGizmoBase.cpp | 205 ++++++++--------- src/slic3r/GUI/Gizmos/GLGizmoBase.hpp | 55 +++-- src/slic3r/GUI/Gizmos/GLGizmoCut.cpp | 6 - src/slic3r/GUI/Gizmos/GLGizmoCut.hpp | 1 - src/slic3r/GUI/Gizmos/GLGizmoFaceDetector.hpp | 1 - src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp | 187 +++++++++------- src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp | 46 ++-- src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp | 22 +- src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp | 1 - src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp | 1 - src/slic3r/GUI/Gizmos/GLGizmoMeshBoolean.hpp | 1 - src/slic3r/GUI/Gizmos/GLGizmoMove.cpp | 211 +++++++++--------- src/slic3r/GUI/Gizmos/GLGizmoMove.hpp | 11 +- src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp | 1 - src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp | 106 ++++----- src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp | 10 +- src/slic3r/GUI/Gizmos/GLGizmoScale.cpp | 6 - src/slic3r/GUI/Gizmos/GLGizmoScale.hpp | 1 - src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp | 1 - src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 14 +- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp | 1 - src/slic3r/GUI/Gizmos/GLGizmoText.cpp | 75 ++----- src/slic3r/GUI/Gizmos/GLGizmoText.hpp | 1 - src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 19 +- src/slic3r/GUI/Gizmos/GLGizmosManager.hpp | 2 +- 28 files changed, 501 insertions(+), 571 deletions(-) diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 481552c058c..ac1a7558ad9 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -1325,6 +1325,7 @@ class ModelInstance final : public ObjectBase void transform_polygon(Polygon* polygon) const; const Transform3d& get_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const { return m_transformation.get_matrix(dont_translate, dont_rotate, dont_scale, dont_mirror); } + Transform3d get_matrix_no_offset() const { return m_transformation.get_matrix_no_offset(); } bool is_printable() const { return object->printable && printable && (print_volume_state == ModelInstancePVS_Inside); } bool is_assemble_initialized() { return m_assemble_initialized; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp index 054b24c5e06..604ce3b32c0 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.cpp @@ -512,62 +512,6 @@ void GLGizmoAdvancedCut::on_render() render_cut_line(); } -void GLGizmoAdvancedCut::on_render_for_picking() -{ - GLGizmoRotate3D::on_render_for_picking(); - - glsafe(::glDisable(GL_DEPTH_TEST)); - - BoundingBoxf3 box = m_parent.get_selection().get_bounding_box(); -#if ENABLE_FIXED_GRABBER - float mean_size = (float)(GLGizmoBase::Grabber::FixedGrabberSize); -#else - float mean_size = (float)((box.size().x() + box.size().y() + box.size().z()) / 3.0); -#endif - - std::array color = picking_color_component(0); - m_move_grabber.color[0] = color[0]; - m_move_grabber.color[1] = color[1]; - m_move_grabber.color[2] = color[2]; - m_move_grabber.color[3] = color[3]; - m_move_grabber.render_for_picking(mean_size); - - glsafe(::glEnable(GL_DEPTH_TEST)); - auto inst_id = m_c->selection_info()->get_active_instance(); - if (inst_id < 0) - return; - - const ModelObject *mo = m_c->selection_info()->model_object(); - const ModelInstance *mi = mo->instances[inst_id]; - const Vec3d & instance_offset = mi->get_offset(); - const double sla_shift = double(m_c->selection_info()->get_sla_shift()); - - const CutConnectors &connectors = mo->cut_connectors; - for (int i = 0; i < connectors.size(); ++i) { - CutConnector connector = connectors[i]; - Vec3d pos = connector.pos + instance_offset + sla_shift * Vec3d::UnitZ(); - float height = connector.height; - - const Camera &camera = wxGetApp().plater()->get_camera(); - if (connector.attribs.type == CutConnectorType::Dowel && connector.attribs.style == CutConnectorStyle::Prizm) { - pos -= height * m_cut_plane_normal; - height *= 2; - } else if (!is_looking_forward()) - pos -= 0.05 * m_cut_plane_normal; - - Transform3d translate_tf = Transform3d::Identity(); - translate_tf.translate(pos); - - Transform3d scale_tf = Transform3d::Identity(); - scale_tf.scale(Vec3f(connector.radius, connector.radius, height).cast()); - - const Transform3d view_model_matrix = translate_tf * m_rotate_matrix * scale_tf; - - - std::array color = picking_color_component(i+1); - render_connector_model(m_shapes[connectors[i].attribs], color, view_model_matrix, true); - } -} void GLGizmoAdvancedCut::on_render_input_window(float x, float y, float bottom_limit) { @@ -926,23 +870,24 @@ void GLGizmoAdvancedCut::render_cut_plane_and_grabbers() else render_color = GrabberColor; - GLModel &cube = m_move_grabber.get_cube(); - // BBS set to fixed size grabber - // float fullsize = 2 * (dragging ? get_dragging_half_size(size) : get_half_size(size)); - float fullsize = 8.0f; - if (GLGizmoBase::INV_ZOOM > 0) { - fullsize = m_move_grabber.FixedGrabberSize * GLGizmoBase::INV_ZOOM; - } + // Orca todo + // GLModel &cube = m_move_grabber.get_cube(); + // // BBS set to fixed size grabber + // // float fullsize = 2 * (dragging ? get_dragging_half_size(size) : get_half_size(size)); + // float fullsize = 8.0f; + // if (GLGizmoBase::INV_ZOOM > 0) { + // fullsize = m_move_grabber.FixedGrabberSize * GLGizmoBase::INV_ZOOM; + // } - cube.set_color(render_color); + // cube.set_color(render_color); - glsafe(::glPushMatrix()); - glsafe(::glTranslated(m_move_grabber.center.x(), m_move_grabber.center.y(), m_move_grabber.center.z())); - glsafe(::glMultMatrixd(m_rotate_matrix.data())); + // glsafe(::glPushMatrix()); + // glsafe(::glTranslated(m_move_grabber.center.x(), m_move_grabber.center.y(), m_move_grabber.center.z())); + // glsafe(::glMultMatrixd(m_rotate_matrix.data())); - glsafe(::glScaled(fullsize, fullsize, fullsize)); - cube.render(); - glsafe(::glPopMatrix()); + // glsafe(::glScaled(fullsize, fullsize, fullsize)); + // cube.render(); + // glsafe(::glPopMatrix()); // Should be placed at last, because GLGizmoRotate3D clears depth buffer set_center(m_cut_plane_center); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.hpp b/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.hpp index 5cb9e765cc0..e1aafbbf26e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoAdvancedCut.hpp @@ -147,7 +147,6 @@ struct Rotate_data { virtual void on_stop_dragging() override; virtual void on_update(const UpdateData& data); virtual void on_render(); - virtual void on_render_for_picking(); virtual void on_render_input_window(float x, float y, float bottom_limit); void show_tooltip_information(float x, float y); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp index 8d46a0ae07b..fed1f275dcf 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp @@ -14,14 +14,6 @@ namespace GUI { float GLGizmoBase::INV_ZOOM = 1.0f; - -const float GLGizmoBase::Grabber::SizeFactor = 0.05f; -const float GLGizmoBase::Grabber::MinHalfSize = 4.0f; -const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f; -const float GLGizmoBase::Grabber::FixedGrabberSize = 16.0f; -const float GLGizmoBase::Grabber::FixedRadiusSize = 80.0f; - - std::array GLGizmoBase::DEFAULT_BASE_COLOR = { 0.625f, 0.625f, 0.625f, 1.0f }; std::array GLGizmoBase::DEFAULT_DRAG_COLOR = { 1.0f, 1.0f, 1.0f, 1.0f }; std::array GLGizmoBase::DEFAULT_HIGHLIGHT_COLOR = { 1.0f, 0.38f, 0.0f, 1.0f }; @@ -68,27 +60,20 @@ void GLGizmoBase::load_render_colors() RenderColor::colors[RenderCol_Flatten_Plane] = IMColor(GLGizmoBase::FLATTEN_COLOR); RenderColor::colors[RenderCol_Flatten_Plane_Hover] = IMColor(GLGizmoBase::FLATTEN_HOVER_COLOR); } +const float GLGizmoBase::Grabber::SizeFactor = 0.05f; +const float GLGizmoBase::Grabber::MinHalfSize = 1.5f; +const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f; -GLGizmoBase::Grabber::Grabber() - : center(Vec3d::Zero()) - , angles(Vec3d::Zero()) - , dragging(false) - , enabled(true) -{ - color = GRABBER_NORMAL_COL; - hover_color = GRABBER_HOVER_COL; -} +PickingModel GLGizmoBase::Grabber::s_cube; +PickingModel GLGizmoBase::Grabber::s_cone; -void GLGizmoBase::Grabber::render(bool hover, float size) +GLGizmoBase::Grabber::~Grabber() { - std::array render_color; - if (hover) { - render_color = hover_color; - } - else - render_color = color; + if (s_cube.model.is_initialized()) + s_cube.model.reset(); - render(size, render_color, false); + if (s_cone.model.is_initialized()) + s_cone.model.reset(); } float GLGizmoBase::Grabber::get_half_size(float size) const @@ -100,6 +85,7 @@ float GLGizmoBase::Grabber::get_dragging_half_size(float size) const { return get_half_size(size) * DraggingScaleFactor; } + void GLGizmoBase::Grabber::register_raycasters_for_picking(int id) { picking_id = id; @@ -113,51 +99,102 @@ void GLGizmoBase::Grabber::unregister_raycasters_for_picking() raycasters = { nullptr }; } -GLModel& GLGizmoBase::Grabber::get_cube() +void GLGizmoBase::Grabber::render(float size, const ColorRGBA& render_color) { - if (! cube_initialized) { - // This cannot be done in constructor, OpenGL is not yet - // initialized at that point (on Linux at least). - indexed_triangle_set mesh = its_make_cube(1., 1., 1.); - its_translate(mesh, Vec3f(-0.5, -0.5, -0.5)); - cube.init_from(mesh); - cube_initialized = true; - } - return cube; -} + GLShaderProgram* shader = wxGetApp().get_current_shader(); + if (shader == nullptr) + return; -void GLGizmoBase::Grabber::render(float size, const std::array& render_color, bool picking) -{ - if (! cube_initialized) { + if (!s_cube.model.is_initialized()) { // This cannot be done in constructor, OpenGL is not yet // initialized at that point (on Linux at least). - indexed_triangle_set mesh = its_make_cube(1., 1., 1.); - its_translate(mesh, Vec3f(-0.5, -0.5, -0.5)); - cube.init_from(mesh); - cube_initialized = true; + indexed_triangle_set its = its_make_cube(1.0, 1.0, 1.0); + its_translate(its, -0.5f * Vec3f::Ones()); + s_cube.model.init_from(its); + s_cube.mesh_raycaster = std::make_unique(std::make_shared(std::move(its))); } - //BBS set to fixed size grabber - //float fullsize = 2 * (dragging ? get_dragging_half_size(size) : get_half_size(size)); - float fullsize = 8.0f; - if (GLGizmoBase::INV_ZOOM > 0) { - fullsize = FixedGrabberSize * GLGizmoBase::INV_ZOOM; + if (!s_cone.model.is_initialized()) { + indexed_triangle_set its = its_make_cone(0.375, 1.5, double(PI) / 18.0); + s_cone.model.init_from(its); + s_cone.mesh_raycaster = std::make_unique(std::make_shared(std::move(its))); } + const float half_size = dragging ? get_dragging_half_size(size) : get_half_size(size); + + s_cube.model.set_color(render_color); + s_cone.model.set_color(render_color); + + const Camera& camera = wxGetApp().plater()->get_camera(); + shader->set_uniform("projection_matrix", camera.get_projection_matrix()); + const Transform3d& view_matrix = camera.get_view_matrix(); + const Matrix3d view_matrix_no_offset = view_matrix.matrix().block(0, 0, 3, 3); + std::vector elements_matrices(GRABBER_ELEMENTS_MAX_COUNT, Transform3d::Identity()); + elements_matrices[0] = matrix * Geometry::translation_transform(center) * Geometry::rotation_transform(angles) * Geometry::scale_transform(2.0 * half_size); + Transform3d view_model_matrix = view_matrix * elements_matrices[0]; + + shader->set_uniform("view_model_matrix", view_model_matrix); + Matrix3d view_normal_matrix = view_matrix_no_offset * elements_matrices[0].matrix().block(0, 0, 3, 3).inverse().transpose(); + shader->set_uniform("view_normal_matrix", view_normal_matrix); + s_cube.model.render(); + + auto render_extension = [&view_matrix, &view_matrix_no_offset, shader](const Transform3d& matrix) { + const Transform3d view_model_matrix = view_matrix * matrix; + shader->set_uniform("view_model_matrix", view_model_matrix); + const Matrix3d view_normal_matrix = view_matrix_no_offset * matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); + shader->set_uniform("view_normal_matrix", view_normal_matrix); + s_cone.model.render(); + }; + + if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosX)) != 0) { + elements_matrices[1] = elements_matrices[0] * Geometry::translation_transform(Vec3d::UnitX()) * Geometry::rotation_transform({ 0.0, 0.5 * double(PI), 0.0 }); + render_extension(elements_matrices[1]); + } + if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegX)) != 0) { + elements_matrices[2] = elements_matrices[0] * Geometry::translation_transform(-Vec3d::UnitX()) * Geometry::rotation_transform({ 0.0, -0.5 * double(PI), 0.0 }); + render_extension(elements_matrices[2]); + } + if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosY)) != 0) { + elements_matrices[3] = elements_matrices[0] * Geometry::translation_transform(Vec3d::UnitY()) * Geometry::rotation_transform({ -0.5 * double(PI), 0.0, 0.0 }); + render_extension(elements_matrices[3]); + } + if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegY)) != 0) { + elements_matrices[4] = elements_matrices[0] * Geometry::translation_transform(-Vec3d::UnitY()) * Geometry::rotation_transform({ 0.5 * double(PI), 0.0, 0.0 }); + render_extension(elements_matrices[4]); + } + if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosZ)) != 0) { + elements_matrices[5] = elements_matrices[0] * Geometry::translation_transform(Vec3d::UnitZ()); + render_extension(elements_matrices[5]); + } + if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegZ)) != 0) { + elements_matrices[6] = elements_matrices[0] * Geometry::translation_transform(-Vec3d::UnitZ()) * Geometry::rotation_transform({ double(PI), 0.0, 0.0 }); + render_extension(elements_matrices[6]); + } - cube.set_color(render_color); - - glsafe(::glPushMatrix()); - glsafe(::glTranslated(center.x(), center.y(), center.z())); - glsafe(::glRotated(Geometry::rad2deg(angles.z()), 0.0, 0.0, 1.0)); - glsafe(::glRotated(Geometry::rad2deg(angles.y()), 0.0, 1.0, 0.0)); - glsafe(::glRotated(Geometry::rad2deg(angles.x()), 1.0, 0.0, 0.0)); - glsafe(::glScaled(fullsize, fullsize, fullsize)); - cube.render(); - glsafe(::glPopMatrix()); + if (raycasters[0] == nullptr) { + GLCanvas3D& canvas = *wxGetApp().plater()->canvas3D(); + raycasters[0] = canvas.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, picking_id, *s_cube.mesh_raycaster, elements_matrices[0]); + if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosX)) != 0) + raycasters[1] = canvas.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, picking_id, *s_cone.mesh_raycaster, elements_matrices[1]); + if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegX)) != 0) + raycasters[2] = canvas.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, picking_id, *s_cone.mesh_raycaster, elements_matrices[2]); + if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosY)) != 0) + raycasters[3] = canvas.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, picking_id, *s_cone.mesh_raycaster, elements_matrices[3]); + if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegY)) != 0) + raycasters[4] = canvas.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, picking_id, *s_cone.mesh_raycaster, elements_matrices[4]); + if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::PosZ)) != 0) + raycasters[5] = canvas.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, picking_id, *s_cone.mesh_raycaster, elements_matrices[5]); + if ((int(extensions) & int(GLGizmoBase::EGrabberExtension::NegZ)) != 0) + raycasters[6] = canvas.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, picking_id, *s_cone.mesh_raycaster, elements_matrices[6]); + } + else { + for (size_t i = 0; i < GRABBER_ELEMENTS_MAX_COUNT; ++i) { + if (raycasters[i] != nullptr) + raycasters[i]->set_transform(elements_matrices[i]); + } + } } - GLGizmoBase::GLGizmoBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) : m_parent(parent) , m_group_id(-1) @@ -290,65 +327,33 @@ void GLGizmoBase::GizmoImguiSetNextWIndowPos(float &x, float y, int flag, float m_imgui->set_next_window_pos(x, y, flag, pivot_x, pivot_y); } -std::array GLGizmoBase::picking_color_component(unsigned int id) const -{ - static const float INV_255 = 1.0f / 255.0f; - - id = BASE_ID - id; - - if (m_group_id > -1) - id -= m_group_id; - - // color components are encoded to match the calculation of volume_id made into GLCanvas3D::_picking_pass() - return std::array { - float((id >> 0) & 0xff) * INV_255, // red - float((id >> 8) & 0xff) * INV_255, // green - float((id >> 16) & 0xff) * INV_255, // blue - float(picking_checksum_alpha_channel(id & 0xff, (id >> 8) & 0xff, (id >> 16) & 0xff))* INV_255 // checksum for validating against unwanted alpha blending and multi sampling - }; -} - void GLGizmoBase::render_grabbers(const BoundingBoxf3& box) const { -#if ENABLE_FIXED_GRABBER - render_grabbers((float)(GLGizmoBase::Grabber::FixedGrabberSize)); -#else render_grabbers((float)((box.size().x() + box.size().y() + box.size().z()) / 3.0)); -#endif } void GLGizmoBase::render_grabbers(float size) const +{ + render_grabbers(0, m_grabbers.size() - 1, size, false); +} + +void GLGizmoBase::render_grabbers(size_t first, size_t last, float size, bool force_hover) const { GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); if (shader == nullptr) return; shader->start_using(); shader->set_uniform("emission_factor", 0.1f); - for (int i = 0; i < (int)m_grabbers.size(); ++i) { + glsafe(::glDisable(GL_CULL_FACE)); + for (size_t i = first; i <= last; ++i) { if (m_grabbers[i].enabled) - m_grabbers[i].render(m_hover_id == i, size); + m_grabbers[i].render(force_hover ? true : m_hover_id == (int)i, size); } + glsafe(::glEnable(GL_CULL_FACE)); shader->stop_using(); } -void GLGizmoBase::render_grabbers_for_picking(const BoundingBoxf3& box) const -{ -#if ENABLE_FIXED_GRABBER - float mean_size = (float)(GLGizmoBase::Grabber::FixedGrabberSize); -#else - float mean_size = (float)((box.size().x() + box.size().y() + box.size().z()) / 3.0); -#endif - - for (unsigned int i = 0; i < (unsigned int)m_grabbers.size(); ++i) { - if (m_grabbers[i].enabled) { - std::array color = picking_color_component(i); - m_grabbers[i].color = color; - m_grabbers[i].render_for_picking(mean_size); - } - } -} - std::string GLGizmoBase::format(float value, unsigned int decimals) const { return Slic3r::string_printf("%.*f", decimals, value); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp index 491468ef45b..48f2d688de1 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp @@ -37,6 +37,19 @@ class GLGizmoBase static const unsigned int BASE_ID = 255 * 255 * 254; static const unsigned int GRABBER_ELEMENTS_MAX_COUNT = 7; + enum class EGrabberExtension { + None = 0, + PosX = 1 << 0, + NegX = 1 << 1, + PosY = 1 << 2, + NegY = 1 << 3, + PosZ = 1 << 4, + NegZ = 1 << 5, + }; + + // Represents NO key(button on keyboard) value + static const int NO_SHORTCUT_KEY_VALUE = 0; + static float INV_ZOOM; //BBS colors @@ -62,35 +75,35 @@ class GLGizmoBase static const float SizeFactor; static const float MinHalfSize; static const float DraggingScaleFactor; - static const float FixedGrabberSize; - static const float FixedRadiusSize; - Vec3d center; - Vec3d angles; - std::array color; - std::array hover_color; - bool enabled; - bool dragging; - int picking_id{ -1 }; - std::array, GRABBER_ELEMENTS_MAX_COUNT> raycasters = { nullptr }; + bool enabled{true}; + bool dragging{false}; + Vec3d center{Vec3d::Zero()}; + Vec3d angles{Vec3d::Zero()}; + Transform3d matrix{Transform3d::Identity()}; + ColorRGBA color{ColorRGBA::WHITE()}; + ColorRGBA hover_color{ColorRGBA::ORCA()}; + EGrabberExtension extensions{EGrabberExtension::None}; + // the picking id shared by all the elements + int picking_id{-1}; + std::array, GRABBER_ELEMENTS_MAX_COUNT> raycasters = {nullptr}; - Grabber(); + Grabber() = default; + ~Grabber(); - void render(bool hover, float size); - void render_for_picking(float size) { render(size, color, true); } + void render(bool hover, float size) { render(size, hover ? complementary(color) : color); } float get_half_size(float size) const; float get_dragging_half_size(float size) const; - GLModel& get_cube(); void register_raycasters_for_picking(int id); void unregister_raycasters_for_picking(); private: - void render(float size, const std::array& render_color, bool picking); + void render(float size, const ColorRGBA &render_color); - GLModel cube; - bool cube_initialized = false; + static PickingModel s_cube; + static PickingModel s_cone; }; public: @@ -192,7 +205,6 @@ class GLGizmoBase bool update_items_state(); void render() { m_tooltip.clear(); on_render(); } - void render_for_picking() { on_render_for_picking(); } void render_input_window(float x, float y, float bottom_limit); virtual void on_change_color_mode(bool is_dark) { m_is_dark_mode = is_dark; } @@ -237,7 +249,6 @@ class GLGizmoBase virtual void on_stop_dragging() {} virtual void on_update(const UpdateData& data) {} virtual void on_render() = 0; - virtual void on_render_for_picking() = 0; virtual void on_render_input_window(float x, float y, float bottom_limit) {} void register_grabbers_for_picking(); void unregister_grabbers_for_picking(); @@ -249,10 +260,10 @@ class GLGizmoBase void GizmoImguiSetNextWIndowPos(float &x, float y, int flag, float pivot_x = 0.0f, float pivot_y = 0.0f); // Returns the picking color for the given id, based on the BASE_ID constant // No check is made for clashing with other picking color (i.e. GLVolumes) - std::array picking_color_component(unsigned int id) const; - void render_grabbers(const BoundingBoxf3& box) const; + + void render_grabbers(const BoundingBoxf3 &box) const; void render_grabbers(float size) const; - void render_grabbers_for_picking(const BoundingBoxf3& box) const; + void render_grabbers(size_t first, size_t last, float size, bool force_hover) const; std::string format(float value, unsigned int decimals) const; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp index a05fb9fa67e..9b44acab281 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.cpp @@ -146,12 +146,6 @@ void GLGizmoCut::on_render() glsafe(::glPopMatrix()); } -void GLGizmoCut::on_render_for_picking() -{ - glsafe(::glDisable(GL_DEPTH_TEST)); - render_grabbers_for_picking(m_parent.get_selection().get_bounding_box()); -} - void GLGizmoCut::on_render_input_window(float x, float y, float bottom_limit) { //static float last_y = 0.0f; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp b/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp index 0d745fe3cb2..87ae89a052b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoCut.hpp @@ -60,7 +60,6 @@ class GLGizmoCut : public GLGizmoBase virtual void on_start_dragging() override; virtual void on_update(const UpdateData& data) override; virtual void on_render() override; - virtual void on_render_for_picking() override; virtual void on_render_input_window(float x, float y, float bottom_limit) override; private: diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFaceDetector.hpp b/src/slic3r/GUI/Gizmos/GLGizmoFaceDetector.hpp index c20cf4c2090..2cfed8d8370 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFaceDetector.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFaceDetector.hpp @@ -16,7 +16,6 @@ class GLGizmoFaceDetector : public GLGizmoBase protected: void on_render() override; - void on_render_for_picking() override {} void on_render_input_window(float x, float y, float bottom_limit) override; std::string on_get_name() const override; void on_set_state() override; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp index 4ad8136bbaa..efe83ff4fe1 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp @@ -1,6 +1,12 @@ -// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro. +///|/ Copyright (c) Prusa Research 2019 - 2023 Oleksandra Iushchenko @YuSanka, Lukáš Matěna @lukasmatena, Enrico Turri @enricoturri1966, Filip Sykala @Jony01, Vojtěch Bubník @bubnikv +///|/ +///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher +///|/ #include "GLGizmoFlatten.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" +#include "slic3r/GUI/GUI_App.hpp" +#include "slic3r/GUI/Plater.hpp" +#include "slic3r/GUI/GUI_ObjectManipulation.hpp" #include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp" #include "libslic3r/Geometry/ConvexHull.hpp" @@ -13,17 +19,48 @@ namespace Slic3r { namespace GUI { +static const Slic3r::ColorRGBA DEFAULT_PLANE_COLOR = { 0.9f, 0.9f, 0.9f, 0.5f }; +static const Slic3r::ColorRGBA DEFAULT_HOVER_PLANE_COLOR = { 0.9f, 0.9f, 0.9f, 0.75f }; GLGizmoFlatten::GLGizmoFlatten(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id) : GLGizmoBase(parent, icon_filename, sprite_id) - , m_normal(Vec3d::Zero()) - , m_starting_center(Vec3d::Zero()) +{} + +bool GLGizmoFlatten::on_mouse(const wxMouseEvent &mouse_event) +{ + if (mouse_event.LeftDown()) { + if (m_hover_id != -1) { + Selection &selection = m_parent.get_selection(); + if (selection.is_single_full_instance()) { + // Rotate the object so the normal points downward: + selection.flattening_rotate(m_planes[m_hover_id].normal); + m_parent.do_rotate(L("Gizmo-Place on Face")); + wxGetApp().obj_manipul()->set_dirty(); + } + return true; + } + } + else if (mouse_event.LeftUp()) + return m_hover_id != -1; + + return false; +} + +void GLGizmoFlatten::data_changed(bool is_serializing) { + const Selection & selection = m_parent.get_selection(); + const ModelObject *model_object = nullptr; + int instance_id = -1; + if (selection.is_single_full_instance() || + selection.is_from_single_object() ) { + model_object = selection.get_model()->objects[selection.get_object_idx()]; + instance_id = selection.get_instance_idx(); + } + set_flattening_data(model_object, instance_id); } bool GLGizmoFlatten::on_init() { - // BBS m_shortcut_key = WXK_CONTROL_F; return true; } @@ -39,7 +76,7 @@ CommonGizmosDataID GLGizmoFlatten::on_get_requirements() const std::string GLGizmoFlatten::on_get_name() const { - return _u8L("Lay on face"); + return _u8L("Place on face"); } bool GLGizmoFlatten::on_is_activable() const @@ -49,77 +86,73 @@ bool GLGizmoFlatten::on_is_activable() const return m_parent.get_selection().is_single_full_instance(); } -void GLGizmoFlatten::on_start_dragging() -{ - if (m_hover_id != -1) { - assert(m_planes_valid); - m_normal = m_planes[m_hover_id].normal; - m_starting_center = m_parent.get_selection().get_bounding_box().center(); - } -} - void GLGizmoFlatten::on_render() { const Selection& selection = m_parent.get_selection(); + GLShaderProgram* shader = wxGetApp().get_shader("flat"); + if (shader == nullptr) + return; + + shader->start_using(); + glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_BLEND)); if (selection.is_single_full_instance()) { - const Transform3d& m = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(); - glsafe(::glPushMatrix()); - glsafe(::glTranslatef(0.f, 0.f, selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z())); - glsafe(::glMultMatrixd(m.data())); + const Transform3d& inst_matrix = selection.get_first_volume()->get_instance_transformation().get_matrix(); + const Camera& camera = wxGetApp().plater()->get_camera(); + const Transform3d model_matrix = Geometry::translation_transform(selection.get_first_volume()->get_sla_shift_z() * Vec3d::UnitZ()) * inst_matrix; + const Transform3d view_model_matrix = camera.get_view_matrix() * model_matrix; + + shader->set_uniform("view_model_matrix", view_model_matrix); + shader->set_uniform("projection_matrix", camera.get_projection_matrix()); if (this->is_plane_update_necessary()) update_planes(); for (int i = 0; i < (int)m_planes.size(); ++i) { - if (i == m_hover_id) - glsafe(::glColor4fv(GLGizmoBase::FLATTEN_HOVER_COLOR.data())); - else - glsafe(::glColor4fv(GLGizmoBase::FLATTEN_COLOR.data())); - - if (m_planes[i].vbo.has_VBOs()) - m_planes[i].vbo.render(); + m_planes[i].vbo.model.set_color(i == m_hover_id ? DEFAULT_HOVER_PLANE_COLOR : DEFAULT_PLANE_COLOR); + m_planes[i].vbo.model.render(); } - glsafe(::glPopMatrix()); } glsafe(::glEnable(GL_CULL_FACE)); glsafe(::glDisable(GL_BLEND)); + + shader->stop_using(); } -void GLGizmoFlatten::on_render_for_picking() +void GLGizmoFlatten::on_register_raycasters_for_picking() { - const Selection& selection = m_parent.get_selection(); + // the gizmo grabbers are rendered on top of the scene, so the raytraced picker should take it into account + m_parent.set_raycaster_gizmos_on_top(true); - glsafe(::glDisable(GL_DEPTH_TEST)); - glsafe(::glDisable(GL_BLEND)); + assert(m_planes_casters.empty()); + + if (!m_planes.empty()) { + const Selection& selection = m_parent.get_selection(); + const Transform3d matrix = Geometry::translation_transform(selection.get_first_volume()->get_sla_shift_z() * Vec3d::UnitZ()) * + selection.get_first_volume()->get_instance_transformation().get_matrix(); - if (selection.is_single_full_instance() && !wxGetKeyState(WXK_CONTROL)) { - const Transform3d& m = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(); - glsafe(::glPushMatrix()); - glsafe(::glTranslatef(0.f, 0.f, selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z())); - glsafe(::glMultMatrixd(m.data())); - if (this->is_plane_update_necessary()) - update_planes(); for (int i = 0; i < (int)m_planes.size(); ++i) { - glsafe(::glColor4fv(picking_color_component(i).data())); - m_planes[i].vbo.render(); + m_planes_casters.emplace_back(m_parent.add_raycaster_for_picking(SceneRaycaster::EType::Gizmo, i, *m_planes[i].vbo.mesh_raycaster, matrix)); } - glsafe(::glPopMatrix()); } +} - glsafe(::glEnable(GL_CULL_FACE)); +void GLGizmoFlatten::on_unregister_raycasters_for_picking() +{ + m_parent.remove_raycasters_for_picking(SceneRaycaster::EType::Gizmo); + m_parent.set_raycaster_gizmos_on_top(false); + m_planes_casters.clear(); } -void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object) +void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object, int instance_id) { - m_starting_center = Vec3d::Zero(); - if (model_object != m_old_model_object) { + if (model_object != m_old_model_object || instance_id != m_old_instance_id) { m_planes.clear(); - m_planes_valid = false; + on_unregister_raycasters_for_picking(); } } @@ -136,12 +169,12 @@ void GLGizmoFlatten::update_planes() } ch = ch.convex_hull_3d(); m_planes.clear(); - const Transform3d& inst_matrix = mo->instances.front()->get_matrix(true); + on_unregister_raycasters_for_picking(); + const Transform3d inst_matrix = mo->instances.front()->get_matrix_no_offset(); // Following constants are used for discarding too small polygons. const float minimal_area = 5.f; // in square mm (world coordinates) const float minimal_side = 1.f; // mm - const float minimal_angle = 1.f; // degree, initial value was 10, but cause bugs // Now we'll go through all the facets and append Points of facets sharing the same normal. // This part is still performed in mesh coordinate system. @@ -152,7 +185,7 @@ void GLGizmoFlatten::update_planes() std::vector facet_visited(num_of_facets, false); int facet_queue_cnt = 0; const stl_normal* normal_ptr = nullptr; - int facet_idx = 0; + int facet_idx = 0; while (1) { // Find next unvisited triangle: for (; facet_idx < num_of_facets; ++ facet_idx) @@ -196,9 +229,7 @@ void GLGizmoFlatten::update_planes() } // Let's prepare transformation of the normal vector from mesh to instance coordinates. - Geometry::Transformation t(inst_matrix); - Vec3d scaling = t.get_scaling_factor(); - t.set_scaling_factor(Vec3d(1./scaling(0), 1./scaling(1), 1./scaling(2))); + const Matrix3d normal_matrix = inst_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); // Now we'll go through all the polygons, transform the points into xy plane to process them: for (unsigned int polygon_id=0; polygon_id < m_planes.size(); ++polygon_id) { @@ -206,7 +237,7 @@ void GLGizmoFlatten::update_planes() const Vec3d& normal = m_planes[polygon_id].normal; // transform the normal according to the instance matrix: - Vec3d normal_transformed = t.get_matrix() * normal; + const Vec3d normal_transformed = normal_matrix * normal; // We are going to rotate about z and y to flatten the plane Eigen::Quaterniond q; @@ -219,7 +250,7 @@ void GLGizmoFlatten::update_planes() // And yes, it is a nasty thing to do. Whoever has time is free to refactor. Vec3d bb_size = BoundingBoxf3(polygon).size(); float sf = std::min(1./bb_size(0), 1./bb_size(1)); - Transform3d tr = Geometry::assemble_transform(Vec3d::Zero(), Vec3d::Zero(), Vec3d(sf, sf, 1.f)); + Transform3d tr = Geometry::scale_transform({ sf, sf, 1.f }); polygon = transform(polygon, tr); polygon = Slic3r::Geometry::convex_hull(polygon); polygon = transform(polygon, tr.inverse()); @@ -236,7 +267,7 @@ void GLGizmoFlatten::update_planes() discard = true; else { // We also check the inner angles and discard polygons with angles smaller than the following threshold - const double angle_threshold = ::cos(minimal_angle * (double)PI / 180.0); + const double angle_threshold = ::cos(10.0 * (double)PI / 180.0); for (unsigned int i = 0; i < polygon.size(); ++i) { const Vec3d& prec = polygon[(i == 0) ? polygon.size() - 1 : i - 1]; @@ -324,34 +355,46 @@ void GLGizmoFlatten::update_planes() m_first_instance_scale = mo->instances.front()->get_scaling_factor(); m_first_instance_mirror = mo->instances.front()->get_mirror(); m_old_model_object = mo; + m_old_instance_id = m_c->selection_info()->get_active_instance(); // And finally create respective VBOs. The polygon is convex with // the vertices in order, so triangulation is trivial. for (auto& plane : m_planes) { - plane.vbo.reserve(plane.vertices.size()); - for (const auto& vert : plane.vertices) - plane.vbo.push_geometry(vert, plane.normal); - for (size_t i=1; i()); + } + for (size_t i = 1; i < plane.vertices.size() - 1; ++i) { + its.indices.emplace_back(0, i, i + 1); // triangle fan + } + + plane.vbo.model.init_from(its); + if (Geometry::Transformation(inst_matrix).is_left_handed()) { + // we need to swap face normals in case the object is mirrored + // for the raycaster to work properly + for (stl_triangle_vertex_indices& face : its.indices) { + if (its_face_normal(its, face).cast().dot(plane.normal) < 0.0) + std::swap(face[1], face[2]); + } + } + plane.vbo.mesh_raycaster = std::make_unique(std::make_shared(std::move(its))); + // vertices are no more needed, clear memory + plane.vertices = std::vector(); } - m_planes_valid = true; + on_register_raycasters_for_picking(); } - bool GLGizmoFlatten::is_plane_update_necessary() const { const ModelObject* mo = m_c->selection_info()->model_object(); if (m_state != On || ! mo || mo->instances.empty()) return false; - if (! m_planes_valid || mo != m_old_model_object - || mo->volumes.size() != m_volumes_matrices.size()) + if (m_planes.empty() || mo != m_old_model_object + || mo->volumes.size() != m_volumes_matrices.size()) return true; // We want to recalculate when the scale changes - some planes could (dis)appear. @@ -367,13 +410,5 @@ bool GLGizmoFlatten::is_plane_update_necessary() const return false; } -Vec3d GLGizmoFlatten::get_flattening_normal() const -{ - Vec3d out = m_normal; - m_normal = Vec3d::Zero(); - m_starting_center = Vec3d::Zero(); - return out; -} - } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp index ab3c2c7bab1..3dfbaf3b78a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFlatten.hpp @@ -1,9 +1,13 @@ +///|/ Copyright (c) Prusa Research 2019 - 2023 Oleksandra Iushchenko @YuSanka, Lukáš Matěna @lukasmatena, Enrico Turri @enricoturri1966, Filip Sykala @Jony01 +///|/ +///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher +///|/ #ifndef slic3r_GLGizmoFlatten_hpp_ #define slic3r_GLGizmoFlatten_hpp_ #include "GLGizmoBase.hpp" -#include "slic3r/GUI/3DScene.hpp" - +#include "slic3r/GUI/GLModel.hpp" +#include "slic3r/GUI/MeshUtils.hpp" namespace Slic3r { @@ -18,13 +22,15 @@ class GLGizmoFlatten : public GLGizmoBase // This gizmo does not use grabbers. The m_hover_id relates to polygon managed by the class itself. private: - mutable Vec3d m_normal; + + GLModel arrow; struct PlaneData { std::vector vertices; // should be in fact local in update_planes() - GLIndexedVertexArray vbo; + PickingModel vbo; Vec3d normal; float area; + int picking_id{ -1 }; }; // This holds information to decide whether recalculation is necessary: @@ -34,10 +40,9 @@ class GLGizmoFlatten : public GLGizmoBase Vec3d m_first_instance_mirror; std::vector m_planes; - bool m_planes_valid = false; - mutable Vec3d m_starting_center; + std::vector> m_planes_casters; const ModelObject* m_old_model_object = nullptr; - std::vector instances_matrices; + int m_old_instance_id{ -1 }; void update_planes(); bool is_plane_update_necessary() const; @@ -45,18 +50,25 @@ class GLGizmoFlatten : public GLGizmoBase public: GLGizmoFlatten(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); - void set_flattening_data(const ModelObject* model_object); - Vec3d get_flattening_normal() const; + void set_flattening_data(const ModelObject* model_object, int instance_id); + + /// + /// Apply rotation on select plane + /// + /// Keep information about mouse click + /// Return True when use the information otherwise False. + bool on_mouse(const wxMouseEvent &mouse_event) override; + void data_changed(bool is_serializing) override; protected: - virtual bool on_init() override; - virtual std::string on_get_name() const override; - virtual bool on_is_activable() const override; - virtual void on_start_dragging() override; - virtual void on_render() override; - virtual void on_render_for_picking() override; - virtual void on_set_state() override; - virtual CommonGizmosDataID on_get_requirements() const override; + bool on_init() override; + std::string on_get_name() const override; + bool on_is_activable() const override; + void on_render() override; + virtual void on_register_raycasters_for_picking() override; + virtual void on_unregister_raycasters_for_picking() override; + void on_set_state() override; + CommonGizmosDataID on_get_requirements() const override; }; } // namespace GUI diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp index 142ffb5a1d6..f8ea6d7f1b0 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp @@ -88,16 +88,16 @@ void GLGizmoHollow::on_render() } -void GLGizmoHollow::on_render_for_picking() -{ - 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 +// void GLGizmoHollow::on_render_for_picking() +// { +// 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); -} +// glsafe(::glEnable(GL_DEPTH_TEST)); +// render_points(selection, true); +// } void GLGizmoHollow::render_points(const Selection& selection, bool picking) { @@ -127,8 +127,8 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking) // First decide about the color of the point. if (picking) { - std::array color = picking_color_component(i); - render_color = color; + // std::array color = picking_color_component(i); + // render_color = color; } else { if (size_t(m_hover_id) == i) { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp index 89bd060cc13..c2ee014fc88 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp @@ -40,7 +40,6 @@ class GLGizmoHollow : public GLGizmoBase bool on_init() override; void on_update(const UpdateData& data) override; void on_render() override; - void on_render_for_picking() override; void render_points(const Selection& selection, bool picking = false); void hollow_mesh(bool postpone_error_messages = false); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp index 0e3524f087e..6a8f21a1991 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.hpp @@ -175,7 +175,6 @@ class GLGizmoMeasure : public GLGizmoBase virtual void on_render_input_window(float x, float y, float bottom_limit) override; virtual void on_register_raycasters_for_picking() override; virtual void on_unregister_raycasters_for_picking() override; - virtual void on_render_for_picking() override {} void remove_selected_sphere_raycaster(int id); void update_measurement_result(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeshBoolean.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMeshBoolean.hpp index 42fa97eede1..f88ac85c976 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeshBoolean.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeshBoolean.hpp @@ -62,7 +62,6 @@ class GLGizmoMeshBoolean : public GLGizmoBase virtual std::string on_get_name() const override; virtual bool on_is_activable() const override; virtual void on_render() override; - virtual void on_render_for_picking() override {} virtual void on_set_state() override; virtual CommonGizmosDataID on_get_requirements() const override; virtual void on_render_input_window(float x, float y, float bottom_limit); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp index 46986e54899..e94882feedb 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp @@ -74,12 +74,10 @@ bool GLGizmoMove3D::on_is_activable() const void GLGizmoMove3D::on_start_dragging() { if (m_hover_id != -1) { - m_displacement = Vec3d::Zero(); - const BoundingBoxf3& box = m_parent.get_selection().get_bounding_box(); - m_starting_drag_position = m_grabbers[m_hover_id].center; - m_starting_box_center = box.center(); - m_starting_box_bottom_center = box.center(); - m_starting_box_bottom_center(2) = box.min(2); + m_displacement = Vec3d::Zero(); + m_starting_drag_position = m_grabbers[m_hover_id].matrix * m_grabbers[m_hover_id].center; + m_starting_box_center = m_center; + m_starting_box_bottom_center = Vec3d(m_center.x(), m_center.y(), m_bounding_box.min.z()); } } @@ -100,86 +98,134 @@ void GLGizmoMove3D::on_update(const UpdateData& data) void GLGizmoMove3D::on_render() { - const Selection& selection = m_parent.get_selection(); - glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); glsafe(::glEnable(GL_DEPTH_TEST)); - const BoundingBoxf3& box = selection.get_bounding_box(); - const Vec3d& center = box.center(); - float space_size = 20.f *INV_ZOOM; - -#if ENABLE_FIXED_GRABBER - // x axis - m_grabbers[0].center = { box.max.x() + space_size, center.y(), center.z() }; - // y axis - m_grabbers[1].center = { center.x(), box.max.y() + space_size, center.z() }; - // z axis - m_grabbers[2].center = { center.x(), center.y(), box.max.z() + space_size }; + const Selection& selection = m_parent.get_selection(); + const auto& [box, box_trafo] = selection.get_bounding_box_in_current_reference_system(); + m_bounding_box = box; + m_center = box_trafo.translation(); + const Transform3d base_matrix = box_trafo; for (int i = 0; i < 3; ++i) { - m_grabbers[i].color = AXES_COLOR[i]; - m_grabbers[i].hover_color = AXES_HOVER_COLOR[i]; + m_grabbers[i].matrix = base_matrix; } -#else + + const Vec3d zero = Vec3d::Zero(); + const Vec3d half_box_size = 0.5 * m_bounding_box.size(); + // x axis - m_grabbers[0].center = { box.max.x() + Offset, center.y(), center.z() }; + m_grabbers[0].center = { half_box_size.x() + Offset, 0.0, 0.0 }; m_grabbers[0].color = AXES_COLOR[0]; // y axis - m_grabbers[1].center = { center.x(), box.max.y() + Offset, center.z() }; + m_grabbers[1].center = { 0.0, half_box_size.y() + Offset, 0.0 }; m_grabbers[1].color = AXES_COLOR[1]; // z axis - m_grabbers[2].center = { center.x(), center.y(), box.max.z() + Offset }; + m_grabbers[2].center = { 0.0, 0.0, half_box_size.z() + Offset }; m_grabbers[2].color = AXES_COLOR[2]; -#endif - glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); +#if ENABLE_GL_CORE_PROFILE + if (!OpenGLManager::get_gl_info().is_core_profile()) +#endif // ENABLE_GL_CORE_PROFILE + glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); - // draw grabbers - for (unsigned int i = 0; i < 3; ++i) { - if (m_grabbers[i].enabled) render_grabber_extension((Axis) i, box, false); - } + auto render_grabber_connection = [this, &zero](unsigned int id) { + if (m_grabbers[id].enabled) { + if (!m_grabber_connections[id].model.is_initialized() || !m_grabber_connections[id].old_center.isApprox(m_grabbers[id].center)) { + m_grabber_connections[id].old_center = m_grabbers[id].center; + m_grabber_connections[id].model.reset(); - // draw axes line - // draw axes - for (unsigned int i = 0; i < 3; ++i) { - if (m_grabbers[i].enabled) { - glsafe(::glColor4fv(AXES_COLOR[i].data())); - glLineStipple(1, 0x0FFF); - glEnable(GL_LINE_STIPPLE); - ::glBegin(GL_LINES); - ::glVertex3dv(center.data()); - // use extension center - ::glVertex3dv(m_grabbers[i].center.data()); - glsafe(::glEnd()); - glDisable(GL_LINE_STIPPLE); - } - } -} + GLModel::Geometry init_data; + init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3 }; + init_data.color = AXES_COLOR[id]; + init_data.vertices.reserve(2); + init_data.indices.reserve(2); -void GLGizmoMove3D::on_render_for_picking() -{ - glsafe(::glDisable(GL_DEPTH_TEST)); + // vertices + init_data.add_vertex((Vec3f)zero.cast()); + init_data.add_vertex((Vec3f)m_grabbers[id].center.cast()); - const BoundingBoxf3& box = m_parent.get_selection().get_bounding_box(); - //BBS donot render base grabber for picking - //render_grabbers_for_picking(box); + // indices + init_data.add_line(0, 1); - //get picking colors only - for (unsigned int i = 0; i < (unsigned int) m_grabbers.size(); ++i) { - if (m_grabbers[i].enabled) { - std::array color = picking_color_component(i); - m_grabbers[i].color = color; + m_grabber_connections[id].model.init_from(std::move(init_data)); + } + + m_grabber_connections[id].model.render(); } + }; + + if (m_hover_id == -1) { +#if ENABLE_GL_CORE_PROFILE + GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); +#else + GLShaderProgram* shader = wxGetApp().get_shader("flat"); +#endif // ENABLE_GL_CORE_PROFILE + if (shader != nullptr) { + shader->start_using(); + const Camera& camera = wxGetApp().plater()->get_camera(); + shader->set_uniform("view_model_matrix", camera.get_view_matrix() * base_matrix); + shader->set_uniform("projection_matrix", camera.get_projection_matrix()); +#if ENABLE_GL_CORE_PROFILE + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.25f); + shader->set_uniform("gap_size", 0.0f); +#endif // ENABLE_GL_CORE_PROFILE + + // draw axes + for (unsigned int i = 0; i < 3; ++i) { + render_grabber_connection(i); + } + + shader->stop_using(); + } + + // draw grabbers + render_grabbers(m_bounding_box); } + else { + // draw axis +#if ENABLE_GL_CORE_PROFILE + GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); +#else + GLShaderProgram* shader = wxGetApp().get_shader("flat"); +#endif // ENABLE_GL_CORE_PROFILE + if (shader != nullptr) { + shader->start_using(); + + const Camera& camera = wxGetApp().plater()->get_camera(); + shader->set_uniform("view_model_matrix", camera.get_view_matrix()* base_matrix); + shader->set_uniform("projection_matrix", camera.get_projection_matrix()); +#if ENABLE_GL_CORE_PROFILE + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.5f); + shader->set_uniform("gap_size", 0.0f); +#endif // ENABLE_GL_CORE_PROFILE + + render_grabber_connection(m_hover_id); + shader->stop_using(); + } - render_grabber_extension(X, box, true); - render_grabber_extension(Y, box, true); - render_grabber_extension(Z, box, true); + shader = wxGetApp().get_shader("gouraud_light"); + if (shader != nullptr) { + shader->start_using(); + shader->set_uniform("emission_factor", 0.1f); + glsafe(::glDisable(GL_CULL_FACE)); + // draw grabber + const Vec3d box_size = m_bounding_box.size(); + const float mean_size = (float)((box_size.x() + box_size.y() + box_size.z()) / 3.0); + m_grabbers[m_hover_id].render(true, mean_size); + glsafe(::glEnable(GL_CULL_FACE)); + shader->stop_using(); + } + } } + //BBS: add input window for move void GLGizmoMove3D::on_render_input_window(float x, float y, float bottom_limit) { @@ -214,49 +260,6 @@ double GLGizmoMove3D::calc_projection(const UpdateData& data) const return projection; } -void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box, bool picking) -{ -#if ENABLE_FIXED_GRABBER - float mean_size = (float)(GLGizmoBase::Grabber::FixedGrabberSize); -#else - float mean_size = (float)((box.size().x() + box.size().y() + box.size().z()) / 3.0); -#endif - - double size = 0.75 * GLGizmoBase::Grabber::FixedGrabberSize * GLGizmoBase::INV_ZOOM; - - std::array color = m_grabbers[axis].color; - if (!picking && m_hover_id != -1) { - if (m_hover_id == axis) { - color = m_grabbers[axis].hover_color; - } - } - - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); - if (shader == nullptr) - return; - - m_vbo_cone.set_color(color); - if (!picking) { - shader->start_using(); - shader->set_uniform("emission_factor", 0.1f); - } - - glsafe(::glPushMatrix()); - glsafe(::glTranslated(m_grabbers[axis].center.x(), m_grabbers[axis].center.y(), m_grabbers[axis].center.z())); - if (axis == X) - glsafe(::glRotated(90.0, 0.0, 1.0, 0.0)); - else if (axis == Y) - glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0)); - - //glsafe(::glTranslated(0.0, 0.0, 2.0 * size)); - glsafe(::glScaled(0.75 * size, 0.75 * size, 2.0 * size)); - m_vbo_cone.render(); - glsafe(::glPopMatrix()); - - if (! picking) - shader->stop_using(); -} - } // namespace GUI diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp index 16f4a98903d..e15fc4a8a12 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.hpp @@ -16,7 +16,8 @@ class GLGizmoMove3D : public GLGizmoBase static const double Offset; Vec3d m_displacement; - + Vec3d m_center{ Vec3d::Zero() }; + BoundingBoxf3 m_bounding_box; double m_snap_step; Vec3d m_starting_drag_position; @@ -27,6 +28,12 @@ class GLGizmoMove3D : public GLGizmoBase //BBS: add size adjust related GizmoObjectManipulation* m_object_manipulation; + struct GrabberConnection + { + GLModel model; + Vec3d old_center{Vec3d::Zero()}; + }; + std::array m_grabber_connections; public: //BBS: add obj manipulation logic @@ -49,13 +56,11 @@ class GLGizmoMove3D : public GLGizmoBase virtual void on_stop_dragging() override; virtual void on_update(const UpdateData& data) override; virtual void on_render() override; - virtual void on_render_for_picking() override; //BBS: GUI refactor: add object manipulation virtual void on_render_input_window(float x, float y, float bottom_limit); private: double calc_projection(const UpdateData& data) const; - void render_grabber_extension(Axis axis, const BoundingBoxf3& box, bool picking); }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp index 5e472c5b049..35ce8b4df6d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp @@ -214,7 +214,6 @@ class GLGizmoPainterBase : public GLGizmoBase ObjectID m_old_mo_id; size_t m_old_volumes_size = 0; void on_render() override {} - void on_render_for_picking() override {} public: GLGizmoPainterBase(GLCanvas3D& parent, const std::string& icon_filename, unsigned int sprite_id); ~GLGizmoPainterBase() override = default; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index 3537f0ee8ec..28321683897 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -165,27 +165,11 @@ void GLGizmoRotate::on_render() render_angle(); render_grabber(box); - render_grabber_extension(box, false); + // render_grabber_extension(box, false); glsafe(::glPopMatrix()); } -void GLGizmoRotate::on_render_for_picking() -{ - const Selection& selection = m_parent.get_selection(); - - glsafe(::glDisable(GL_DEPTH_TEST)); - - glsafe(::glPushMatrix()); - - transform_to_local(selection); - - const BoundingBoxf3& box = selection.get_bounding_box(); - render_grabbers_for_picking(box); - render_grabber_extension(box, true); - - glsafe(::glPopMatrix()); -} //BBS: add input window for move void GLGizmoRotate3D::on_render_input_window(float x, float y, float bottom_limit) @@ -325,50 +309,50 @@ void GLGizmoRotate::render_grabber(const BoundingBoxf3& box) const render_grabbers(box); } -void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool picking) -{ - double size = 0.75 * GLGizmoBase::Grabber::FixedGrabberSize * GLGizmoBase::INV_ZOOM; - //float mean_size = (float)((box.size()(0) + box.size()(1) + box.size()(2)) / 3.0); - //double size = m_dragging ? (double)m_grabbers[0].get_dragging_half_size(mean_size) : (double)m_grabbers[0].get_half_size(mean_size); - - std::array color = m_grabbers[0].color; - if (!picking && m_hover_id != -1) { - color = m_grabbers[0].hover_color; - //color[0] = 1.0f - color[0]; - //color[1] = 1.0f - color[1]; - //color[2] = 1.0f - color[2]; - } - - GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); - if (shader == nullptr) - return; - - m_cone.set_color(color); - if (!picking) { - shader->start_using(); - shader->set_uniform("emission_factor", 0.1f); - } - - glsafe(::glPushMatrix()); - glsafe(::glTranslated(m_grabbers[0].center.x(), m_grabbers[0].center.y(), m_grabbers[0].center.z())); - glsafe(::glRotated(Geometry::rad2deg(m_angle), 0.0, 0.0, 1.0)); - glsafe(::glRotated(90.0, 1.0, 0.0, 0.0)); - glsafe(::glTranslated(0.0, 0.0, 1.5 * size)); - glsafe(::glScaled(0.75 * size, 0.75 * size, 3.0 * size)); - m_cone.render(); - glsafe(::glPopMatrix()); - glsafe(::glPushMatrix()); - glsafe(::glTranslated(m_grabbers[0].center.x(), m_grabbers[0].center.y(), m_grabbers[0].center.z())); - glsafe(::glRotated(Geometry::rad2deg(m_angle), 0.0, 0.0, 1.0)); - glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0)); - glsafe(::glTranslated(0.0, 0.0, 1.5 * size)); - glsafe(::glScaled(0.75 * size, 0.75 * size, 3.0 * size)); - m_cone.render(); - glsafe(::glPopMatrix()); - - if (! picking) - shader->stop_using(); -} +// void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool picking) +// { +// double size = 0.75 * GLGizmoBase::Grabber::FixedGrabberSize * GLGizmoBase::INV_ZOOM; +// //float mean_size = (float)((box.size()(0) + box.size()(1) + box.size()(2)) / 3.0); +// //double size = m_dragging ? (double)m_grabbers[0].get_dragging_half_size(mean_size) : (double)m_grabbers[0].get_half_size(mean_size); + +// std::array color = m_grabbers[0].color; +// if (!picking && m_hover_id != -1) { +// color = m_grabbers[0].hover_color; +// //color[0] = 1.0f - color[0]; +// //color[1] = 1.0f - color[1]; +// //color[2] = 1.0f - color[2]; +// } + +// GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light"); +// if (shader == nullptr) +// return; + +// m_cone.set_color(color); +// if (!picking) { +// shader->start_using(); +// shader->set_uniform("emission_factor", 0.1f); +// } + +// glsafe(::glPushMatrix()); +// glsafe(::glTranslated(m_grabbers[0].center.x(), m_grabbers[0].center.y(), m_grabbers[0].center.z())); +// glsafe(::glRotated(Geometry::rad2deg(m_angle), 0.0, 0.0, 1.0)); +// glsafe(::glRotated(90.0, 1.0, 0.0, 0.0)); +// glsafe(::glTranslated(0.0, 0.0, 1.5 * size)); +// glsafe(::glScaled(0.75 * size, 0.75 * size, 3.0 * size)); +// m_cone.render(); +// glsafe(::glPopMatrix()); +// glsafe(::glPushMatrix()); +// glsafe(::glTranslated(m_grabbers[0].center.x(), m_grabbers[0].center.y(), m_grabbers[0].center.z())); +// glsafe(::glRotated(Geometry::rad2deg(m_angle), 0.0, 0.0, 1.0)); +// glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0)); +// glsafe(::glTranslated(0.0, 0.0, 1.5 * size)); +// glsafe(::glScaled(0.75 * size, 0.75 * size, 3.0 * size)); +// m_cone.render(); +// glsafe(::glPopMatrix()); + +// if (! picking) +// shader->stop_using(); +// } void GLGizmoRotate::transform_to_local(const Selection& selection) const { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp index 2cbed7c9676..2920b9fa67b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp @@ -61,7 +61,6 @@ class GLGizmoRotate : public GLGizmoBase void on_start_dragging() override; void on_update(const UpdateData& data) override; void on_render() override; - void on_render_for_picking() override; private: void render_circle() const; @@ -70,7 +69,7 @@ class GLGizmoRotate : public GLGizmoBase void render_reference_radius() const; void render_angle() const; void render_grabber(const BoundingBoxf3& box) const; - void render_grabber_extension(const BoundingBoxf3& box, bool picking); + // void render_grabber_extension(const BoundingBoxf3& box, bool picking); void transform_to_local(const Selection& selection) const; // returns the intersection of the mouse ray with the plane perpendicular to the gizmo axis, in local coordinate @@ -144,13 +143,6 @@ class GLGizmoRotate3D : public GLGizmoBase } } void on_render() override; - void on_render_for_picking() override - { - for (GLGizmoRotate& g : m_gizmos) { - g.render_for_picking(); - } - } - void on_render_input_window(float x, float y, float bottom_limit) override; private: diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp index 0f98c5dd358..1a93ce893f9 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp @@ -252,12 +252,6 @@ void GLGizmoScale3D::on_render() render_grabbers(grabber_mean_size); } -void GLGizmoScale3D::on_render_for_picking() -{ - glsafe(::glDisable(GL_DEPTH_TEST)); - render_grabbers_for_picking(m_parent.get_selection().get_bounding_box()); -} - void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2) const { unsigned int grabbers_count = (unsigned int)m_grabbers.size(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp index 839c7f6823c..b583c8f344f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.hpp @@ -63,7 +63,6 @@ class GLGizmoScale3D : public GLGizmoBase virtual void on_start_dragging() override; virtual void on_update(const UpdateData& data) override; virtual void on_render() override; - virtual void on_render_for_picking() override; //BBS: GUI refactor: add object manipulation virtual void on_render_input_window(float x, float y, float bottom_limit); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp index 39093e14d67..b4be94d2c94 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp @@ -37,7 +37,6 @@ class GLGizmoSimplify: public GLGizmoBase // must implement virtual bool on_init() override { return true;}; virtual void on_render() override; - virtual void on_render_for_picking() override{}; CommonGizmosDataID on_get_requirements() const override; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index a9e289b4dee..a819a741b10 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -102,13 +102,6 @@ void GLGizmoSlaSupports::on_render() } -void GLGizmoSlaSupports::on_render_for_picking() -{ - const Selection& selection = m_parent.get_selection(); - //glsafe(::glEnable(GL_DEPTH_TEST)); - render_points(selection, true); -} - void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) { size_t cache_size = m_editing_mode ? m_editing_cache.size() : m_normal_cache.size(); @@ -146,9 +139,10 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) continue; // First decide about the color of the point. - if (picking) - render_color = picking_color_component(i); - else { + if (picking) { + // orca todo + // render_color = picking_color_component(i); + } else { if (size_t(m_hover_id) == i && m_editing_mode) // ignore hover state unless editing mode is active render_color = { 0.f, 1.f, 1.f, 1.f }; else { // neigher hover nor picking diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp index 20dea8d8ebd..87fb0cbd00b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp @@ -75,7 +75,6 @@ class GLGizmoSlaSupports : public GLGizmoBase bool on_init() override; void on_update(const UpdateData& data) override; void on_render() override; - void on_render_for_picking() override; void render_points(const Selection& selection, bool picking = false); bool unsaved_changes() const; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoText.cpp b/src/slic3r/GUI/Gizmos/GLGizmoText.cpp index 553b477b329..d4ff3884cd4 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoText.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoText.cpp @@ -431,24 +431,25 @@ void GLGizmoText::on_render() return; } - if (m_is_modify && m_grabbers.size() == 1) { - std::vector trafo_matrices; - for (const ModelVolume *mv : mo->volumes) { - if (mv->is_model_part()) { - trafo_matrices.emplace_back(mi->get_transformation().get_matrix() * mv->get_matrix()); - } - } - - m_mouse_position_world = trafo_matrices[m_rr.mesh_id] * Vec3d(m_rr.hit(0), m_rr.hit(1), m_rr.hit(2)); - - float mean_size = (float) (GLGizmoBase::Grabber::FixedGrabberSize); - - m_grabbers[0].center = m_mouse_position_world; - m_grabbers[0].enabled = true; - std::array color = picking_color_component(0); - m_grabbers[0].color = color; - m_grabbers[0].render_for_picking(mean_size); - } +// orca todo + // if (m_is_modify && m_grabbers.size() == 1) { + // std::vector trafo_matrices; + // for (const ModelVolume *mv : mo->volumes) { + // if (mv->is_model_part()) { + // trafo_matrices.emplace_back(mi->get_transformation().get_matrix() * mv->get_matrix()); + // } + // } + + // m_mouse_position_world = trafo_matrices[m_rr.mesh_id] * Vec3d(m_rr.hit(0), m_rr.hit(1), m_rr.hit(2)); + + // float mean_size = (float) (GLGizmoBase::Grabber::FixedGrabberSize); + + // m_grabbers[0].center = m_mouse_position_world; + // m_grabbers[0].enabled = true; + // std::array color = picking_color_component(0); + // m_grabbers[0].color = color; + // m_grabbers[0].render_for_picking(mean_size); + // } delete_temp_preview_text_volume(); @@ -459,44 +460,6 @@ void GLGizmoText::on_render() plater->update(); } -void GLGizmoText::on_render_for_picking() -{ - glsafe(::glDisable(GL_DEPTH_TEST)); - - int obejct_idx, volume_idx; - ModelVolume *model_volume = get_selected_single_volume(obejct_idx, volume_idx); - if (model_volume && !model_volume->get_text_info().m_text.empty()) { - if (m_grabbers.size() == 1) { - ModelObject *mo = m_c->selection_info()->model_object(); - if (m_is_modify) { - const Selection &selection = m_parent.get_selection(); - mo = selection.get_model()->objects[m_object_idx]; - } - if (mo == nullptr) return; - - const Selection & selection = m_parent.get_selection(); - const ModelInstance *mi = mo->instances[selection.get_instance_idx()]; - - // Precalculate transformations of individual meshes. - std::vector trafo_matrices; - for (const ModelVolume *mv : mo->volumes) { - if (mv->is_model_part()) { - trafo_matrices.emplace_back(mi->get_transformation().get_matrix() * mv->get_matrix()); - } - } - - m_mouse_position_world = trafo_matrices[m_rr.mesh_id] * Vec3d(m_rr.hit(0), m_rr.hit(1), m_rr.hit(2)); - - float mean_size = (float) (GLGizmoBase::Grabber::FixedGrabberSize); - m_grabbers[0].center = m_mouse_position_world; - m_grabbers[0].enabled = true; - std::array color = picking_color_component(0); - m_grabbers[0].color = color; - m_grabbers[0].render_for_picking(mean_size); - } - } -} - void GLGizmoText::on_update(const UpdateData &data) { Vec2d mouse_pos = Vec2d(data.mouse_pos.x(), data.mouse_pos.y()); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoText.hpp b/src/slic3r/GUI/Gizmos/GLGizmoText.hpp index 53b792364f2..0eaf1304ca3 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoText.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoText.hpp @@ -91,7 +91,6 @@ class GLGizmoText : public GLGizmoBase virtual std::string on_get_name() const override; virtual bool on_is_activable() const override; virtual void on_render() override; - virtual void on_render_for_picking() override; virtual void on_update(const UpdateData &data) override; void push_combo_style(const float scale); void pop_combo_style(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index 8707f7a0dff..0abfd3739ad 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -596,7 +596,9 @@ Vec3d GLGizmosManager::get_flattening_normal() const if (!m_enabled || m_gizmos.empty()) return Vec3d::Zero(); - return dynamic_cast(m_gizmos[Flatten].get())->get_flattening_normal(); + // Orca todo: this function is not available in GLGizmoFlatten anymore + return Vec3d::Zero(); + // return dynamic_cast(m_gizmos[Flatten].get())->get_flattening_normal(); } void GLGizmosManager::set_flattening_data(const ModelObject* model_object) @@ -604,7 +606,8 @@ void GLGizmosManager::set_flattening_data(const ModelObject* model_object) if (!m_enabled || m_gizmos.empty()) return; - dynamic_cast(m_gizmos[Flatten].get())->set_flattening_data(model_object); + // Orca todo: revisit instance id + dynamic_cast(m_gizmos[Flatten].get())->set_flattening_data(model_object,0); } void GLGizmosManager::set_sla_support_data(ModelObject* model_object) @@ -719,14 +722,14 @@ void GLGizmosManager::render_painter_assemble_view() const m_assemble_view_data->model_objects_clipper()->render_cut(); } -void GLGizmosManager::render_current_gizmo_for_picking_pass() const -{ - if (! m_enabled || m_current == Undefined) +// void GLGizmosManager::render_current_gizmo_for_picking_pass() const +// { +// if (! m_enabled || m_current == Undefined) - return; +// return; - m_gizmos[m_current]->render_for_picking(); -} +// m_gizmos[m_current]->render_for_picking(); +// } void GLGizmosManager::render_overlay() { diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp index 70d276b9865..126a5ac1624 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp @@ -287,7 +287,7 @@ class GLGizmosManager : public Slic3r::ObjectBase void on_change_color_mode(bool is_dark); void render_current_gizmo() const; - void render_current_gizmo_for_picking_pass() const; + // void render_current_gizmo_for_picking_pass() const; void render_painter_gizmo(); void render_painter_assemble_view() const;