diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 30614100f..12e61d7f3 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -232,6 +232,7 @@ add_library(libslic3r STATIC SLA/Contour3D.cpp SLA/EigenMesh3D.hpp SLA/Clustering.hpp + SLA/ReprojectPointsOnMesh.hpp ) if (SLIC3R_STATIC) diff --git a/src/libslic3r/SLA/ReprojectPointsOnMesh.hpp b/src/libslic3r/SLA/ReprojectPointsOnMesh.hpp new file mode 100644 index 000000000..fa919a117 --- /dev/null +++ b/src/libslic3r/SLA/ReprojectPointsOnMesh.hpp @@ -0,0 +1,45 @@ +#ifndef REPROJECTPOINTSONMESH_HPP +#define REPROJECTPOINTSONMESH_HPP + +#include "libslic3r/Point.hpp" +#include "SupportPoint.hpp" +#include "Hollowing.hpp" +#include "EigenMesh3D.hpp" +#include "libslic3r/Model.hpp" + +#include + +namespace Slic3r { namespace sla { + +template Vec3d pos(const Pt &p) { return p.pos.template cast(); } +template void pos(Pt &p, const Vec3d &pp) { p.pos = pp.cast(); } + +template +void reproject_support_points(const EigenMesh3D &mesh, std::vector &pts) +{ + tbb::parallel_for(size_t(0), pts.size(), [&mesh, &pts](size_t idx) { + int junk; + Vec3d new_pos; + mesh.squared_distance(pos(pts[idx]), junk, new_pos); + pos(pts[idx], new_pos); + }); +} + +inline void reproject_points_and_holes(ModelObject *object) +{ + bool has_sppoints = !object->sla_support_points.empty(); + bool has_holes = !object->sla_drain_holes.empty(); + + if (!object || (!has_holes && !has_sppoints)) return; + + EigenMesh3D emesh{object->raw_mesh()}; + + if (has_sppoints) + reproject_support_points(emesh, object->sla_support_points); + + if (has_holes) + reproject_support_points(emesh, object->sla_drain_holes); +} + +}} +#endif // REPROJECTPOINTSONMESH_HPP diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 7fd8ec09d..ca91967e1 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -38,6 +38,7 @@ #include "libslic3r/Model.hpp" #include "libslic3r/SLA/Hollowing.hpp" #include "libslic3r/SLA/SupportPoint.hpp" +#include "libslic3r/SLA/ReprojectPointsOnMesh.hpp" #include "libslic3r/Polygon.hpp" #include "libslic3r/Print.hpp" #include "libslic3r/PrintConfig.hpp" @@ -3122,6 +3123,8 @@ void Plater::priv::reload_from_disk() std::swap(old_model_object->volumes[sel_v.volume_idx], old_model_object->volumes.back()); old_model_object->delete_volume(old_model_object->volumes.size() - 1); old_model_object->ensure_on_bed(); + + sla::reproject_points_and_holes(old_model_object); } } } @@ -3177,6 +3180,7 @@ void Plater::priv::fix_through_netfabb(const int obj_idx, const int vol_idx/* = Plater::TakeSnapshot snapshot(q, _L("Fix Throught NetFabb")); fix_model_by_win10_sdk_gui(*model.objects[obj_idx], vol_idx); + sla::reproject_points_and_holes(model.objects[obj_idx]); this->update(); this->object_list_changed(); this->schedule_background_process();