From f7a43f9757b4300aca5f62261e524ba52c013c05 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 12 May 2020 15:52:33 +0200 Subject: [PATCH 1/6] Reproject support and hole points after a reload from disk op. --- src/libslic3r/CMakeLists.txt | 1 + src/libslic3r/SLA/ReprojectPointsOnMesh.hpp | 28 +++++++++++++++++++++ src/slic3r/GUI/Plater.cpp | 12 +++++++++ 3 files changed, 41 insertions(+) create mode 100644 src/libslic3r/SLA/ReprojectPointsOnMesh.hpp 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..1479eb430 --- /dev/null +++ b/src/libslic3r/SLA/ReprojectPointsOnMesh.hpp @@ -0,0 +1,28 @@ +#ifndef REPROJECTPOINTSONMESH_HPP +#define REPROJECTPOINTSONMESH_HPP + +#include "libslic3r/Point.hpp" +#include "SupportPoint.hpp" +#include "Hollowing.hpp" +#include "EigenMesh3D.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); + }); +} + +}} +#endif // REPROJECTPOINTSONMESH_HPP diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 7fd8ec09d..2ef7417d4 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,17 @@ 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(); + + std::unique_ptr emesh; + if (!old_model_object->sla_support_points.empty()) { + emesh = std::make_unique(old_model_object->raw_mesh()); + sla::reproject_support_points(*emesh, old_model_object->sla_support_points); + } + + if (!old_model_object->sla_drain_holes.empty()) { + if (!emesh) emesh = std::make_unique(old_model_object->raw_mesh()); + sla::reproject_support_points(*emesh, old_model_object->sla_drain_holes); + } } } } From f91c27b2ffefbdd57b2aac9d233218b952701c3f Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Wed, 13 May 2020 14:53:05 +0200 Subject: [PATCH 2/6] Do reprojection also after netfabb repair --- src/libslic3r/SLA/ReprojectPointsOnMesh.hpp | 17 +++++++++++++++++ src/slic3r/GUI/Plater.cpp | 12 ++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/libslic3r/SLA/ReprojectPointsOnMesh.hpp b/src/libslic3r/SLA/ReprojectPointsOnMesh.hpp index 1479eb430..fa919a117 100644 --- a/src/libslic3r/SLA/ReprojectPointsOnMesh.hpp +++ b/src/libslic3r/SLA/ReprojectPointsOnMesh.hpp @@ -5,6 +5,7 @@ #include "SupportPoint.hpp" #include "Hollowing.hpp" #include "EigenMesh3D.hpp" +#include "libslic3r/Model.hpp" #include @@ -24,5 +25,21 @@ void reproject_support_points(const EigenMesh3D &mesh, std::vector &p }); } +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 2ef7417d4..ca91967e1 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3124,16 +3124,7 @@ void Plater::priv::reload_from_disk() old_model_object->delete_volume(old_model_object->volumes.size() - 1); old_model_object->ensure_on_bed(); - std::unique_ptr emesh; - if (!old_model_object->sla_support_points.empty()) { - emesh = std::make_unique(old_model_object->raw_mesh()); - sla::reproject_support_points(*emesh, old_model_object->sla_support_points); - } - - if (!old_model_object->sla_drain_holes.empty()) { - if (!emesh) emesh = std::make_unique(old_model_object->raw_mesh()); - sla::reproject_support_points(*emesh, old_model_object->sla_drain_holes); - } + sla::reproject_points_and_holes(old_model_object); } } } @@ -3189,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(); From 2d3a218a07567c8378c8fa73424429d4e92b77ea Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 14 May 2020 09:50:53 +0200 Subject: [PATCH 3/6] Change pch to new CMake functions --- src/libslic3r/CMakeLists.txt | 3 ++- src/slic3r/CMakeLists.txt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 12e61d7f3..ae9087ed4 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -308,5 +308,6 @@ if(SLIC3R_PROFILE) endif() if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY) - add_precompiled_header(libslic3r pchheader.hpp FORCEINCLUDE) + #add_precompiled_header(libslic3r pchheader.hpp FORCEINCLUDE) + target_precompile_headers(libslic3r PRIVATE pchheader.hpp) endif () diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index ac6961990..a110a82ed 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -231,5 +231,6 @@ if (SLIC3R_STATIC AND UNIX AND NOT APPLE) endif () if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY) - add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE) + #add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE) + target_precompile_headers(libslic3r_gui PRIVATE pchheader.hpp) endif () From 63c82ed8c60e0bd3694c48df2fdba4e2b3ef711e Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 14 May 2020 10:10:47 +0200 Subject: [PATCH 4/6] Modify PCH script to use builtin cmake function if possible. --- cmake/modules/PrecompiledHeader.cmake | 15 +++++++++++++++ src/libslic3r/CMakeLists.txt | 3 +-- src/slic3r/CMakeLists.txt | 3 +-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cmake/modules/PrecompiledHeader.cmake b/cmake/modules/PrecompiledHeader.cmake index 2f62a7dbe..e5f01af21 100644 --- a/cmake/modules/PrecompiledHeader.cmake +++ b/cmake/modules/PrecompiledHeader.cmake @@ -101,7 +101,14 @@ function(export_all_flags _filename) file(GENERATE OUTPUT "${_filename}" CONTENT "${_compile_definitions}${_include_directories}${_compile_flags}${_compile_options}${_cxx_flags}\n") endfunction() +# Use the new builtin CMake function if possible or fall back to the old one. +if (CMAKE_VERSION VERSION_LESS 3.16) + function(add_precompiled_header _target _input) + + message(STATUS "Adding precompiled header ${_input} to target ${_target} with legacy method. " + "Update your cmake instance to use the native PCH functions.") + cmake_parse_arguments(_PCH "FORCEINCLUDE" "SOURCE_CXX;SOURCE_C" "" ${ARGN}) get_filename_component(_input_we ${_input} NAME_WE) @@ -241,3 +248,11 @@ function(add_precompiled_header _target _input) endforeach() endif(CMAKE_COMPILER_IS_GNUCXX) endfunction() + +else () + +function(add_precompiled_header _target _input) + target_precompile_headers(${_target} PRIVATE ${_input}) +endfunction() + +endif (CMAKE_VERSION VERSION_LESS 3.16) diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index ae9087ed4..12e61d7f3 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -308,6 +308,5 @@ if(SLIC3R_PROFILE) endif() if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY) - #add_precompiled_header(libslic3r pchheader.hpp FORCEINCLUDE) - target_precompile_headers(libslic3r PRIVATE pchheader.hpp) + add_precompiled_header(libslic3r pchheader.hpp FORCEINCLUDE) endif () diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index a110a82ed..ac6961990 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -231,6 +231,5 @@ if (SLIC3R_STATIC AND UNIX AND NOT APPLE) endif () if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY) - #add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE) - target_precompile_headers(libslic3r_gui PRIVATE pchheader.hpp) + add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE) endif () From 2c3ec346ceb771191b7388fb6e5438079fedf850 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 14 May 2020 13:37:06 +0200 Subject: [PATCH 5/6] Exclude *.m and *.mm Objective-C sources from including pch --- cmake/modules/PrecompiledHeader.cmake | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cmake/modules/PrecompiledHeader.cmake b/cmake/modules/PrecompiledHeader.cmake index e5f01af21..7ef80aacf 100644 --- a/cmake/modules/PrecompiledHeader.cmake +++ b/cmake/modules/PrecompiledHeader.cmake @@ -52,6 +52,10 @@ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. + +# Use the new builtin CMake function if possible or fall back to the old one. +if (CMAKE_VERSION VERSION_LESS 3.16) + include(CMakeParseArguments) macro(combine_arguments _variable) @@ -101,9 +105,6 @@ function(export_all_flags _filename) file(GENERATE OUTPUT "${_filename}" CONTENT "${_compile_definitions}${_include_directories}${_compile_flags}${_compile_options}${_cxx_flags}\n") endfunction() -# Use the new builtin CMake function if possible or fall back to the old one. -if (CMAKE_VERSION VERSION_LESS 3.16) - function(add_precompiled_header _target _input) message(STATUS "Adding precompiled header ${_input} to target ${_target} with legacy method. " @@ -252,7 +253,17 @@ endfunction() else () function(add_precompiled_header _target _input) + message(STATUS "Adding precompiled header ${_input} to target ${_target}.") target_precompile_headers(${_target} PRIVATE ${_input}) + + get_target_property(_sources ${_target} SOURCES) + list(FILTER _sources INCLUDE REGEX ".*\\.mm?") + + if (_sources) + message(STATUS "PCH skipping sources: ${_sources}") + endif () + + set_source_files_properties(${_sources} PROPERTIES SKIP_PRECOMPILE_HEADERS ON) endfunction() endif (CMAKE_VERSION VERSION_LESS 3.16) From ee639a4710d88fe719031e7106d2346e18ebba44 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Thu, 14 May 2020 14:17:20 +0200 Subject: [PATCH 6/6] FDM supports gizmo: do not disable slope visualizer when it should stay on --- src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp index a75eed12c..b85fe57f0 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp @@ -756,8 +756,11 @@ void GLGizmoFdmSupports::on_set_state() } if (m_state == Off && m_old_state != Off) { // the gizmo was just turned Off // we are actually shutting down - m_setting_angle = false; - m_parent.use_slope(false); + if (m_setting_angle) { + m_setting_angle = false; + m_parent.use_slope(false); + } + wxGetApp().plater()->leave_gizmos_stack(); { Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("FDM gizmo turned off")));