Fix review findings in the shared wipe tower estimate

A raft is not a reason to reserve a tower. Print::apply runs
normalize_fdm_2, which clears enable_prime_tower for a plate that purges
one filament unless smooth timelapse or wrapping detection is on, so a
single-filament plate with a raft prints no tower at all and the estimate
was reserving bed area for one. Drop the input; need_wipe_tower is now
exactly the two exceptions normalize_fdm_2 honours, named there so the
next reason added has to be checked against it.

The GUI preview and the validation containment check each re-derived
"is a tower printed here" from the filament count instead of reading the
estimate, so both missed the towers printed with no tool change to purge
for. They now take the answer from the footprint, which is the drift this
shared estimate exists to remove. A tower that is not printed estimates to
zero, so its hull is degenerate and every check on it passes trivially -
the containment check needs no gate of its own.

WipeTowerData::width was written only by the pre-generation estimate and
left at zero for the whole post-generation life of the Print, while its
neighbour depth held the real value. Set it from the generator in both
branches.

The plate's height scan transformed every model part's full mesh per
instance on each scene reload, discarding all but the z extent. The
cached convex hull has the same z extent.

A plate loaded from a sliced .gcode.3mf holds no objects and its filaments
live in slice_filaments_info; the config-taking get_extruders overload
returned an empty list for it, which sized the tower for a placeholder two
filaments. It now answers the way the wx overload does, without reaching
the plater.

