From 3ab20de3c032069199a70ca5af3f1656cbac210f Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Thu, 8 Jun 2023 09:20:46 +0200 Subject: [PATCH 1/6] Wipe tower: Use perimeter_speed and infill_speed instead of the hardcoded values --- src/libslic3r/GCode/WipeTower.cpp | 19 +++++++++++++++---- src/libslic3r/GCode/WipeTower.hpp | 8 +++++++- src/libslic3r/Print.cpp | 2 +- src/libslic3r/PrintObject.cpp | 6 +++--- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index fa97b848ce..490df98068 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -516,7 +516,7 @@ WipeTower::ToolChangeResult WipeTower::construct_tcr(WipeTowerWriter& writer, -WipeTower::WipeTower(const PrintConfig& config, const std::vector>& wiping_matrix, size_t initial_tool) : +WipeTower::WipeTower(const PrintConfig& config, const PrintRegionConfig& default_region_config, const std::vector>& wiping_matrix, size_t initial_tool) : m_semm(config.single_extruder_multi_material.value), m_wipe_tower_pos(config.wipe_tower_x, config.wipe_tower_y), m_wipe_tower_width(float(config.wipe_tower_width)), @@ -530,6 +530,8 @@ WipeTower::WipeTower(const PrintConfig& config, const std::vectordepth - m_layer_info->toolchanges_depth(); box_coordinates fill_box(Vec2f(m_perimeter_width, m_layer_info->depth-(current_depth-m_perimeter_width)), m_wipe_tower_width - 2 * m_perimeter_width, current_depth-m_perimeter_width); @@ -1203,7 +1212,7 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() // First generate vector of annotated point which form the boundary. std::vector> pts = {{wt_box.ru, Corner}}; if (double alpha_start = std::asin((0.5*w)/r); ! std::isnan(alpha_start) && r > 0.5*w+0.01) { - for (double alpha = alpha_start; alpha < M_PI-alpha_start+0.001; alpha+=(M_PI-2*alpha_start) / 20.) + for (double alpha = alpha_start; alpha < M_PI-alpha_start+0.001; alpha+=(M_PI-2*alpha_start) / 40.) pts.emplace_back(Vec2f(center.x() + r*std::cos(alpha)/support_scale, center.y() + r*std::sin(alpha)), alpha == alpha_start ? ArcStart : Arc); pts.back().second = ArcEnd; } @@ -1285,6 +1294,8 @@ WipeTower::ToolChangeResult WipeTower::finish_layer() return poly; }; + feedrate = first_layer ? m_first_layer_speed * 60.f : m_perimeter_speed * 60.f; + // outer contour (always) bool infill_cone = first_layer && m_wipe_tower_width > 2*spacing && m_wipe_tower_depth > 2*spacing; Polygon poly = supported_rectangle(wt_box, feedrate, infill_cone); diff --git a/src/libslic3r/GCode/WipeTower.hpp b/src/libslic3r/GCode/WipeTower.hpp index 969da848d0..301cd3bec0 100644 --- a/src/libslic3r/GCode/WipeTower.hpp +++ b/src/libslic3r/GCode/WipeTower.hpp @@ -14,6 +14,7 @@ namespace Slic3r class WipeTowerWriter; class PrintConfig; +class PrintRegionConfig; enum GCodeFlavor : unsigned char; @@ -129,7 +130,10 @@ public: // y -- y coordinates of wipe tower in mm ( left bottom corner ) // width -- width of wipe tower in mm ( default 60 mm - leave as it is ) // wipe_area -- space available for one toolchange in mm - WipeTower(const PrintConfig& config, const std::vector>& wiping_matrix, size_t initial_tool); + WipeTower(const PrintConfig& config, + const PrintRegionConfig& default_region_config, + const std::vector>& wiping_matrix, + size_t initial_tool); // Set the extruder properties. @@ -269,6 +273,8 @@ private: size_t m_max_color_changes = 0; // Maximum number of color changes per layer. int m_old_temperature = -1; // To keep track of what was the last temp that we set (so we don't issue the command when not neccessary) float m_travel_speed = 0.f; + float m_infill_speed = 0.f; + float m_perimeter_speed = 0.f; float m_first_layer_speed = 0.f; size_t m_first_layer_idx = size_t(-1); diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 8d53dbb5a8..94b08b8857 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -1453,7 +1453,7 @@ void Print::_make_wipe_tower() this->throw_if_canceled(); // Initialize the wipe tower. - WipeTower wipe_tower(m_config, wipe_volumes, m_wipe_tower_data.tool_ordering.first_extruder()); + WipeTower wipe_tower(m_config, m_default_region_config, wipe_volumes, m_wipe_tower_data.tool_ordering.first_extruder()); //wipe_tower.set_retract(); //wipe_tower.set_zhop(); diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index ff7906da07..0b135f0b94 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -814,15 +814,15 @@ bool PrintObject::invalidate_state_by_config_options( || opt_key == "overhang_speed_2" || opt_key == "overhang_speed_3" || opt_key == "external_perimeter_speed" - || opt_key == "infill_speed" - || opt_key == "perimeter_speed" || opt_key == "small_perimeter_speed" || opt_key == "solid_infill_speed" || opt_key == "top_solid_infill_speed") { invalidated |= m_print->invalidate_step(psGCodeExport); } else if ( opt_key == "wipe_into_infill" - || opt_key == "wipe_into_objects") { + || opt_key == "wipe_into_objects" + || opt_key == "infill_speed" + || opt_key == "perimeter_speed") { invalidated |= m_print->invalidate_step(psWipeTower); invalidated |= m_print->invalidate_step(psGCodeExport); } else { From c5b22163c59cc3be3e5a4026eb3b9d6d47a51f39 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Fri, 30 Jun 2023 10:35:40 +0200 Subject: [PATCH 2/6] Fix crash when exporting to stl --- src/libslic3r/CSGMesh/CSGMesh.hpp | 33 ++++++++++++++++++++++++++++++- src/libslic3r/SLAPrintSteps.cpp | 29 --------------------------- src/slic3r/GUI/Plater.cpp | 7 +++++-- 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/src/libslic3r/CSGMesh/CSGMesh.hpp b/src/libslic3r/CSGMesh/CSGMesh.hpp index d14ed76595..a9a1811186 100644 --- a/src/libslic3r/CSGMesh/CSGMesh.hpp +++ b/src/libslic3r/CSGMesh/CSGMesh.hpp @@ -1,8 +1,10 @@ #ifndef CSGMESH_HPP #define CSGMESH_HPP +#include "libslic3r/Point.hpp" + #include -#include +#include namespace Slic3r { namespace csg { @@ -81,6 +83,35 @@ struct CSGPart { {} }; +template bool is_all_positive(const Cont &csgmesh) +{ + bool is_all_pos = + std::all_of(csgmesh.begin(), + csgmesh.end(), + [](auto &part) { + return csg::get_operation(part) == csg::CSGType::Union; + }); + + return is_all_pos; +} + +template +indexed_triangle_set csgmesh_merge_positive_parts(const Cont &csgmesh) +{ + indexed_triangle_set m; + for (auto &csgpart : csgmesh) { + auto op = csg::get_operation(csgpart); + const indexed_triangle_set * pmesh = csg::get_mesh(csgpart); + if (pmesh && op == csg::CSGType::Union) { + indexed_triangle_set mcpy = *pmesh; + its_transform(mcpy, csg::get_transform(csgpart), true); + its_merge(m, mcpy); + } + } + + return m; +} + }} // namespace Slic3r::csg #endif // CSGMESH_HPP diff --git a/src/libslic3r/SLAPrintSteps.cpp b/src/libslic3r/SLAPrintSteps.cpp index 33e2a6e20f..412bd1b422 100644 --- a/src/libslic3r/SLAPrintSteps.cpp +++ b/src/libslic3r/SLAPrintSteps.cpp @@ -127,35 +127,6 @@ void SLAPrint::Steps::apply_printer_corrections(SLAPrintObject &po, SliceOrigin } } -template bool is_all_positive(const Cont &csgmesh) -{ - bool is_all_pos = - std::all_of(csgmesh.begin(), - csgmesh.end(), - [](auto &part) { - return csg::get_operation(part) == csg::CSGType::Union; - }); - - return is_all_pos; -} - -template -static indexed_triangle_set csgmesh_merge_positive_parts(const Cont &csgmesh) -{ - indexed_triangle_set m; - for (auto &csgpart : csgmesh) { - auto op = csg::get_operation(csgpart); - const indexed_triangle_set * pmesh = csg::get_mesh(csgpart); - if (pmesh && op == csg::CSGType::Union) { - indexed_triangle_set mcpy = *pmesh; - its_transform(mcpy, csg::get_transform(csgpart), true); - its_merge(m, mcpy); - } - } - - return m; -} - indexed_triangle_set SLAPrint::Steps::generate_preview_vdb( SLAPrintObject &po, SLAPrintObjectStep step) { diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index fcd97cdc15..902eeb6ded 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -6471,9 +6471,12 @@ void Plater::export_stl_obj(bool extended, bool selection_only) csg::model_to_csgmesh(mo, Transform3d::Identity(), std::back_inserter(csgmesh), csg::mpartsPositive | csg::mpartsNegative | csg::mpartsDoSplits); - if (csg::check_csgmesh_booleans(range(csgmesh)) == csgmesh.end()) { + auto csgrange = range(csgmesh); + if (csg::is_all_positive(csgrange)) { + mesh = TriangleMesh{csg::csgmesh_merge_positive_parts(csgrange)}; + } else if (csg::check_csgmesh_booleans(csgrange) == csgrange.end()) { try { - auto cgalm = csg::perform_csgmesh_booleans(range(csgmesh)); + auto cgalm = csg::perform_csgmesh_booleans(csgrange); mesh = MeshBoolean::cgal::cgal_to_triangle_mesh(*cgalm); } catch (...) {} } From 866fc767bb129b042669bc5a50deb98cd0cc5218 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Fri, 28 Jul 2023 19:30:49 +0200 Subject: [PATCH 3/6] Integrating LibBGCode into deps with an optional var for source dir One can then co-develop the two projects with relative convenience --- deps/CMakeLists.txt | 9 +++++++-- deps/LibBGCode/LibBGCode.cmake | 24 ++++++++++++++++++++++++ src/libslic3r/CMakeLists.txt | 3 +++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 deps/LibBGCode/LibBGCode.cmake diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index b00f85ba70..1008707d78 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -20,8 +20,8 @@ # therefore, unfortunatelly, the installation cannot be copied/moved elsewhere without re-installing wxWidgets. # +cmake_minimum_required(VERSION 3.10) project(PrusaSlicer-deps) -cmake_minimum_required(VERSION 3.2) include(ExternalProject) include(ProcessorCount) @@ -62,6 +62,8 @@ if (NOT _is_multi AND NOT CMAKE_BUILD_TYPE) message(STATUS "Forcing CMAKE_BUILD_TYPE to Release as it was not specified.") endif () +cmake_policy(SET CMP0135 NEW) + function(prusaslicer_add_cmake_project projectname) cmake_parse_arguments(P_ARGS "" "INSTALL_DIR;BUILD_COMMAND;INSTALL_COMMAND" "CMAKE_ARGS" ${ARGN}) @@ -195,6 +197,8 @@ include(NanoSVG/NanoSVG.cmake) include(wxWidgets/wxWidgets.cmake) include(OCCT/OCCT.cmake) +include(LibBGCode/LibBGCode.cmake) + set(_dep_list dep_Boost dep_TBB @@ -206,10 +210,11 @@ set(_dep_list dep_OpenCSG dep_CGAL dep_Qhull - dep_OCCT + # dep_OCCT ${PNG_PKG} ${ZLIB_PKG} ${EXPAT_PKG} + dep_LibBGCode ) # if (NOT MSVC) diff --git a/deps/LibBGCode/LibBGCode.cmake b/deps/LibBGCode/LibBGCode.cmake new file mode 100644 index 0000000000..6ecd5ee725 --- /dev/null +++ b/deps/LibBGCode/LibBGCode.cmake @@ -0,0 +1,24 @@ +set(LibBGCode_SOURCE_DIR "" CACHE PATH "Optionally specify local LibBGCode source directory") + +set(_source_dir_line "URL;https://github.com/prusa3d/libbgcode/archive/refs/heads/main.zip") + +if (LibBGCode_SOURCE_DIR) + set(_source_dir_line "SOURCE_DIR;${LibBGCode_SOURCE_DIR};BUILD_ALWAYS;ON") +endif () + +prusaslicer_add_cmake_project(LibBGCode_deps + ${_source_dir_line} + SOURCE_SUBDIR deps + CMAKE_ARGS + -DDEP_DOWNLOAD_DIR:PATH=${DEP_DOWNLOAD_DIR} + -DLibBGCode_Deps_SELECT_ALL:BOOL=OFF + -DLibBGCode_Deps_SELECT_heatshrink:BOOL=ON + -DDESTDIR=${DESTDIR} +) + +prusaslicer_add_cmake_project(LibBGCode + ${_source_dir_line} + DEPENDS dep_LibBGCode_deps + CMAKE_ARGS + -DLibBGCode_BUILD_TESTS:BOOL=OFF +) \ No newline at end of file diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 0de0b4e517..f11986d314 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -14,6 +14,8 @@ if (TARGET OpenVDB::openvdb) set(OpenVDBUtils_SOURCES OpenVDBUtils.cpp OpenVDBUtils.hpp OpenVDBUtilsLegacy.hpp) endif() +find_package(LibBGCode REQUIRED COMPONENTS Convert) + set(SLIC3R_SOURCES pchheader.cpp pchheader.hpp @@ -508,6 +510,7 @@ target_link_libraries(libslic3r ZLIB::ZLIB JPEG::JPEG qoi + LibBGCode::bgcode_convert ) if (APPLE) From d9f0c1a0526343f4b2d3076d386bb8fa52241651 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Sat, 29 Jul 2023 15:41:13 +0200 Subject: [PATCH 4/6] fix unknown policy on older cmakes --- deps/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 1008707d78..fce6a6e753 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -62,7 +62,9 @@ if (NOT _is_multi AND NOT CMAKE_BUILD_TYPE) message(STATUS "Forcing CMAKE_BUILD_TYPE to Release as it was not specified.") endif () -cmake_policy(SET CMP0135 NEW) +if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) + cmake_policy(SET CMP0135 NEW) +endif () function(prusaslicer_add_cmake_project projectname) cmake_parse_arguments(P_ARGS "" "INSTALL_DIR;BUILD_COMMAND;INSTALL_COMMAND" "CMAKE_ARGS" ${ARGN}) From 6d3d3298dafaf74a406c5dedc6f6788c0b8df5f6 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Sat, 29 Jul 2023 15:45:29 +0200 Subject: [PATCH 5/6] use git to download libbgcode by default should work on the build server --- deps/LibBGCode/LibBGCode.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/LibBGCode/LibBGCode.cmake b/deps/LibBGCode/LibBGCode.cmake index 6ecd5ee725..61b7f34504 100644 --- a/deps/LibBGCode/LibBGCode.cmake +++ b/deps/LibBGCode/LibBGCode.cmake @@ -1,6 +1,6 @@ set(LibBGCode_SOURCE_DIR "" CACHE PATH "Optionally specify local LibBGCode source directory") -set(_source_dir_line "URL;https://github.com/prusa3d/libbgcode/archive/refs/heads/main.zip") +set(_source_dir_line "GIT_REPOSITORY;git@github.com:prusa3d/libbgcode.git;GIT_TAG;main") if (LibBGCode_SOURCE_DIR) set(_source_dir_line "SOURCE_DIR;${LibBGCode_SOURCE_DIR};BUILD_ALWAYS;ON") From be468dca797a32260d4daf84a391038853f053ee Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 1 Aug 2023 13:34:39 +0200 Subject: [PATCH 6/6] Revert accidental commenting out of dep_OCCT --- deps/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index fce6a6e753..d5edcb5719 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -212,7 +212,7 @@ set(_dep_list dep_OpenCSG dep_CGAL dep_Qhull - # dep_OCCT + dep_OCCT ${PNG_PKG} ${ZLIB_PKG} ${EXPAT_PKG}