From 8dc82e7a8d8905f0394fbe284908796b9bbd7e86 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 26 Oct 2023 22:45:42 +0800 Subject: [PATCH] Few small fixes --- src/slic3r/GUI/GCodeViewer.cpp | 6 ++-- src/slic3r/GUI/GLCanvas3D.cpp | 10 ------- src/slic3r/GUI/GLModel.cpp | 17 ++++++----- src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp | 40 ++----------------------- src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp | 1 - 5 files changed, 14 insertions(+), 60 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 3737c7021c..667c950f93 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -5584,13 +5584,13 @@ void GCodeViewer::render_statistics() ImGuiWrapper& imgui = *wxGetApp().imgui(); - auto add_time = [this, &imgui](const std::string& label, int64_t time) { + auto add_time = [&imgui](const std::string& label, int64_t time) { imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label); ImGui::SameLine(offset); imgui.text(std::to_string(time) + " ms (" + get_time_dhms(static_cast(time) * 0.001f) + ")"); }; - auto add_memory = [this, &imgui](const std::string& label, int64_t memory) { + auto add_memory = [&imgui](const std::string& label, int64_t memory) { auto format_string = [memory](const std::string& units, float value) { return std::to_string(memory) + " bytes (" + Slic3r::float_to_string_decimal_point(float(memory) * value, 3) @@ -5613,7 +5613,7 @@ void GCodeViewer::render_statistics() imgui.text(format_string("GB", inv_gb)); }; - auto add_counter = [this, &imgui](const std::string& label, int64_t counter) { + auto add_counter = [&imgui](const std::string& label, int64_t counter) { imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label); ImGui::SameLine(offset); imgui.text(std::to_string(counter)); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 32b828e6fa..a6d32d8d5f 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -7002,14 +7002,6 @@ void GLCanvas3D::_check_and_update_toolbar_icon_scale() void GLCanvas3D::_render_overlays() { glsafe(::glDisable(GL_DEPTH_TEST)); - glsafe(::glPushMatrix()); - glsafe(::glLoadIdentity()); - // ensure that the textures are renderered inside the frustrum - const Camera& camera = wxGetApp().plater()->get_camera(); - glsafe(::glTranslated(0.0, 0.0, -(camera.get_near_z() + 0.10))); - // ensure that the overlay fits the frustrum near z plane - double gui_scale = camera.get_gui_scale(); - glsafe(::glScaled(gui_scale, gui_scale, 1.0)); _check_and_update_toolbar_icon_scale(); @@ -7081,8 +7073,6 @@ void GLCanvas3D::_render_overlays() }*/ } m_labels.render(sorted_instances); - - glsafe(::glPopMatrix()); } void GLCanvas3D::_render_style_editor() diff --git a/src/slic3r/GUI/GLModel.cpp b/src/slic3r/GUI/GLModel.cpp index 94a431f1c8..eaaf4b4bd3 100644 --- a/src/slic3r/GUI/GLModel.cpp +++ b/src/slic3r/GUI/GLModel.cpp @@ -417,7 +417,7 @@ void GLModel::init_from(const indexed_triangle_set& its) // update bounding box for (size_t i = 0; i < vertices_count(); ++i) { - m_bounding_box.merge(m_render_data.geometry.extract_position_3(i).cast()); + m_bounding_box.merge(data.extract_position_3(i).cast()); } } @@ -460,7 +460,7 @@ void GLModel::init_from(const Polygons& polygons, float z) // update bounding box for (size_t i = 0; i < vertices_count(); ++i) { - m_bounding_box.merge(m_render_data.geometry.extract_position_3(i).cast()); + m_bounding_box.merge(data.extract_position_3(i).cast()); } } @@ -707,31 +707,32 @@ bool GLModel::send_to_gpu() // indices glsafe(::glGenBuffers(1, &m_render_data.ibo_id)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_render_data.ibo_id)); + const size_t indices_count = data.indices.size(); if (m_render_data.vertices_count <= 256) { // convert indices to unsigned char to save gpu memory - std::vector reduced_indices(data.indices.size()); - for (size_t i = 0; i < data.indices.size(); ++i) { + std::vector reduced_indices(indices_count); + for (size_t i = 0; i < indices_count; ++i) { reduced_indices[i] = (unsigned char)data.indices[i]; } data.index_type = Geometry::EIndexType::UBYTE; - glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, reduced_indices.size() * sizeof(unsigned char), reduced_indices.data(), GL_STATIC_DRAW)); + glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_count * sizeof(unsigned char), reduced_indices.data(), GL_STATIC_DRAW)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); } else if (m_render_data.vertices_count <= 65536) { // convert indices to unsigned short to save gpu memory - std::vector reduced_indices(data.indices.size()); + std::vector reduced_indices(indices_count); for (size_t i = 0; i < data.indices.size(); ++i) { reduced_indices[i] = (unsigned short)data.indices[i]; } data.index_type = Geometry::EIndexType::USHORT; - glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, reduced_indices.size() * sizeof(unsigned short), reduced_indices.data(), GL_STATIC_DRAW)); + glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_count * sizeof(unsigned short), reduced_indices.data(), GL_STATIC_DRAW)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); } else { glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, data.indices_size_bytes(), data.indices.data(), GL_STATIC_DRAW)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); } - m_render_data.indices_count = indices_count(); + m_render_data.indices_count = indices_count; data.indices = std::vector(); return true; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index ab3196364e..7924fea189 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -157,13 +157,9 @@ void GLGizmoRotate::on_render() render_grabber_connection(color, radius_changed); shader->stop_using(); } - glsafe(::glPushMatrix()); - transform_to_local(selection); render_grabber(box); render_grabber_extension(box, false); - - glsafe(::glPopMatrix()); } void GLGizmoRotate::on_render_for_picking() @@ -445,12 +441,12 @@ Transform3d GLGizmoRotate::local_transform(const Selection& selection) const { case X: { - ret = Geometry::assemble_transform(Vec3d::Zero(), Vec3d(0.0, 0.5 * PI, 0.0)) * Geometry::assemble_transform(Vec3d::Zero(), Vec3d(0.0, 0.0, -0.5 * PI)); + ret = Geometry::assemble_transform(Vec3d::Zero(), 0.5 * PI * Vec3d::UnitY()) * Geometry::assemble_transform(Vec3d::Zero(), -0.5 * PI * Vec3d::UnitZ()); break; } case Y: { - ret = Geometry::assemble_transform(Vec3d::Zero(), Vec3d(0.0, 0.0, -0.5 * PI)) * Geometry::assemble_transform(Vec3d::Zero(), Vec3d(0.0, -0.5 * PI, 0.0)); + ret = Geometry::assemble_transform(Vec3d::Zero(), -0.5 * PI * Vec3d::UnitZ()) * Geometry::assemble_transform(Vec3d::Zero(), -0.5 * PI * Vec3d::UnitY()); break; } default: @@ -467,38 +463,6 @@ Transform3d GLGizmoRotate::local_transform(const Selection& selection) const return Geometry::assemble_transform(m_center) * ret; } -void GLGizmoRotate::transform_to_local(const Selection& selection) const -{ - glsafe(::glTranslated(m_center.x(), m_center.y(), m_center.z())); - - if (selection.is_single_volume() || selection.is_single_modifier() || selection.requires_local_axes()) { - const Transform3d orient_matrix = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(true, false, true, true); - glsafe(::glMultMatrixd(orient_matrix.data())); - } - - switch (m_axis) - { - case X: - { - glsafe(::glRotatef(90.0f, 0.0f, 1.0f, 0.0f)); - glsafe(::glRotatef(-90.0f, 0.0f, 0.0f, 1.0f)); - break; - } - case Y: - { - glsafe(::glRotatef(-90.0f, 0.0f, 0.0f, 1.0f)); - glsafe(::glRotatef(-90.0f, 0.0f, 1.0f, 0.0f)); - break; - } - default: - case Z: - { - // no rotation - break; - } - } -} - Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray, const Selection& selection) const { double half_pi = 0.5 * double(PI); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp index b3cb707808..80d16172bf 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.hpp @@ -87,7 +87,6 @@ private: Transform3d local_transform(const Selection& selection) const; - 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 Vec3d mouse_position_in_local_plane(const Linef3& mouse_ray, const Selection& selection) const; };