diff --git a/src/libslic3r/SLA/Hollowing.cpp b/src/libslic3r/SLA/Hollowing.cpp index 1ce0c4c67..ecc42b889 100644 --- a/src/libslic3r/SLA/Hollowing.cpp +++ b/src/libslic3r/SLA/Hollowing.cpp @@ -123,6 +123,7 @@ Contour3D DrainHole::to_mesh() const Eigen::Quaterniond q; q.setFromTwoVectors(Vec3d{0., 0., 1.}, normal.cast()); for(auto& p : hole.points) p = q * p + pos.cast(); + return hole; } @@ -251,15 +252,8 @@ void cut_drainholes(std::vector & obj_slices, std::function thr) { TriangleMesh mesh; - for (const sla::DrainHole &holept : holes) { - auto r = double(holept.radius); - auto h = double(holept.height); - sla::Contour3D hole = sla::cylinder(r, h); - Eigen::Quaterniond q; - q.setFromTwoVectors(Vec3d{0., 0., 1.}, holept.normal.cast()); - for(auto& p : hole.points) p = q * p + holept.pos.cast(); - mesh.merge(sla::to_triangle_mesh(hole)); - } + for (const sla::DrainHole &holept : holes) + mesh.merge(sla::to_triangle_mesh(holept.to_mesh())); if (mesh.empty()) return; diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 4d34c09c7..4c10a44fa 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -1119,6 +1119,10 @@ TriangleMesh SLAPrintObject::get_mesh(SLAPrintObjectStep step) const return this->support_mesh(); case slaposPad: return this->pad_mesh(); + case slaposHollowing: + if (m_hollowing_data) + return m_hollowing_data->hollow_mesh_with_holes; + [[fallthrough]]; default: return TriangleMesh(); } @@ -1182,11 +1186,18 @@ sla::DrainHoles SLAPrintObject::transformed_drainhole_points() const assert(m_model_object != nullptr); auto pts = m_model_object->sla_drain_holes; auto tr = trafo().cast(); + auto sc = m_model_object->instances.front()->get_scaling_factor().cast(); for (sla::DrainHole &hl : pts) { hl.pos = tr * hl.pos; hl.normal = tr * hl.normal - tr.translation(); + + // The normal scales as a covector (and we must also + // undo the damage already done). + hl.normal = Vec3f(hl.normal(0)/(sc(0)*sc(0)), + hl.normal(1)/(sc(1)*sc(1)), + hl.normal(2)/(sc(2)*sc(2))); } - + return pts; } diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index 1b8e18a2a..771ca0bcd 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -80,6 +80,12 @@ public: // Ready after this->is_step_done(slaposHollowing) is true const TriangleMesh& hollowed_interior_mesh() const; + + // 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 { + return m_hollowing_data ? m_hollowing_data->hollow_mesh_with_holes : transformed_mesh(); + } // This will return the transformed mesh which is cached const TriangleMesh& transformed_mesh() const; @@ -318,7 +324,7 @@ private: public: TriangleMesh interior; - // std::vector + mutable TriangleMesh hollow_mesh_with_holes; // caching the complete hollowed mesh }; std::unique_ptr m_hollowing_data; diff --git a/src/libslic3r/SLAPrintSteps.cpp b/src/libslic3r/SLAPrintSteps.cpp index 0ae0e66a4..f781814ae 100644 --- a/src/libslic3r/SLAPrintSteps.cpp +++ b/src/libslic3r/SLAPrintSteps.cpp @@ -1,5 +1,5 @@ #include - +#include // Need the cylinder method for the the drainholes in hollowing step #include @@ -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,26 +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!"; } // The slicing will be performed on an imaginary 1D grid which starts from @@ -111,18 +141,8 @@ void SLAPrint::Steps::hollow_model(SLAPrintObject &po) // same imaginary grid (the height vector argument to TriangleMeshSlicer). void SLAPrint::Steps::slice_model(SLAPrintObject &po) { - TriangleMesh hollowed_mesh; - - bool is_hollowing = po.m_config.hollowing_enable.getBool() && po.m_hollowing_data; - - if (is_hollowing) { - hollowed_mesh = po.transformed_mesh(); - hollowed_mesh.merge(po.m_hollowing_data->interior); - hollowed_mesh.require_shared_vertices(); - } - - const TriangleMesh &mesh = is_hollowing ? hollowed_mesh : po.transformed_mesh(); - + const TriangleMesh &mesh = po.get_mesh_to_print(); + // We need to prepare the slice index... double lhd = m_print->m_objects.front()->m_config.layer_height.getFloat(); @@ -168,8 +188,8 @@ void SLAPrint::Steps::slice_model(SLAPrintObject &po) auto &slice_grid = po.m_model_height_levels; slicer.slice(slice_grid, closing_r, &po.m_model_slices, thr); - sla::DrainHoles drainholes = po.transformed_drainhole_points(); - cut_drainholes(po.m_model_slices, slice_grid, closing_r, drainholes, thr); +// sla::DrainHoles drainholes = po.transformed_drainhole_points(); +// cut_drainholes(po.m_model_slices, slice_grid, closing_r, drainholes, thr); auto mit = slindex_it; double doffs = m_print->m_printer_config.absolute_correction.getFloat(); @@ -199,16 +219,7 @@ void SLAPrint::Steps::support_points(SLAPrintObject &po) // If supports are disabled, we can skip the model scan. if(!po.m_config.supports_enable.getBool()) return; - bool is_hollowing = po.m_config.hollowing_enable.getBool() && po.m_hollowing_data; - - TriangleMesh hollowed_mesh; - if (is_hollowing) { - hollowed_mesh = po.transformed_mesh(); - hollowed_mesh.merge(po.m_hollowing_data->interior); - hollowed_mesh.require_shared_vertices(); - } - - const TriangleMesh &mesh = is_hollowing ? hollowed_mesh : po.transformed_mesh(); + const TriangleMesh &mesh = po.get_mesh_to_print(); if (!po.m_supportdata) po.m_supportdata.reset(new SLAPrintObject::SupportData(mesh)); @@ -229,7 +240,7 @@ void SLAPrint::Steps::support_points(SLAPrintObject &po) // Tell the mesh where drain holes are. Although the points are // calculated on slices, the algorithm then raycasts the points // so they actually lie on the mesh. - po.m_supportdata->emesh.load_holes(po.transformed_drainhole_points()); +// po.m_supportdata->emesh.load_holes(po.transformed_drainhole_points()); throw_if_canceled(); sla::SupportPointGenerator::Config config; @@ -298,7 +309,7 @@ void SLAPrint::Steps::support_tree(SLAPrintObject &po) po.m_supportdata->emesh.ground_level_offset(pcfg.wall_thickness_mm); po.m_supportdata->cfg = make_support_cfg(po.m_config); - po.m_supportdata->emesh.load_holes(po.transformed_drainhole_points()); +// po.m_supportdata->emesh.load_holes(po.transformed_drainhole_points()); // scaling for the sub operations double d = objectstep_scale * OBJ_STEP_LEVELS[slaposSupportTree] / 100.0; diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 2e90a87ee..8805dc92c 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -6060,9 +6060,9 @@ void GLCanvas3D::_load_sla_shells() if (obj->is_step_done(slaposSliceSupports)) { unsigned int initial_volumes_count = (unsigned int)m_volumes.volumes.size(); for (const SLAPrintObject::Instance& instance : obj->instances()) { - add_volume(*obj, 0, instance, obj->transformed_mesh(), GLVolume::MODEL_COLOR[0], true); - if (! obj->hollowed_interior_mesh().empty()) - add_volume(*obj, -int(slaposHollowing), instance, obj->hollowed_interior_mesh(), GLVolume::MODEL_COLOR[0], false); + add_volume(*obj, 0, instance, obj->get_mesh_to_print(), GLVolume::MODEL_COLOR[0], true); +// if (! obj->hollowed_interior_mesh().empty()) +// add_volume(*obj, -int(slaposHollowing), instance, obj->hollowed_interior_mesh(), GLVolume::MODEL_COLOR[0], false); // Set the extruder_id and volume_id to achieve the same color as in the 3D scene when // through the update_volumes_colors_by_extruder() call. m_volumes.volumes.back()->extruder_id = obj->model_object()->volumes.front()->extruder_id(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp index d02fdd077..042298274 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp @@ -608,10 +608,14 @@ void GLGizmoHollow::update_mesh_raycaster(std::unique_ptr &&rc) m_c->m_volume_with_cavity.reset(); } -void GLGizmoHollow::hollow_mesh() +void GLGizmoHollow::hollow_mesh(bool postpone_error_messages) { // Trigger a UI job to hollow the mesh. - wxGetApp().plater()->hollow(); + // wxGetApp().plater()->hollow(); + + wxGetApp().CallAfter([this, postpone_error_messages]() { + wxGetApp().plater()->reslice_SLA_hollowing(*m_c->m_model_object, postpone_error_messages); + }); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp index f6560c861..79b0a6929 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp @@ -55,7 +55,7 @@ private: void render_hollowed_mesh() const; bool is_mesh_update_necessary() const; void update_mesh(); - void hollow_mesh(); + void hollow_mesh(bool postpone_error_messages = false); bool unsaved_changes() const; bool m_show_supports = true; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 6d869baaa..37ea24a16 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -5099,6 +5099,16 @@ void Plater::reslice() } void Plater::reslice_SLA_supports(const ModelObject &object, bool postpone_error_messages) +{ + reslice_SLA_until_step(slaposPad, object, postpone_error_messages); +} + +void Plater::reslice_SLA_hollowing(const ModelObject &object, bool postpone_error_messages) +{ + reslice_SLA_until_step(slaposHollowing, object, postpone_error_messages); +} + +void Plater::reslice_SLA_until_step(SLAPrintObjectStep step, const ModelObject &object, bool postpone_error_messages) { //FIXME Don't reslice if export of G-code or sending to OctoPrint is running. // bitmask of UpdateBackgroundProcessReturnState @@ -5117,7 +5127,7 @@ void Plater::reslice_SLA_supports(const ModelObject &object, bool postpone_error // Otherwise calculate everything, but start with the provided object. if (!this->p->background_processing_enabled()) { task.single_model_instance_only = true; - task.to_object_step = slaposPad; + task.to_object_step = step; } this->p->background_process.set_task(task); // and let the background processing start. diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index c03813a9c..9639a1693 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -26,6 +26,7 @@ class Model; class ModelObject; class Print; class SLAPrint; +enum SLAPrintObjectStep : unsigned int; namespace UndoRedo { class Stack; @@ -197,6 +198,8 @@ public: void hollow(); void reslice(); void reslice_SLA_supports(const ModelObject &object, bool postpone_error_messages = false); + void reslice_SLA_hollowing(const ModelObject &object, bool postpone_error_messages = false); + void reslice_SLA_until_step(SLAPrintObjectStep step, const ModelObject &object, bool postpone_error_messages = false); void changed_object(int obj_idx); void changed_objects(const std::vector& object_idxs); void schedule_background_process(bool schedule = true);