From 93ce0d23b75881e8fd7cf71df4ff3a885d54b6af Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 14 Aug 2018 13:08:49 +0200 Subject: [PATCH] Simple attempt to smooth the lay flat triangles --- xs/src/slic3r/GUI/GLCanvas3D.cpp | 41 +++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index f1bbba934..45260544d 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -2209,14 +2209,49 @@ void GLCanvas3D::update_gizmos_data() TriangleMesh ch = model_object->mesh().convex_hull3d(); stl_facet* facet_ptr = ch.stl.facet_start; std::vector points; + const unsigned int k = 20; + const float ratio = 0.2f; + const unsigned int N = 3; // 3 - triangle + while (facet_ptr < ch.stl.facet_start+ch.stl.stats.number_of_facets) { Pointf3 a = Pointf3(facet_ptr->vertex[1].x - facet_ptr->vertex[0].x, facet_ptr->vertex[1].y - facet_ptr->vertex[0].y, facet_ptr->vertex[1].z - facet_ptr->vertex[0].z); Pointf3 b = Pointf3(facet_ptr->vertex[2].x - facet_ptr->vertex[0].x, facet_ptr->vertex[2].y - facet_ptr->vertex[0].y, facet_ptr->vertex[2].z - facet_ptr->vertex[0].z); + if (0.5 * sqrt(dot(cross(a, b), cross(a,b))) > 50.f) { - points.emplace_back(Pointf3s()); - for (unsigned int j=0; j<3; ++j) - points.back().emplace_back(Pointf3(facet_ptr->vertex[j].x, facet_ptr->vertex[j].y, facet_ptr->vertex[j].z)); + points.emplace_back(Pointf3s(2*k*N)); + + std::vector> neighbours; + if (k != 0) { + for (unsigned int j=0; jvertex[j].x, facet_ptr->vertex[j].y, facet_ptr->vertex[j].z); + neighbours.push_back(std::make_pair((int)(j*2*k-k) < 0 ? (N-1)*2*k+k : j*2*k-k, j*2*k+k)); + } + + for (unsigned int i=0; ivertex[j].x, facet_ptr->vertex[j].y, facet_ptr->vertex[j].z)); + points.back().emplace_back(Pointf3(facet_ptr->normal.x, facet_ptr->normal.y, facet_ptr->normal.z)); } facet_ptr+=1;