From 022cc0871a0b8ce43d82a93e115d58f7a13990d3 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 22 Jan 2020 17:26:13 +0100 Subject: [PATCH] Allowed to do drilling without hollowing --- src/libslic3r/SLAPrint.hpp | 3 +- src/libslic3r/SLAPrintSteps.cpp | 85 +++++++++++++++++++-------------- 2 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index 20580772b..771ca0bcd 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -84,8 +84,7 @@ public: // Get the mesh that is going to be printed with all the modifications // like hollowing and drilled holes. const TriangleMesh & get_mesh_to_print() const { - bool is_hollowing = m_config.hollowing_enable.getBool() && m_hollowing_data; - return is_hollowing ? m_hollowing_data->hollow_mesh_with_holes : transformed_mesh(); + return m_hollowing_data ? m_hollowing_data->hollow_mesh_with_holes : transformed_mesh(); } // This will return the transformed mesh which is cached diff --git a/src/libslic3r/SLAPrintSteps.cpp b/src/libslic3r/SLAPrintSteps.cpp index e94110cf6..f781814ae 100644 --- a/src/libslic3r/SLAPrintSteps.cpp +++ b/src/libslic3r/SLAPrintSteps.cpp @@ -38,7 +38,7 @@ const std::array OBJ_STEP_LEVELS = { std::string OBJ_STEP_LABELS(size_t idx) { switch (idx) { - case slaposHollowing: return L("Hollowing out the model"); + case slaposHollowing: return L("Hollowing and drilling holes"); case slaposObjectSlice: return L("Slicing model"); case slaposDrillHolesIfHollowed: return L("Drilling holes into hollowed model."); case slaposSupportPoints: return L("Generating support points"); @@ -79,43 +79,56 @@ SLAPrint::Steps::Steps(SLAPrint *print) void SLAPrint::Steps::hollow_model(SLAPrintObject &po) { - if (!po.m_config.hollowing_enable.getBool()) { - BOOST_LOG_TRIVIAL(info) << "Skipping hollowing step!"; - po.m_hollowing_data.reset(); - return; - } else { + po.m_hollowing_data.reset(); + if (! po.m_config.hollowing_enable.getBool()) + BOOST_LOG_TRIVIAL(info) << "Skipping hollowing step!"; + else { BOOST_LOG_TRIVIAL(info) << "Performing hollowing step!"; + + double thickness = po.m_config.hollowing_min_thickness.getFloat(); + double quality = po.m_config.hollowing_quality.getFloat(); + double closing_d = po.m_config.hollowing_closing_distance.getFloat(); + sla::HollowingConfig hlwcfg{thickness, quality, closing_d}; + auto meshptr = generate_interior(po.transformed_mesh(), hlwcfg); + + if (meshptr->empty()) + BOOST_LOG_TRIVIAL(warning) << "Hollowed interior is empty!"; + else { + po.m_hollowing_data.reset(new SLAPrintObject::HollowingData()); + po.m_hollowing_data->interior = *meshptr; + auto &hollowed_mesh = po.m_hollowing_data->hollow_mesh_with_holes; + hollowed_mesh = po.transformed_mesh(); + hollowed_mesh.merge(po.m_hollowing_data->interior); + hollowed_mesh.require_shared_vertices(); + } + } + + // Drill holes into the hollowed/original mesh. + if (po.m_model_object->sla_drain_holes.empty()) + BOOST_LOG_TRIVIAL(info) << "Drilling skipped (no holes)."; + else { + BOOST_LOG_TRIVIAL(info) << "Drilling drainage holes."; + sla::DrainHoles drainholes = po.transformed_drainhole_points(); + + TriangleMesh holes_mesh; + + for (const sla::DrainHole &holept : drainholes) + holes_mesh.merge(sla::to_triangle_mesh(holept.to_mesh())); + + holes_mesh.require_shared_vertices(); + MeshBoolean::self_union(holes_mesh); //FIXME-fix and use the cgal version + + // If there is no hollowed mesh yet, copy the original mesh. + if (! po.m_hollowing_data) { + po.m_hollowing_data.reset(new SLAPrintObject::HollowingData()); + po.m_hollowing_data->hollow_mesh_with_holes = po.transformed_mesh(); + } + + TriangleMesh &hollowed_mesh = po.m_hollowing_data->hollow_mesh_with_holes; + hollowed_mesh = po.get_mesh_to_print(); + MeshBoolean::cgal::minus(hollowed_mesh, holes_mesh); + hollowed_mesh.require_shared_vertices(); } - - if (!po.m_hollowing_data) - po.m_hollowing_data.reset(new SLAPrintObject::HollowingData()); - - double thickness = po.m_config.hollowing_min_thickness.getFloat(); - double quality = po.m_config.hollowing_quality.getFloat(); - double closing_d = po.m_config.hollowing_closing_distance.getFloat(); - sla::HollowingConfig hlwcfg{thickness, quality, closing_d}; - auto meshptr = generate_interior(po.transformed_mesh(), hlwcfg); - if (meshptr) po.m_hollowing_data->interior = *meshptr; - - if (po.m_hollowing_data->interior.empty()) - BOOST_LOG_TRIVIAL(warning) << "Hollowed interior is empty!"; - - auto &hollowed_mesh = po.m_hollowing_data->hollow_mesh_with_holes; - hollowed_mesh = po.transformed_mesh(); - hollowed_mesh.merge(po.m_hollowing_data->interior); - hollowed_mesh.require_shared_vertices(); - - sla::DrainHoles drainholes = po.transformed_drainhole_points(); - - TriangleMesh holes_mesh; - - for (const sla::DrainHole &holept : drainholes) - holes_mesh.merge(sla::to_triangle_mesh(holept.to_mesh())); - - holes_mesh.require_shared_vertices(); - MeshBoolean::minus(hollowed_mesh, holes_mesh); - - hollowed_mesh.require_shared_vertices(); } // The slicing will be performed on an imaginary 1D grid which starts from