diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp index fc6decbaa8..392a2db878 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp @@ -218,15 +218,9 @@ void InstancesHider::render_cut() const clipper->set_limiting_plane(ClippingPlane::ClipsNothing()); glsafe(::glPushMatrix()); - if (mv->is_model_part()) - glsafe(::glColor3f(0.8f, 0.3f, 0.0f)); - else { - const ColorRGBA color = color_from_model_volume(*mv); - glsafe(::glColor4fv(color.data())); - } glsafe(::glPushAttrib(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST)); - clipper->render_cut(); + clipper->render_cut(mv->is_model_part() ? ColorRGBA(0.8f, 0.3f, 0.0f, 1.0f) : color_from_model_volume(*mv)); glsafe(::glPopAttrib()); glsafe(::glPopMatrix()); @@ -435,8 +429,7 @@ void ObjectClipper::render_cut() const clipper->set_limiting_plane(ClippingPlane(Vec3d::UnitZ(), -SINKING_Z_THRESHOLD)); glsafe(::glPushMatrix()); // BBS - glsafe(::glColor3f(0.25f, 0.25f, 0.25f)); - clipper->render_cut(); + clipper->render_cut({ 0.25f, 0.25f, 0.25f, 1.0f }); glsafe(::glPopMatrix()); ++clipper_id; @@ -584,8 +577,7 @@ void SupportsClipper::render_cut() const m_clipper->set_transformation(supports_trafo); glsafe(::glPushMatrix()); - glsafe(::glColor3f(1.0f, 0.f, 0.37f)); - m_clipper->render_cut(); + m_clipper->render_cut({ 1.0f, 0.f, 0.37f, 1.0f }); glsafe(::glPopMatrix()); } @@ -734,8 +726,7 @@ void ModelObjectsClipper::render_cut() const clipper->set_transformation(trafo); glsafe(::glPushMatrix()); // BBS - glsafe(::glColor3f(0.25f, 0.25f, 0.25f)); - clipper->render_cut(); + clipper->render_cut({0.25f, 0.25f, 0.25f, 1.0f}); glsafe(::glPopMatrix()); ++clipper_id; diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp index f4211dfb59..6c42052cd5 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp @@ -4,6 +4,7 @@ #include #include +#include "slic3r/GUI/3DScene.hpp" #include "slic3r/GUI/MeshUtils.hpp" #include "libslic3r/SLA/Hollowing.hpp" diff --git a/src/slic3r/GUI/MeshUtils.cpp b/src/slic3r/GUI/MeshUtils.cpp index cd9a617f4b..64d9be0826 100644 --- a/src/slic3r/GUI/MeshUtils.cpp +++ b/src/slic3r/GUI/MeshUtils.cpp @@ -6,6 +6,7 @@ #include "libslic3r/ClipperUtils.hpp" #include "libslic3r/Model.hpp" +#include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/Camera.hpp" #include @@ -67,13 +68,25 @@ void MeshClipper::set_transformation(const Geometry::Transformation& trafo) -void MeshClipper::render_cut() +void MeshClipper::render_cut(const ColorRGBA& color) { if (! m_triangles_valid) recalculate_triangles(); - if (m_vertex_array.has_VBOs()) - m_vertex_array.render(); + GLShaderProgram* curr_shader = wxGetApp().get_current_shader(); + if (curr_shader != nullptr) + curr_shader->stop_using(); + + GLShaderProgram* shader = wxGetApp().get_shader("flat"); + if (shader != nullptr) { + shader->start_using(); + m_model.set_color(color); + m_model.render(); + shader->stop_using(); + } + + if (curr_shader != nullptr) + curr_shader->start_using(); } bool MeshClipper::is_projection_inside_cut(const Vec3d &point_in) const @@ -189,15 +202,28 @@ void MeshClipper::recalculate_triangles() tr.pretranslate(0.001 * m_plane.get_normal().normalized()); // to avoid z-fighting - m_vertex_array.release_geometry(); - for (auto it=m_triangles2d.cbegin(); it != m_triangles2d.cend(); it=it+3) { - m_vertex_array.push_geometry(tr * Vec3d((*(it+0))(0), (*(it+0))(1), height_mesh), up); - m_vertex_array.push_geometry(tr * Vec3d((*(it+1))(0), (*(it+1))(1), height_mesh), up); - m_vertex_array.push_geometry(tr * Vec3d((*(it+2))(0), (*(it+2))(1), height_mesh), up); + m_model.reset(); + + GLModel::Geometry init_data; + const GLModel::Geometry::EIndexType index_type = (m_triangles2d.size() < 65536) ? GLModel::Geometry::EIndexType::USHORT : GLModel::Geometry::EIndexType::UINT; + init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, index_type }; + init_data.reserve_vertices(m_triangles2d.size()); + init_data.reserve_indices(m_triangles2d.size()); + + // vertices + indices + for (auto it = m_triangles2d.cbegin(); it != m_triangles2d.cend(); it = it + 3) { + init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 0)).x(), (*(it + 0)).y(), height_mesh)).cast(), (Vec3f)up.cast()); + init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 1)).x(), (*(it + 1)).y(), height_mesh)).cast(), (Vec3f)up.cast()); + init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 2)).x(), (*(it + 2)).y(), height_mesh)).cast(), (Vec3f)up.cast()); const size_t idx = it - m_triangles2d.cbegin(); - m_vertex_array.push_triangle(idx, idx+1, idx+2); + if (index_type == GLModel::Geometry::EIndexType::USHORT) + init_data.add_ushort_triangle((unsigned short)idx, (unsigned short)idx + 1, (unsigned short)idx + 2); + else + init_data.add_uint_triangle((unsigned int)idx, (unsigned int)idx + 1, (unsigned int)idx + 2); } - m_vertex_array.finalize_geometry(true); + + if (!init_data.is_empty()) + m_model.init_from(std::move(init_data)); m_triangles_valid = true; } diff --git a/src/slic3r/GUI/MeshUtils.hpp b/src/slic3r/GUI/MeshUtils.hpp index 123b8a7852..db0bf1c0aa 100644 --- a/src/slic3r/GUI/MeshUtils.hpp +++ b/src/slic3r/GUI/MeshUtils.hpp @@ -6,7 +6,7 @@ #include "libslic3r/SLA/IndexedMesh.hpp" #include "admesh/stl.h" -#include "slic3r/GUI/3DScene.hpp" +#include "slic3r/GUI/GLModel.hpp" #include @@ -69,7 +69,8 @@ public: // MeshClipper class cuts a mesh and is able to return a triangulated cut. -class MeshClipper { +class MeshClipper +{ public: // Inform MeshClipper about which plane we want to use to cut the mesh // This is supposed to be in world coordinates. @@ -92,7 +93,7 @@ public: // Render the triangulated cut. Transformation matrices should // be set in world coords. - void render_cut(); + void render_cut(const ColorRGBA& color); bool is_projection_inside_cut(const Vec3d &point) const; bool has_valid_contour() const; @@ -106,7 +107,7 @@ private: ClippingPlane m_plane; ClippingPlane m_limiting_plane = ClippingPlane::ClipsNothing(); std::vector m_triangles2d; - GLIndexedVertexArray m_vertex_array; + GLModel m_model; bool m_triangles_valid = false; struct CutIsland diff --git a/src/slic3r/Utils/UndoRedo.cpp b/src/slic3r/Utils/UndoRedo.cpp index 56a5172ab3..eaf90c7349 100644 --- a/src/slic3r/Utils/UndoRedo.cpp +++ b/src/slic3r/Utils/UndoRedo.cpp @@ -21,6 +21,7 @@ #include #include +#include "slic3r/GUI/3DScene.hpp" #include #ifndef NDEBUG