From 63ce3c3150fcf8bf4d068894857acdce49fbc5c6 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 15 Apr 2019 22:24:10 +0200 Subject: [PATCH] SLA gizmo now does not make redundant copies of the object and supports meshes --- src/libslic3r/SLA/SLASupportTree.cpp | 4 ++++ src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 20 ++++++++++---------- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp | 4 ++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/libslic3r/SLA/SLASupportTree.cpp b/src/libslic3r/SLA/SLASupportTree.cpp index 37a6bae4b..75f9b0140 100644 --- a/src/libslic3r/SLA/SLASupportTree.cpp +++ b/src/libslic3r/SLA/SLASupportTree.cpp @@ -817,6 +817,10 @@ public: meshcache = mesh(merged); + // The mesh will be passed by const-pointer to TriangleMeshSlicer, + // which will need this. + meshcache.require_shared_vertices(); + // TODO: Is this necessary? //meshcache.repair(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index af27c2f9f..2285e2520 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -145,7 +145,7 @@ void GLGizmoSlaSupports::render_clipping_plane(const Selection& selection, const // Now initialize the TMS for the object, perform the cut and save the result. if (! m_tms) { m_tms.reset(new TriangleMeshSlicer); - m_tms->init(const_cast(&m_mesh), [](){}); + m_tms->init(m_mesh, [](){}); } std::vector list_of_expolys; m_tms->set_up_direction(up); @@ -176,10 +176,10 @@ void GLGizmoSlaSupports::render_clipping_plane(const Selection& selection, const if (!m_supports_tms || (int)timestamp != m_old_timestamp) { // The timestamp has changed - stash the mesh and initialize the TMS. - m_supports_mesh = print_object->support_mesh(); + m_supports_mesh = &print_object->support_mesh(); m_supports_tms.reset(new TriangleMeshSlicer); - m_supports_mesh.require_shared_vertices(); // TriangleMeshSlicer needs this - m_supports_tms->init(const_cast(&m_supports_mesh), [](){}); + // The mesh should already have the shared vertices calculated. + m_supports_tms->init(m_supports_mesh, [](){}); m_old_timestamp = timestamp; } @@ -410,10 +410,12 @@ void GLGizmoSlaSupports::update_mesh() wxBusyCursor wait; Eigen::MatrixXf& V = m_V; Eigen::MatrixXi& F = m_F; + // We rely on SLA model object having a single volume, + // this way we can use that mesh directly. // This mesh does not account for the possible Z up SLA offset. - m_mesh = m_model_object->raw_mesh(); - m_mesh.require_shared_vertices(); // TriangleMeshSlicer needs this - const stl_file& stl = m_mesh.stl; + m_mesh = &m_model_object->volumes.front()->mesh; + const_cast(m_mesh)->require_shared_vertices(); // TriangleMeshSlicer needs this + const stl_file& stl = m_mesh->stl; V.resize(3 * stl.stats.number_of_facets, 3); F.resize(stl.stats.number_of_facets, 3); for (unsigned int i=0; i m_AABB; - TriangleMesh m_mesh; - mutable TriangleMesh m_supports_mesh; + const TriangleMesh* m_mesh; + mutable const TriangleMesh* m_supports_mesh; mutable std::vector m_triangles; mutable std::vector m_supports_triangles; mutable int m_old_timestamp = -1;