Belt printer: no layer changes that print nothing, and a preview that survives them

Since the slicing frame of a belt object starts at the belt below its
leading end, its first layers are empty.  On a single part they carry
the brim bands; with several parts along the belt the later parts'
empty layers fall between the earlier parts' printing layers and were
written to the G-code as layer changes with no moves at all.  The
preview numbers its layers (libvgcode::Layers) from the vertices it is
given and expects consecutive ids, so at the first such gap it stopped
creating layers and folded everything after it into the last one: the
top slider layer held nearly the whole print, the slider jumped every
other layer through the single-colour stretch before a second part on
another filament, and with the belt purge tower the whole print greyed
out while dragging.

Drop the belt layers that print nothing (no object, support or brim
content) in GCode::collect_layers_to_print, and renumber the layers
consecutively over the moves that exist when converting a result for
libvgcode, so a file with empty layers from any source still previews
correctly.  The layer slider labels a belt layer with its print Z (the
slicer's layer Z, which increases along the belt) instead of libvgcode's
toolpath height, which on a tilted layer is wherever its last extrusion
ended; the slider assumes that list increases and showed "0 / max" on
alternate layers.  The processor reads that print Z from the ";Z:" tag
non-BBL printers write (it only knew "; Z_HEIGHT:"), on belt printers
only, so nothing changes elsewhere.  Regression test: two cubes 60 mm apart along the
belt produce no layer without an extrusion and the header's layer count
matches.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
harrierpigeon
2026-10-07 03:50:51 -05:00
co-authored by Claude Fable 5.1
parent 6927475499
commit f64b49ab52
6 changed files with 147 additions and 4 deletions
+30
View File
@@ -2440,6 +2440,36 @@ std::vector<std::pair<coordf_t, std::vector<GCode::LayerToPrint>>> GCode::collec
layers_to_print.emplace_back(std::move(merged));
}
// Belt printers: drop the layers that print nothing at all. An object's
// slicing frame starts at the belt below its leading end, so its first layers
// are empty, and with several objects along the belt those empty layers fall
// between other objects' printing layers. A layer change with no moves is
// noise in the file, and the preview (libvgcode) numbers its layers from the
// moves it sees, so a gap folds every later layer into the one before it.
if (print.config().belt_printer.value) {
auto prints_something = [](const LayerToPrint &ltp) {
if (ltp.object_layer != nullptr && ltp.object_layer->has_extrusions())
return true;
if (ltp.support_layer != nullptr && ltp.support_layer->has_extrusions())
return true;
if (ltp.belt_brim_band != nullptr && ! ltp.belt_brim_band->fills.empty())
return true;
if (ltp.object_layer != nullptr && ltp.original_object != nullptr && ltp.original_object->has_belt_brim()) {
const auto &by_layer = ltp.original_object->belt_brim_by_layer();
const size_t id = ltp.object_layer->id();
if (id < by_layer.size() && ! by_layer[id].empty())
return true;
}
return false;
};
layers_to_print.erase(
std::remove_if(layers_to_print.begin(), layers_to_print.end(),
[&prints_something](const std::pair<coordf_t, std::vector<LayerToPrint>> &group) {
return std::none_of(group.second.begin(), group.second.end(), prints_something);
}),
layers_to_print.end());
}
return layers_to_print;
}