From dc95440c3d8ae9f9aee7d386ad3b34bfcd994237 Mon Sep 17 00:00:00 2001 From: remi durand Date: Tue, 1 Jun 2021 17:52:58 +0200 Subject: [PATCH] better default grid supermerill/SuperSlicer#1218 --- src/slic3r/GUI/2DBed.cpp | 52 +++++++++++++++++++++++++++++++++------- src/slic3r/GUI/3DBed.cpp | 37 +++++++++++++++++++++++----- src/slic3r/GUI/3DBed.hpp | 2 ++ 3 files changed, 76 insertions(+), 15 deletions(-) diff --git a/src/slic3r/GUI/2DBed.cpp b/src/slic3r/GUI/2DBed.cpp index ea6720356..e2370783e 100644 --- a/src/slic3r/GUI/2DBed.cpp +++ b/src/slic3r/GUI/2DBed.cpp @@ -81,21 +81,55 @@ void Bed_2D::repaint(const std::vector& shape) // draw grid auto step = 10; // 1cm grid Polylines polylines; - for (auto x = bb.min(0) - fmod(bb.min(0), step) + step; x < bb.max(0); x += step) { - polylines.push_back(Polyline::new_scale({ Vec2d(x, bb.min(1)), Vec2d(x, bb.max(1)) })); + Polylines polylines_big; + Polylines polylines_small; + int idx = 1; + for (double x = bb.min(0) - fmod(bb.min(0), step) + step; x < bb.max(0); x += step, ++idx) { + if (idx % 10 == 0) + polylines_big.push_back(Polyline::new_scale({ Vec2d(x, bb.min(1)), Vec2d(x, bb.max(1)) })); + else if (idx % 2 == 1) + polylines_small.push_back(Polyline::new_scale({ Vec2d(x, bb.min(1)), Vec2d(x, bb.max(1)) })); + else + polylines.push_back(Polyline::new_scale({ Vec2d(x, bb.min(1)), Vec2d(x, bb.max(1)) })); } - for (auto y = bb.min(1) - fmod(bb.min(1), step) + step; y < bb.max(1); y += step) { - polylines.push_back(Polyline::new_scale({ Vec2d(bb.min(0), y), Vec2d(bb.max(0), y) })); + idx = 1; + for (double y = bb.min(1) - fmod(bb.min(1), step) + step; y < bb.max(1); y += step, ++idx) { + if (idx % 10 == 0) + polylines_big.push_back(Polyline::new_scale({ Vec2d(bb.min(0), y), Vec2d(bb.max(0), y) })); + else if (idx % 2 == 1) + polylines_small.push_back(Polyline::new_scale({ Vec2d(bb.min(0), y), Vec2d(bb.max(0), y) })); + else + polylines.push_back(Polyline::new_scale({ Vec2d(bb.min(0), y), Vec2d(bb.max(0), y) })); } polylines = intersection_pl(polylines, (Polygons)bed_polygon); + polylines_big = intersection_pl(polylines_big, (Polygons)bed_polygon); + polylines_small = intersection_pl(polylines_small, (Polygons)bed_polygon); - dc.SetPen(wxPen(wxColour(230, 230, 230), 1, wxPENSTYLE_SOLID)); + dc.SetPen(wxPen(wxColour(230, 230, 230), 1, wxPENSTYLE_SOLID)); + for (auto pl : polylines_small) + { + for (size_t i = 0; i < pl.points.size() - 1; i++) { + Point pt1 = to_pixels(unscale(pl.points[i]), ch); + Point pt2 = to_pixels(unscale(pl.points[i + 1]), ch); + dc.DrawLine(pt1(0), pt1(1), pt2(0), pt2(1)); + } + } + dc.SetPen(wxPen(wxColour(230, 230, 230), 2, wxPENSTYLE_SOLID)); for (auto pl : polylines) { - for (size_t i = 0; i < pl.points.size()-1; i++) { - Point pt1 = to_pixels(unscale(pl.points[i]), ch); - Point pt2 = to_pixels(unscale(pl.points[i + 1]), ch); - dc.DrawLine(pt1(0), pt1(1), pt2(0), pt2(1)); + for (size_t i = 0; i < pl.points.size() - 1; i++) { + Point pt1 = to_pixels(unscale(pl.points[i]), ch); + Point pt2 = to_pixels(unscale(pl.points[i + 1]), ch); + dc.DrawLine(pt1(0), pt1(1), pt2(0), pt2(1)); + } + } + dc.SetPen(wxPen(wxColour(230, 230, 230), 3, wxPENSTYLE_SOLID)); + for (auto pl : polylines_big) + { + for (size_t i = 0; i < pl.points.size() - 1; i++) { + Point pt1 = to_pixels(unscale(pl.points[i]), ch); + Point pt2 = to_pixels(unscale(pl.points[i + 1]), ch); + dc.DrawLine(pt1(0), pt1(1), pt2(0), pt2(1)); } } diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index 4277aeb36..6ce0d6770 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -300,21 +300,36 @@ void Bed3D::calc_triangles(const ExPolygon& poly) void Bed3D::calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox) { Polylines axes_lines; - for (coord_t x = bed_bbox.min(0); x <= bed_bbox.max(0); x += scale_(10.0)) { + Polylines axes_lines_big; + Polylines axes_lines_small; + for (coord_t x = bed_bbox.min(0), idx= 0; x <= bed_bbox.max(0); x += scale_(5.0), idx++) { Polyline line; line.append(Point(x, bed_bbox.min(1))); line.append(Point(x, bed_bbox.max(1))); - axes_lines.push_back(line); + if (idx % 10 == 0) + axes_lines_big.push_back(line); + else if(idx%2==1) + axes_lines_small.push_back(line); + else + axes_lines.push_back(line); } - for (coord_t y = bed_bbox.min(1); y <= bed_bbox.max(1); y += scale_(10.0)) { + for (coord_t y = bed_bbox.min(1), idx = 0; y <= bed_bbox.max(1); y += scale_(5.0), idx++) { Polyline line; line.append(Point(bed_bbox.min(0), y)); line.append(Point(bed_bbox.max(0), y)); - axes_lines.push_back(line); + if (idx % 10 == 0) + axes_lines_big.push_back(line); + else if (idx % 2 == 1) + axes_lines_small.push_back(line); + else + axes_lines.push_back(line); } // clip with a slightly grown expolygon because our lines lay on the contours and may get erroneously clipped Lines gridlines = to_lines(intersection_pl(axes_lines, offset(poly, (float)SCALED_EPSILON))); + Lines gridlines_big = to_lines(intersection_pl(axes_lines_big, offset(poly, (float)SCALED_EPSILON))); + Lines gridlines_small = to_lines(intersection_pl(axes_lines_small, offset(poly, (float)SCALED_EPSILON))); + // append bed contours Lines contour_lines = to_lines(poly); @@ -322,6 +337,10 @@ void Bed3D::calc_gridlines(const ExPolygon& poly, const BoundingBox& bed_bbox) if (!m_gridlines.set_from_lines(gridlines, GROUND_Z)) printf("Unable to create bed grid lines\n"); + if (!m_gridlines_big.set_from_lines(gridlines_big, GROUND_Z)) + printf("Unable to create bed grid lines\n"); + if (!m_gridlines_small.set_from_lines(gridlines_small, GROUND_Z)) + printf("Unable to create bed grid lines\n"); } @@ -559,13 +578,19 @@ void Bed3D::render_default(bool bottom) const } // draw grid - glsafe(::glLineWidth(1.5f * m_scale_factor)); if (has_model && !bottom) glsafe(::glColor4f(0.9f, 0.9f, 0.9f, 1.0f)); else glsafe(::glColor4f(0.9f, 0.9f, 0.9f, 0.6f)); - glsafe(::glVertexPointer(3, GL_FLOAT, m_triangles.get_vertex_data_size(), (GLvoid*)m_gridlines.get_vertices_data())); + glsafe(::glLineWidth(0.5f * m_scale_factor)); + glsafe(::glVertexPointer(3, GL_FLOAT, m_gridlines_small.get_vertex_data_size(), (GLvoid*)m_gridlines_small.get_vertices_data())); + glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_gridlines_small.get_vertices_count())); + glsafe(::glLineWidth(1.5f * m_scale_factor)); + glsafe(::glVertexPointer(3, GL_FLOAT, m_gridlines.get_vertex_data_size(), (GLvoid*)m_gridlines.get_vertices_data())); glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_gridlines.get_vertices_count())); + glsafe(::glLineWidth(3.0f * m_scale_factor)); + glsafe(::glVertexPointer(3, GL_FLOAT, m_gridlines_big.get_vertex_data_size(), (GLvoid*)m_gridlines_big.get_vertices_data())); + glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_gridlines_big.get_vertices_count())); glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); diff --git a/src/slic3r/GUI/3DBed.hpp b/src/slic3r/GUI/3DBed.hpp index b5b063e6f..a61cd8374 100644 --- a/src/slic3r/GUI/3DBed.hpp +++ b/src/slic3r/GUI/3DBed.hpp @@ -82,6 +82,8 @@ private: Polygon m_polygon; GeometryBuffer m_triangles; GeometryBuffer m_gridlines; + GeometryBuffer m_gridlines_big; + GeometryBuffer m_gridlines_small; mutable GLTexture m_texture; mutable GLModel m_model; mutable Vec3d m_model_offset{ Vec3d::Zero() };