Belt printers: brim laid onto the tilted belt, with a leading apron

A belt printer slices in a rotated frame, so the belt surface is a tilted
plane rather than the Z=0 bed plane.  Each slicing layer touches the belt
only along a narrow strip at its leading edge - about 0.2mm at 45 degrees -
so a part's first layer is really a first line, with almost no contact patch
to hold it down while the belt drags it forward.  Brim was hard-disabled on
belt printers, leaving no remedy at all.

Generate the brim on the belt plane instead.  The object's belt footprint is
the union over layers of each slice clipped to that layer's contact band; the
brim is offset from it in a "flattened" frame where the shear axis is
stretched by 1/cos(tilt), so ordinary Clipper offsets measure true on-belt
distance.  It is emitted as cross-belt lines, one per layer band, anchored to
a fixed fraction of the band so every line shares a nozzle-to-belt clearance
and therefore comes out the same width; flow is matched to the resulting band
pitch, keeping the sheet uniform and gap-free.

Three new controls, all belt-only:

  * Leading brim length - extends the brim ahead of the part along the belt,
    on every downhill-facing edge of its contact area.  This apron necessarily
    prints BELOW the object's first layer, since layer 0 is the part's leading
    contact, so it needs brim-only bands of its own.
  * Extra brim width - widens the brim sideways across the belt only.
  * Brim type "Leading edge only" - brim at the part's first belt contact and
    nothing after it.  Appended last in BrimType so no existing value shifts;
    degrades to an outer brim off belt printers, with a warning.

The apron bands are lightweight records rather than a Layer subclass, so no
fabricated Layer::id() can leak into initial-layer temperature selection, the
spiral vase probe, cooling or gradual interpolation.  They are generated in
posSupportMaterial because their print_z values must exist before ToolOrdering
is built at psWipeTower, and they are emitted from a short dedicated branch in
process_layer that runs before any layer pointer is dereferenced.

The footprint is closed before offsetting outwards: a belt contact patch is
often a broken-up strip, and the merged offset rings of two islands closer
than 2 x brim_width would otherwise fill the space between them - space that
lies under the part.

Also fixes a pre-existing bug where PrintObject::get_first_layer_bbox()
overwrote a valid bbox with an unassigned one on any belt printer with a brim
configured, because has_brim() was true while make_brim() returned early.

Belt brim is refused alongside the prime tower and spiral vase, and requires
one instance per PrintObject - translating an instance along the belt axis
changes its physical belt-floor Z.  Untilted belt printers are unchanged: they
still get no brim, since the plate brim is emitted out of skirt_brim_groups(),
which _make_skirt() never builds for a belt printer.
This commit is contained in:
harrierpigeon
2026-08-06 01:08:44 -05:00
parent 386364f84b
commit 55b4dca9bc
24 changed files with 1744 additions and 31 deletions

View File