Also drop estimate_wipe_tower_size, which has no callers.
This commit is contained in:
Hanif Koh
2026-09-09 15:45:16 +08:00
committed by HanifKoh
parent 8df5e5e738
commit e1efec7d6c
9 changed files with 154 additions and 76 deletions
+7 -4
View File
@@ -11,7 +11,7 @@
namespace Slic3r {
WipeTowerFootprint estimate_wipe_tower_footprint(const ConfigBase &config, size_t filaments_cnt, double layer_height, double max_object_height, bool any_raft)
WipeTowerFootprint estimate_wipe_tower_footprint(const ConfigBase &config, size_t filaments_cnt, double layer_height, double max_object_height)
{
WipeTowerFootprint footprint;
footprint.height = max_object_height;
@@ -56,8 +56,9 @@ WipeTowerFootprint estimate_wipe_tower_footprint(const ConfigBase &config, size_
const bool dual_nozzle = nozzle_opt != nullptr && nozzle_opt->values.size() == 2;
const bool rib_wall = opt_enum("wipe_tower_wall_type", int(WipeTowerWallType::wtwRectangle)) == int(WipeTowerWallType::wtwRib);
const bool smooth_timelapse = opt_enum("timelapse_type", int(TimelapseType::tlTraditional)) == int(TimelapseType::tlSmooth);
// Reasons a tower is printed with no tool change to purge for.
const bool need_wipe_tower = smooth_timelapse || opt_bool("enable_wrapping_detection") || any_raft;
// Reasons a tower is printed with no tool change to purge for: the ones that stop
// normalize_fdm_2 clearing enable_prime_tower. Its mixed-filament case is not modelled.
const bool need_wipe_tower = smooth_timelapse || opt_bool("enable_wrapping_detection");
// No tool change, nothing to purge; smooth timelapse still primes once.
size_t purge_count = 0;
@@ -80,7 +81,9 @@ WipeTowerFootprint estimate_wipe_tower_footprint(const ConfigBase &config, size_
// Both wall types decide this together: over-reserving only wastes bed area, but
// reporting no tower for one that is built collapses the validation hull to a point.
if (volume < EPSILON && !need_wipe_tower)
// A tool change is a reason on its own: the generator floors the tower whatever the
// purge volumes resolve to.
if (volume < EPSILON && filaments_cnt < 2 && !need_wipe_tower)
return footprint;
const double min_depth = WipeTower::get_limit_depth_by_height(float(max_object_height));
+4 -4
View File
@@ -21,9 +21,9 @@ struct WipeTowerFootprint
// changes, so a count derived from the model must include them
// (Print::extruders(true)) or a real tower is sized as if it were never built.
// layer_height: thinnest layer the tower will be planned at.
// any_raft: any object on the plate prints a raft, which puts the tower on every layer
// below it. Caller-resolved: raft_layers is a PrintObjectConfig key, absent
// from Print's config and overridable per object.
WipeTowerFootprint estimate_wipe_tower_footprint(const ConfigBase &config, size_t filaments_cnt, double layer_height, double max_object_height, bool any_raft);
//
// A raft is deliberately not a reason: normalize_fdm_2 clears enable_prime_tower for a plate
// purging one filament unless smooth timelapse or wrapping detection is on.
WipeTowerFootprint estimate_wipe_tower_footprint(const ConfigBase &config, size_t filaments_cnt, double layer_height, double max_object_height);
} // namespace Slic3r
+14 -15
View File
@@ -1081,22 +1081,21 @@ static StringObjectException layered_print_cleareance_valid(const Print &print,
if (print_config.enable_wrapping_detection.value && !intersection({wrapping_poly}, convex_hulls_temp).empty()) {
return {L("Prime Tower") + L(" is too close to clumping detection area, and collisions will be caused.\n")};
}
// Skip the containment check for towers that will never be printed (single-filament
// prints without smooth timelapse keep the config's tower position but emit nothing).
// No gate on "is there a tower": one that is not printed estimates to zero, so the hull
// is degenerate and every check passes. Re-deriving it here missed the wrapping-detection
// tower on a single-filament plate.
// Pre-generation only the body square is tested — the auto-brim estimate can overshoot
// the generated brim by several mm and must not hard-fail a print that physically fits.
// Post-generation the mesh bottom already includes the real brim, so the exact
// footprint is tested.
if (filaments_count > 1 || print.enable_timelapse_print()) {
// The shared printable polygon is plate-local, while the tower polygons above are
// already shifted by the plate origin.
Polygons printable_polys = print.get_extruder_shared_printable_polygon();
const Point plate_shift(scale_(plate_origin.x()), scale_(plate_origin.y()));
for (Polygon &p : printable_polys)
p.translate(plate_shift);
if (!diff(convex_hulls_temp, printable_polys).empty())
return {L("Prime Tower") + L(" is partially outside the printable area, and it cannot be printed.\n")};
}
// The shared printable polygon is plate-local, while the tower polygons above are
// already shifted by the plate origin.
Polygons printable_polys = print.get_extruder_shared_printable_polygon();
const Point plate_shift(scale_(plate_origin.x()), scale_(plate_origin.y()));
for (Polygon &p : printable_polys)
p.translate(plate_shift);
if (!diff(convex_hulls_temp, printable_polys).empty())
return {L("Prime Tower") + L(" is partially outside the printable area, and it cannot be printed.\n")};
return {};
}
@@ -4005,16 +4004,14 @@ const WipeTowerData &Print::wipe_tower_data(size_t filaments_cnt) const
double max_height = 0.;
double layer_height = std::numeric_limits<double>::max();
bool any_raft = false;
for (const PrintObject *object : m_objects) {
max_height = std::max(max_height, unscale_(double(object->size().z())));
layer_height = std::min(layer_height, object->config().layer_height.value);
any_raft = any_raft || object->config().raft_layers.value > 0;
}
if (max_height < EPSILON)
return m_wipe_tower_data;
const WipeTowerFootprint footprint = estimate_wipe_tower_footprint(m_config, filaments_cnt, layer_height, max_height, any_raft);
const WipeTowerFootprint footprint = estimate_wipe_tower_footprint(m_config, filaments_cnt, layer_height, max_height);
WipeTowerData &data = const_cast<Print *>(this)->m_wipe_tower_data;
data.depth = float(footprint.depth);
data.width = float(footprint.width);
@@ -4244,6 +4241,7 @@ void Print::_make_wipe_tower()
m_wipe_tower_data.tool_changes.reserve(m_wipe_tower_data.tool_ordering.layer_tools().size());
wipe_tower.generate_new(m_wipe_tower_data.tool_changes);
m_wipe_tower_data.depth = wipe_tower.get_depth();
m_wipe_tower_data.width = wipe_tower.width();
m_wipe_tower_data.brim_width = wipe_tower.get_brim_width();
m_wipe_tower_data.bbx = wipe_tower.get_bbx();
m_wipe_tower_data.rib_offset = wipe_tower.get_rib_offset();
@@ -4357,6 +4355,7 @@ void Print::_make_wipe_tower()
m_wipe_tower_data.tool_changes.reserve(m_wipe_tower_data.tool_ordering.layer_tools().size());
wipe_tower.generate(m_wipe_tower_data.tool_changes);
m_wipe_tower_data.depth = wipe_tower.get_depth();
m_wipe_tower_data.width = wipe_tower.width();
m_wipe_tower_data.z_and_depth_pairs = wipe_tower.get_z_and_depth_pairs();
m_wipe_tower_data.brim_width = wipe_tower.get_brim_width();
m_wipe_tower_data.height = wipe_tower.get_wipe_tower_height();
+2 -2
View File
@@ -782,8 +782,8 @@ struct WipeTowerData
// Depth of the wipe tower to pass to GLCanvas3D for exact bounding box:
float depth;
// Effective width (a rib wall squares the tower). Pre-generation estimate only; once the
// tower exists its mesh is exact.
// Effective width (a rib wall squares the tower): the estimate until generation, then the
// generated width, so it never disagrees with depth.
float width;
std::vector<std::pair<float, float>> z_and_depth_pairs;
float brim_width;
+3 -1
View File
@@ -2895,12 +2895,14 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
Vec3d plate_origin = ppl.get_plate(plate_id)->get_origin();
const Print* current_print = part_plate->fff_print();
if (!need_wipe_tower && part_plate->get_extruders(true).size() < 2) continue;
if (part_plate->get_objects_on_this_plate().empty()) continue;
// Body and brim from this plate's own estimate: m_process->fff_print() is the
// selected plate's, so an auto brim drew every tower with that plate's brim.
const WipeTowerFootprint footprint = part_plate->estimate_wipe_tower_footprint(full_config);
// The estimate is also the answer to whether this plate prints a tower;
// deciding it here as well only gave the two room to drift.
if (footprint.depth <= 0.) continue;
float brim_width = float(footprint.brim_width);
Vec3d wipe_tower_size(footprint.width, footprint.depth, footprint.height);
+13 -14
View File
@@ -1,5 +1,6 @@
#include <cstddef>
#include <algorithm>
#include <limits>
#include <numeric>
#include <vector>
#include <string>
@@ -1541,6 +1542,14 @@ std::vector<int> PartPlate::get_extruders(bool conside_custom_gcode) const
std::vector<int> PartPlate::get_extruders(bool conside_custom_gcode, const DynamicPrintConfig& glb_config, const DynamicPrintConfig& project_config) const
{
std::vector<int> plate_extruders;
// A plate from a sliced .gcode.3mf holds no objects, so report the filaments the G-code
// used. check_objects_empty_and_gcode3mf does this for get_extruders(bool), but reaches
// the plater, which the CLI has none of; slice_filaments_info is only filled for such a plate.
if (m_model->objects.empty()) {
for (const FilamentInfo &info : slice_filaments_info)
plate_extruders.push_back(info.id + 1);
return plate_extruders;
}
int glb_support_intf_extr = glb_config.opt_int("support_interface_filament");
int glb_support_extr = glb_config.opt_int("support_filament");
int glb_outer_wall_extr = glb_config.opt_int("outer_wall_filament_id");
@@ -2347,37 +2356,27 @@ WipeTowerFootprint PartPlate::estimate_wipe_tower_footprint(const DynamicPrintCo
// seeding from the global value, or folding in an off-plate override, diverges from Print.
const ConfigOption *layer_height_opt = config.option("layer_height");
const double global_layer_height = layer_height_opt != nullptr ? layer_height_opt->getFloat() : 0.08;
const ConfigOption *raft_layers_opt = config.option("raft_layers");
const int global_raft_layers = raft_layers_opt != nullptr ? raft_layers_opt->getInt() : 0;
double max_height = 0.;
double layer_height = std::numeric_limits<double>::max();
bool any_raft = false;
for (int obj_idx = 0; obj_idx < int(m_model->objects.size()); ++obj_idx) {
const ModelObject *object = m_model->objects[obj_idx];
if (!use_global_objects && !contain_any_instance_totally(obj_idx))
continue;
// Per instance, to match PrintObject::size(); the union over instances differs once
// they are rotated apart.
// they are rotated apart. The cached convex hull has the mesh's z extent and is cheap
// enough for every scene reload.
for (int inst_idx = 0; inst_idx < int(object->instances.size()); ++inst_idx) {
if (!use_global_objects && !contain_instance_totally(obj_idx, inst_idx))
continue;
max_height = std::max(max_height, object->instance_bounding_box(inst_idx, true).size().z());
max_height = std::max(max_height, object->instance_convex_hull_bounding_box(inst_idx, true).size().z());
}
const ConfigOption *object_layer_height = object->config.option("layer_height");
layer_height = std::min(layer_height, object_layer_height != nullptr ? object_layer_height->getFloat() : global_layer_height);
const ConfigOption *object_raft_layers = object->config.option("raft_layers");
any_raft = any_raft || (object_raft_layers != nullptr ? object_raft_layers->getInt() : global_raft_layers) > 0;
}
if (layer_height == std::numeric_limits<double>::max())
layer_height = global_layer_height;
return Slic3r::estimate_wipe_tower_footprint(config, size_t(plate_extruder_size), layer_height, max_height, any_raft);
}
Vec3d PartPlate::estimate_wipe_tower_size(const DynamicPrintConfig &config, int plate_extruder_size, bool use_global_objects) const
{
const WipeTowerFootprint footprint = estimate_wipe_tower_footprint(config, plate_extruder_size, use_global_objects);
return Vec3d(footprint.width, footprint.depth, footprint.height);
return Slic3r::estimate_wipe_tower_footprint(config, size_t(plate_extruder_size), layer_height, max_height);
}
arrangement::ArrangePolygon PartPlate::estimate_wipe_tower_polygon(const DynamicPrintConfig& config, int plate_index, Vec3d& wt_pos, Vec3d& wt_size, int plate_extruder_size, bool use_global_objects) const
+3 -2
View File
@@ -340,9 +340,10 @@ public:
Vec3d get_origin() { return m_origin; }
//Vec3d calculate_wipe_tower_size(const DynamicPrintConfig &config, const double w, const double wipe_volume, int plate_extruder_size = 0, bool use_global_objects = false) const;
// plate_extruder_size: filaments purged on the plate; 0 derives it from the plate's objects.
// plate_extruder_size: filaments purged on the plate; 0 derives them from its objects.
// use_global_objects skips the containment test, which the CLI needs before objects are
// assigned to plates - the layer height is then the project's thinnest, which over-reserves.
WipeTowerFootprint estimate_wipe_tower_footprint(const DynamicPrintConfig & config, int plate_extruder_size = 0, bool use_global_objects = false) const;
Vec3d estimate_wipe_tower_size(const DynamicPrintConfig & config, int plate_extruder_size = 0, bool use_global_objects = false) const;
arrangement::ArrangePolygon estimate_wipe_tower_polygon(const DynamicPrintConfig & config, int plate_index, Vec3d& wt_pos, Vec3d& wt_size, int plate_extruder_size = 0, bool use_global_objects = false) const;
bool check_objects_empty_and_gcode3mf(std::vector<int> &result) const;
// get used filaments from config, 1 based idx