diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index 7fdbb6915..1ac645c93 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -1346,6 +1346,31 @@ std::pair WipeTower::get_wipe_tower_cone_base(double width, doub return std::make_pair(R, support_scale); } +// Static method to extract wipe_volumes[from][to] from the configuration. +std::vector> WipeTower::extract_wipe_volumes(const PrintConfig& config) +{ + // Get wiping matrix to get number of extruders and convert vector to vector: + std::vector wiping_matrix(cast(config.wiping_volumes_matrix.values)); + + // Extract purging volumes for each extruder pair: + std::vector> wipe_volumes; + const unsigned int number_of_extruders = (unsigned int)(sqrt(wiping_matrix.size())+EPSILON); + for (unsigned int i = 0; i(wiping_matrix.begin()+i*number_of_extruders, wiping_matrix.begin()+(i+1)*number_of_extruders)); + + // Also include filament_minimal_purge_on_wipe_tower. This is needed for the preview. + for (unsigned int i = 0; i get_wipe_tower_cone_base(double width, double height, double depth, double angle_deg); + static std::vector> extract_wipe_volumes(const PrintConfig& config); struct Extrusion { diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index f16dadc8c..b93fef1ff 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -1337,11 +1337,22 @@ const WipeTowerData& Print::wipe_tower_data(size_t extruders_cnt) const { // If the wipe tower wasn't created yet, make sure the depth and brim_width members are set to default. if (! is_step_done(psWipeTower) && extruders_cnt !=0) { + const_cast(this)->m_wipe_tower_data.brim_width = m_config.wipe_tower_brim_width; + + // Calculating depth should take into account currently set wiping volumes. + // For a long time, the initial preview would just use 900/width per toolchange (15mm on a 60mm wide tower) + // and it worked well enough. Let's try to do slightly better by accounting for the purging volumes. + std::vector> wipe_volumes = WipeTower::extract_wipe_volumes(m_config); + std::vector max_wipe_volumes; + for (const std::vector& v : wipe_volumes) + max_wipe_volumes.emplace_back(*std::max_element(v.begin(), v.end())); + float maximum = std::accumulate(max_wipe_volumes.begin(), max_wipe_volumes.end(), 0.f); + maximum = maximum * extruders_cnt / max_wipe_volumes.size(); float width = float(m_config.wipe_tower_width); + float layer_height = 0.2f; // just assume fixed value, it will still be better than before. - const_cast(this)->m_wipe_tower_data.depth = (900.f/width) * float(extruders_cnt - 1); - const_cast(this)->m_wipe_tower_data.brim_width = m_config.wipe_tower_brim_width; + const_cast(this)->m_wipe_tower_data.depth = (maximum/layer_height)/width; } return m_wipe_tower_data; @@ -1353,13 +1364,7 @@ void Print::_make_wipe_tower() if (! this->has_wipe_tower()) return; - // Get wiping matrix to get number of extruders and convert vector to vector: - std::vector wiping_matrix(cast(m_config.wiping_volumes_matrix.values)); - // Extract purging volumes for each extruder pair: - std::vector> wipe_volumes; - const unsigned int number_of_extruders = (unsigned int)(sqrt(wiping_matrix.size())+EPSILON); - for (unsigned int i = 0; i(wiping_matrix.begin()+i*number_of_extruders, wiping_matrix.begin()+(i+1)*number_of_extruders)); + std::vector> wipe_volumes = WipeTower::extract_wipe_volumes(m_config); // Let the ToolOrdering class know there will be initial priming extrusions at the start of the print. m_wipe_tower_data.tool_ordering = ToolOrdering(*this, (unsigned int)-1, true); @@ -1412,7 +1417,7 @@ void Print::_make_wipe_tower() //wipe_tower.set_zhop(); // Set the extruder & material properties at the wipe tower object. - for (size_t i = 0; i < number_of_extruders; ++ i) + for (size_t i = 0; i < m_config.nozzle_diameter.size(); ++ i) wipe_tower.set_extruder(i, m_config); m_wipe_tower_data.priming = Slic3r::make_unique>( diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index e8a80bf78..97975404f 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -488,8 +488,6 @@ int GLVolumeCollection::load_wipe_tower_preview( float rotation_angle, bool size_unknown, float brim_width) #endif // ENABLE_OPENGL_ES { - if (depth < 0.01f) - return int(this->volumes.size() - 1); if (height == 0.0f) height = 0.1f;