@@ -1,6 +1,8 @@
#include <catch2/catch_all.hpp>
#include "libslic3r/ClipperUtils.hpp"
#include "libslic3r/GCodeReader.hpp"
#include "libslic3r/Layer.hpp"
#include "libslic3r/Config.hpp"
#include "libslic3r/Geometry.hpp"
#include "libslic3r/Geometry/ConvexHull.hpp"
@@ -441,3 +443,193 @@ SCENARIO("Skirt and brim generation", "[SkirtBrim]") {
}
}
}
// Belt printers ---------------------------------------------------------------
//
// On a tilted belt the brim is laid onto the belt PLANE rather than into the Z=0
// bed plane, so it is spread across many layers instead of living on the first
// one. The discriminating measurement is the number of contiguous brim runs in
// the G-code: a flat plate brim gives a single run, a belt brim gives one per
// layer that carries a band. Distinct Z values are useless here, because the
// machine-frame transform couples Y into Z so every belt move has its own Z.
static DynamicPrintConfig belt_brim_config()
{
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
config.set_deserialize_strict({
{ "belt_printer", 1 },
{ "belt_slice_rotation", "x" },
{ "belt_slice_rotation_angle", 45 },
{ "belt_slice_rotation_global", 1 },
{ "gcode_remap_x", "rev_x" },
{ "gcode_remap_y", "pos_z" },
{ "gcode_remap_z", "pos_y" },
{ "layer_height", 0.2 },
{ "initial_layer_print_height", 0.2 },
{ "skirt_loops", 0 },
{ "top_shell_layers", 0 },
{ "bottom_shell_layers", 1 },
{ "machine_start_gcode", "T[initial_tool]\n" },
});
return config;
}
TEST_CASE("Belt brim spans many layers instead of one", "[SkirtBrim][belt]")
{
DynamicPrintConfig config = belt_brim_config();
config.set_deserialize_strict({
{ "brim_type", "outer_only" },
{ "brim_width", 5 },
});
const std::string gcode = slice({ cube(20) }, config);
// A plate-brim implementation would score 1 here.
CHECK(role_passes(gcode, "brim") > 10);
}
TEST_CASE("Belt brim is absent when both widths are zero", "[SkirtBrim][belt]")
{
// The "no effect when disabled" guard: brim_type Auto is the shipped default and
// reports has_brim() even at width 0, so this also pins the gate that keeps the
// flat plate brim from running on a tilted belt.
const char *brim_type = GENERATE("auto_brim", "outer_only", "no_brim");
DYNAMIC_SECTION("brim_type " << brim_type) {
DynamicPrintConfig config = belt_brim_config();
config.set_deserialize_strict({
{ "brim_type", brim_type },
{ "brim_width", 0 },
{ "leading_brim_length", 0 },
{ "extra_brim_width", 0 },
});
const std::string gcode = slice({ cube(20) }, config);
CHECK(role_passes(gcode, "brim") == 0);
}
}
TEST_CASE("Leading brim length alone produces a belt brim", "[SkirtBrim][belt]")
{
// Exercises the leading_brim_length-only enablement path and the downhill sweep.
DynamicPrintConfig config = belt_brim_config();
config.set_deserialize_strict({
{ "brim_type", "outer_only" },
{ "brim_width", 0 },
{ "leading_brim_length", 5 },
{ "brim_object_gap", 0 },
});
const std::string gcode = slice({ cube(20) }, config);
CHECK(role_passes(gcode, "brim") > 0);
}
TEST_CASE("Leading brim length reaches further ahead of the object", "[SkirtBrim][belt]")
{
// Compared between two runs rather than against an absolute coordinate, so the
// assertion survives any change of origin or axis remap.
auto brim_extent = [](double extra) {
DynamicPrintConfig config = belt_brim_config();
config.set_deserialize_strict({
{ "brim_type", "outer_only" },
{ "brim_width", 3 },
{ "leading_brim_length", extra },
{ "brim_object_gap", 0 },
});
const std::string gcode = slice({ cube(20) }, config);
// The apron prints before the object reaches the belt, so it shows up as brim
// extrusion at the lowest machine Z of any brim move.
double min_z = std::numeric_limits<double>::max();
GCodeReader parser;
parser.parse_buffer(gcode, [&min_z](GCodeReader &self, const GCodeReader::GCodeLine &line) {
if (line.extruding(self) && line.comment().find("brim") != std::string_view::npos)
min_z = std::min(min_z, static_cast<double>(self.z()));
});
return min_z;
};
const double without = brim_extent(0.);
const double with = brim_extent(10.);
REQUIRE(without < std::numeric_limits<double>::max());
REQUIRE(with < std::numeric_limits<double>::max());
CHECK(with < without);
}
TEST_CASE("Every brim type slices on a belt printer", "[SkirtBrim][belt]")
{
// Auto / Mouse ear / Painted collapse to outer-only rather than crashing or
// silently producing nothing.
const char *brim_type = GENERATE("auto_brim", "brim_ears", "painted", "outer_only",
"inner_only", "outer_and_inner", "no_brim");
DYNAMIC_SECTION("brim_type " << brim_type) {
DynamicPrintConfig config = belt_brim_config();
config.set_deserialize_strict({
{ "brim_type", brim_type },
{ "brim_width", 5 },
});
const std::string gcode = slice({ cube(20) }, config);
REQUIRE(! gcode.empty());
if (std::string(brim_type) == "no_brim")
CHECK(role_passes(gcode, "brim") == 0);
else if (std::string(brim_type) != "inner_only")
// A solid cube has no holes, so inner_only legitimately yields nothing.
CHECK(role_passes(gcode, "brim") > 0);
}
}
TEST_CASE("An untilted belt printer gets no brim", "[SkirtBrim][belt]")
{
// Belt brim needs a tilt to have a belt plane to lie on, and the flat plate brim
// cannot reach the G-code on any belt printer: it is emitted out of
// skirt_brim_groups(), which _make_skirt() builds, and that returns early for every
// belt printer. So an untilted belt printer gets nothing - unchanged by this
// feature. Making the flat brim work here would mean reopening the belt skirt gate,
// which is a separate change; Print::validate() warns instead.
DynamicPrintConfig config = belt_brim_config();
config.set_deserialize_strict({
{ "belt_slice_rotation", "none" },
{ "brim_type", "outer_only" },
{ "brim_width", 5 },
});
const std::string gcode = slice({ cube(20) }, config);
CHECK(role_passes(gcode, "brim") == 0);
}
TEST_CASE("Belt brim does not resurrect the skirt", "[SkirtBrim][belt]")
{
DynamicPrintConfig config = belt_brim_config();
config.set_deserialize_strict({
{ "brim_type", "outer_only" },
{ "brim_width", 5 },
{ "skirt_loops", 2 },
});
const std::string gcode = slice({ cube(20) }, config);
CHECK(role_passes(gcode, "skirt") == 0);
}
TEST_CASE("Belt brim lines all have the same width", "[SkirtBrim][belt]")
{
// Each brim line's extrusion volume comes from its nozzle-to-belt clearance. Anchoring
// every line to a fixed fraction of its own band gives them all the same clearance, so
// they all come out the same width. The nominal-spacing lattice this replaced let each
// line land wherever it fell inside its band, so the clearance - and the width with it -
// varied by 2x, which showed up as visibly ragged brim.
DynamicPrintConfig config = belt_brim_config();
config.set_deserialize_strict({
{ "brim_type", "outer_only" },
{ "brim_width", 5 },
{ "brim_object_gap", 0 },
});
Print print;
init_and_process_print({ cube(20) }, print, config);
const PrintObject *obj = print.objects().front();
std::vector<float> widths;
auto collect = [&widths](const ExtrusionEntityCollection &coll) {
for (const ExtrusionEntity *ee : coll.entities)
if (const auto *path = dynamic_cast<const ExtrusionPath *>(ee))
widths.push_back(path->width);
};
for (const ExtrusionEntityCollection &band : obj->belt_brim_by_layer())
collect(band);
for (const BeltBrimBand &band : obj->belt_brim_prologue())
collect(band.fills);
REQUIRE(widths.size() > 10);
const float lo = *std::min_element(widths.begin(), widths.end());
const float hi = *std::max_element(widths.begin(), widths.end());
CHECK_THAT(hi, Catch::Matchers::WithinRel(lo, 1e-4));
}