Merge Main into Belt Printer

Merge origin/main (00429da739) into belt-printer.

Conflicts resolved:
- src/CMakeLists.txt: keep both wxInspector workarounds.
- GCodeProcessor.cpp: keep the belt compare_pos / z_for_height lines.
- PrintObjectSlice.cpp: the belt bbox-Z guard also covers main's
  printable_region_ids bookkeeping.
- TreeSupport.cpp: the belt-floor check runs before main's PendingNode
  queueing.
- Tab.hpp: keep the belt fields, drop the removed upload description
  fields.
- tests/libslic3r/CMakeLists.txt: keep both test files.

Also included:
- eSUN PLA belt presets declare their own filament_id (OFkrxQC4) and
  scripts/filament_id_snapshot.json is regenerated, as main's filament_id
  check requires.
- Custom.json version bumped to 02.04.00.05 so the belt entries reach
  existing installs.
- Fix the ambiguous WithinRel call in the belt apron width test, which
  otherwise breaks the fff_print build.
This commit is contained in:
Hanif Koh
2026-09-14 16:33:08 +08:00
4930 changed files with 62617 additions and 21404 deletions
+1
View File
@@ -19,6 +19,7 @@ add_executable(${_TEST_NAME}_tests
test_skirt_brim.cpp
test_slicing_pipeline_hook.cpp
test_support_material.cpp
test_tree_support.cpp
test_trianglemesh.cpp
test_wipe_tower.cpp
)
+68
View File
@@ -2,7 +2,10 @@
#include "test_helpers.hpp"
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
using namespace Slic3r;
using namespace Slic3r::Test;
@@ -25,3 +28,68 @@ TEST_CASE("Cooling consumes its internal speed markers", "[Cooling]")
const std::string gcode = slice({ cube(20) }, { { "layer_height", 0.2 } });
CHECK(gcode.find(";_EXTRUDE_SET_SPEED") == std::string::npos);
}
TEST_CASE("Overhang fan transitions do not depend on overhang speed", "[Cooling][Regression]")
{
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
config.set_deserialize_strict({
{ "bridge_speed", 2.0 },
{ "enable_arc_fitting", false },
{ "enable_overhang_bridge_fan", true },
{ "enable_overhang_speed", false },
{ "initial_layer_print_height", 0.3 },
{ "inner_wall_speed", 30.0 },
{ "layer_height", 0.3 },
{ "outer_wall_speed", 30.0 },
{ "overhang_1_4_speed", "30" },
{ "overhang_2_4_speed", "29" },
{ "overhang_3_4_speed", "6" },
{ "overhang_4_4_speed", "3" },
{ "slow_down_for_layer_cooling", false },
{ "slowdown_for_curled_perimeters", false },
});
config.set_key_value("fan_max_speed", new ConfigOptionFloats{20.0});
config.set_key_value("fan_min_speed", new ConfigOptionFloats{20.0});
config.set_key_value("overhang_fan_speed", new ConfigOptionInts{100});
config.set_key_value("overhang_fan_threshold", new ConfigOptionEnumsGeneric{Overhang_threshold_2_4});
config.set_key_value("layer_change_gcode", new ConfigOptionString{";TEST_LAYER_Z=[layer_z]"});
const auto fan_commands = [](const std::string &gcode) {
std::vector<std::pair<std::string, std::string>> commands;
std::istringstream input(gcode);
std::string layer;
std::string line;
while (std::getline(input, line)) {
if (line.rfind(";TEST_LAYER_Z=", 0) == 0)
layer = line;
else if (!layer.empty() && (line.rfind("M106", 0) == 0 || line.rfind("M107", 0) == 0))
commands.emplace_back(layer, line);
}
return commands;
};
const auto feedrates = [](const std::string &gcode) {
std::vector<std::string> values;
std::istringstream input(gcode);
std::string word;
while (input >> word)
if (!word.empty() && word.front() == 'F')
values.push_back(word);
return values;
};
constexpr double sphere_radius = 50.0; // 100 mm diameter.
const std::string without_speed_gcode = slice({make_sphere(sphere_radius, PI / 24.0)}, config);
config.set_deserialize_strict({{"enable_overhang_speed", true}});
const std::string with_speed_gcode = slice({make_sphere(sphere_radius, PI / 24.0)}, config);
const auto without_speed_fan = fan_commands(without_speed_gcode);
const auto with_speed_fan = fan_commands(with_speed_gcode);
const auto without_speed_feedrates = feedrates(without_speed_gcode);
const auto with_speed_feedrates = feedrates(with_speed_gcode);
REQUIRE_FALSE(without_speed_fan.empty());
REQUIRE(std::any_of(without_speed_fan.begin(), without_speed_fan.end(),
[](const auto &command) { return command.second.find("S255") != std::string::npos; }));
REQUIRE(with_speed_feedrates != without_speed_feedrates);
CHECK(with_speed_fan == without_speed_fan);
}
+273
View File
@@ -9,6 +9,7 @@
#include <vector>
#include "libslic3r/ClipperUtils.hpp"
#include "libslic3r/AABBTreeLines.hpp"
#include "libslic3r/Fill/Fill.hpp"
#include "libslic3r/Flow.hpp"
#include "libslic3r/Geometry.hpp"
@@ -699,6 +700,213 @@ TEST_CASE("Solid infill direction offsets every layer when no template is set",
}
}
// Orca: the spiral inset pattern chains the concentric loops into a single continuous path per
// island, so it has to cope with the degenerate loops offsetting leaves behind and it must not join
// loops that only look adjacent.
namespace {
Slic3r::Polylines spiral_inset_fill(const Slic3r::ExPolygon &surface_shape, double spacing)
{
std::unique_ptr<Slic3r::Fill> filler(Slic3r::Fill::new_from_type("spiralinset"));
filler->spacing = spacing;
// Cancel the half-spacing contraction fill_surface() applies, so the filler sees the shape as given.
filler->overlap = 0.5 * spacing;
Slic3r::FillParams fill_params;
fill_params.density = 1.f;
fill_params.dont_adjust = true;
Slic3r::Surface surface(Slic3r::stBottom, surface_shape);
return filler->fill_surface(&surface, fill_params);
}
Slic3r::ExPolygon rectangle(double x, double y, double w, double h)
{
return Slic3r::ExPolygon({Slic3r::Point::new_scale(x, y), Slic3r::Point::new_scale(x + w, y),
Slic3r::Point::new_scale(x + w, y + h), Slic3r::Point::new_scale(x, y + h)});
}
// Area of the surface the toolpaths fail to cover, and the largest single patch of it, in mm2. Each
// bead is measured at its own width so the variable width walls are not sold short.
std::pair<double, double> uncovered_area(const Slic3r::ExPolygon &surface_shape, const Slic3r::Polygons &covered)
{
double total = 0, biggest = 0;
for (const Slic3r::ExPolygon &gap : Slic3r::diff_ex(Slic3r::ExPolygons{surface_shape}, Slic3r::union_(covered))) {
const double area = unscale<double>(unscale<double>(gap.area()));
total += area;
biggest = std::max(biggest, area);
}
return {total, biggest};
}
Slic3r::Polygons beads_of(const Slic3r::Polylines &paths, double width)
{
return Slic3r::offset(paths, float(scale_(0.5 * width)));
}
Slic3r::Polygons beads_of(const Slic3r::ThickPolylines &paths)
{
Slic3r::Polygons covered;
for (const Slic3r::ThickPolyline &path : paths)
for (size_t i = 0; i + 1 < path.points.size(); ++i) {
Slic3r::Polyline segment;
segment.points = {path.points[i], path.points[i + 1]};
Slic3r::append(covered, Slic3r::offset(Slic3r::Polylines{segment},
float(0.5 * std::max(path.width[2 * i], path.width[2 * i + 1]))));
}
return covered;
}
} // namespace
TEST_CASE("Spiral inset fill drops loops shorter than the end clipping", "[Fill][Regression]")
{
// A sliver whose whole perimeter is shorter than the length clipped off the end of a loop, so the
// clipping consumes the path entirely. Such a loop carries no extrusion and must be dropped
// rather than kept as an empty path and read back from.
const double spacing = 0.45;
Slic3r::Polylines paths;
REQUIRE_NOTHROW(paths = spiral_inset_fill(rectangle(0, 0, 0.05, 0.05), spacing));
for (const Slic3r::Polyline &path : paths)
CHECK(path.size() >= 2);
// The same surface at a size the clipping cannot swallow still gets filled.
REQUIRE_NOTHROW(paths = spiral_inset_fill(rectangle(0, 0, 5, 5), spacing));
REQUIRE(paths.size() == 1);
CHECK(paths.front().size() >= 2);
}
TEST_CASE("Spiral inset fill keeps separate islands on separate paths", "[Fill]")
{
// Two lobes joined by a neck narrower than the loop spacing: the inward offsets break the surface
// into two islands, which cannot share one spiral, and no path may leave the surface.
const double spacing = 0.45;
Slic3r::ExPolygon dumbbell = rectangle(0, 0, 6, 6);
dumbbell = Slic3r::union_ex(Slic3r::ExPolygons{dumbbell, rectangle(6, 2.9, 4, 0.2), rectangle(10, 0, 6, 6)}).front();
const Slic3r::Polylines paths = spiral_inset_fill(dumbbell, spacing);
REQUIRE(paths.size() >= 2);
// Inflate by a hair so that loops sitting exactly on the outline still count as contained.
const Slic3r::ExPolygons within = Slic3r::offset_ex(dumbbell, float(SCALED_EPSILON));
REQUIRE(within.size() == 1);
for (const Slic3r::Polyline &path : paths) {
CHECK(path.size() >= 2);
CHECK(within.front().contains(path));
}
}
TEST_CASE("Spiral inset fill stays connected across sharp corners", "[Fill][Regression]")
{
// At a corner of half-angle a, the next ring inward retreats along the bisector by spacing/sin(a),
// which leaves it several spacings from the end of the ring it continues. Judging the break by
// distance broke the spiral into loose rings at every spike; nesting is what decides the island.
const double spacing = 0.45;
const Slic3r::ExPolygon spike({Slic3r::Point::new_scale(0, 0), Slic3r::Point::new_scale(30, 0),
Slic3r::Point::new_scale(15, 4)});
const Slic3r::Polylines paths = spiral_inset_fill(spike, spacing);
CHECK(paths.size() == 1);
const Slic3r::ExPolygons within = Slic3r::offset_ex(spike, float(SCALED_EPSILON));
REQUIRE(within.size() == 1);
for (const Slic3r::Polyline &path : paths)
CHECK(within.front().contains(path));
}
TEST_CASE("Spiral inset fill starts on a convex corner", "[Fill][Regression]")
{
// The only right angle on this outline is the reflex one: the two edges meeting at the origin
// span 90 degrees exactly as a square corner would, but the material lies outside them. The next
// ring in steps away from a reflex corner along the bisector instead of hugging it, so starting
// the spiral there sent it across a long diagonal on every single ring.
const double spacing = 0.45;
const Slic3r::ExPolygon notched({Slic3r::Point::new_scale(0, 0), Slic3r::Point::new_scale(0, 10),
Slic3r::Point::new_scale(-16, 18), Slic3r::Point::new_scale(-16, -2),
Slic3r::Point::new_scale(-8, -16), Slic3r::Point::new_scale(18, -16),
Slic3r::Point::new_scale(10, 0)});
const Slic3r::Polylines paths = spiral_inset_fill(notched, spacing);
REQUIRE(paths.size() >= 1);
// Every edge of the outline is at least 45 degrees off the bisector of that reflex corner, and
// so is every ring offset from it. A long segment running along the bisector can therefore only
// be the spiral striking out across the rings to reach the next one.
for (const Slic3r::Polyline &path : paths)
for (const Slic3r::Line &segment : path.lines()) {
const Vec2d v = (segment.b - segment.a).cast<double>();
const double direction = std::fmod(std::atan2(v.y(), v.x()) * 180.0 / M_PI + 180.0, 180.0);
if (std::abs(direction - 45.0) > 25.0)
continue;
CAPTURE(direction, unscale<double>(segment.length()));
CHECK(segment.length() <= scale_(1.5 * spacing));
}
}
TEST_CASE("Spiral inset fill closes the gaps with variable width walls", "[Fill]")
{
// Fixed width loops cannot fill a region that is not a whole number of lines across and leave the
// remainder open, which on a ring shows up as a wedge several lines wide. Plain concentric avoids
// that by building solid surfaces out of Arachne's variable width walls, and so must this pattern.
const double spacing = 0.45;
Slic3r::ExPolygon ring = rectangle(0, 0, 24, 24);
Slic3r::Polygon hole;
for (int i = 0; i < 64; ++i) {
const double angle = -2.0 * PI * i / 64.0; // clockwise, so it reads as a hole
hole.points.emplace_back(Slic3r::Point::new_scale(12 + 7.3 * std::cos(angle), 12 + 7.3 * std::sin(angle)));
}
ring.holes.emplace_back(hole);
Slic3r::PrintConfig print_config;
Slic3r::PrintObjectConfig object_config;
auto make_filler = [&]() {
std::unique_ptr<Slic3r::Fill> filler(Slic3r::Fill::new_from_type("spiralinset"));
filler->spacing = spacing;
filler->overlap = 0.5 * spacing; // cancel the contraction, so both see the same surface
filler->print_config = &print_config;
filler->print_object_config = &object_config;
return filler;
};
Slic3r::FillParams params;
params.density = 1.f;
params.dont_adjust = false;
params.layer_height = 0.2;
const Slic3r::Surface surface(Slic3r::stTop, ring);
std::unique_ptr<Slic3r::Fill> fixed = make_filler();
const Slic3r::Polylines fixed_width = fixed->fill_surface(&surface, params);
REQUIRE(!fixed_width.empty());
const auto fixed_gaps = uncovered_area(ring, beads_of(fixed_width, fixed->spacing));
params.use_arachne = true;
std::unique_ptr<Slic3r::Fill> variable = make_filler();
const Slic3r::ThickPolylines variable_width = variable->fill_surface_arachne(&surface, params);
REQUIRE(!variable_width.empty());
const auto variable_gaps = uncovered_area(ring, beads_of(variable_width));
CAPTURE(fixed_gaps.first, fixed_gaps.second, variable_gaps.first, variable_gaps.second);
// The wedges the fixed width loops leave behind are what the variable width walls take up.
CHECK(variable_gaps.second < 0.5 * fixed_gaps.second);
CHECK(variable_gaps.first < fixed_gaps.first);
// And it is still a spiral: far fewer paths than the ring has loops.
// And the walls are still chained into spirals rather than printed one path per wall. The ring is
// at its narrowest (12 - 7.3) mm across and is filled from both sides, so it is at least this many
// walls thick there and thicker elsewhere. Arachne's short thin feature walls cannot join a spiral,
// so only the substantial paths count towards this.
const size_t walls_across = size_t(2.0 * (12.0 - 7.3) / spacing);
size_t spirals = 0;
for (const Slic3r::ThickPolyline &path : variable_width)
if (path.length() > scale_(10.0 * spacing))
++spirals;
CAPTURE(spirals, walls_across, variable_width.size(), fixed_width.size());
CHECK(2 * spirals < walls_across);
}
TEST_CASE("Honeycomb infill rounds its cell corners with the smooth factor", "[Fill]")
{
// A cell whose sides are several times the line width, so that the corners have room to be rounded.
@@ -1022,3 +1230,68 @@ TEST_CASE("Smoothing multiline lightning infill keeps its outlines connected", "
REQUIRE(smooth.point_count > sharp.point_count);
REQUIRE(smooth.sharp_turns < sharp.sharp_turns);
}
TEST_CASE("Sparse plane-path anchors match the printed infill", "[Fill][InternalBridge][Regression]")
{
// Orca: Compare generated anchors with actual extrusion across plane-path patterns,
// smoothing, multiline and rotations; an origin shift must not pass as valid support.
const std::string pattern = GENERATE("hilbertcurve", "octagramspiral", "archimedeanchords");
const std::string smoothing = GENERATE("0%", "100%");
const int multiline = GENERATE(1, 2);
const bool rotated = GENERATE(false, true);
const bool separated = GENERATE(false, true);
CAPTURE(pattern, smoothing, multiline, rotated, separated);
auto config = DynamicPrintConfig::full_print_config();
config.set_deserialize_strict({{"sparse_infill_pattern", pattern},
{"sparse_infill_density", "15%"},
{"sparse_infill_smooth_factor", smoothing},
{"fill_multiline", multiline},
{"infill_direction", 45},
{"sparse_infill_rotate_template", rotated ? "0,25,50" : ""},
{"align_infill_direction_to_model", rotated},
{"separated_infills", separated},
{"top_shell_layers", 0},
{"bottom_shell_layers", 0},
{"top_shell_thickness", 0},
{"bottom_shell_thickness", 0},
{"layer_height", 0.2},
{"initial_layer_print_height", 0.2},
{"resolution", 0.012}});
Print print;
Model model;
TriangleMesh mesh = make_cube(30, 24, 1);
if (separated) {
// Orca: Two disconnected bodies in one object must each use their own infill origin.
TriangleMesh second = make_cube(30, 24, 1);
second.translate(50, 0, 0);
mesh.merge(second);
}
Slic3r::Test::init_print({mesh}, print, model, config, nullptr, false);
if (rotated) {
model.objects.front()->instances.front()->set_rotation(Vec3d(0., 0., Geometry::deg2rad(23.)));
print.apply(model, config);
}
print.process();
const Layer &layer = *print.objects().front()->get_layer(4);
Polylines printed;
for (const LayerRegion *region : layer.regions())
for (const ExtrusionEntity *entity : region->fills.flatten().entities)
if (entity->role() == erInternalInfill)
entity->collect_polylines(printed);
REQUIRE_FALSE(printed.empty());
const AABBTreeLines::LinesDistancer<Line> printed_tree(to_lines(printed));
// Orca: Exclude perimeter connections: anchoring and extrusion can trim those differently.
const Polylines anchors = intersection_pl(layer.generate_sparse_infill_polylines_for_anchoring(nullptr, nullptr, nullptr),
shrink(to_polygons(layer.lslices), scale_(3.)));
REQUIRE_FALSE(anchors.empty());
double max_distance = 0.;
for (const Polyline &path : anchors)
for (const Point &point : path.equally_spaced_points(scale_(0.25)))
max_distance = std::max(max_distance, printed_tree.distance_from_lines<false>(point));
// Orca: Allow only the configured simplification tolerance; infill-scale offsets
// would hide anchors that no longer coincide with printed lines.
CHECK(unscale<double>(max_distance) <= config.opt_float("resolution"));
}
+3
View File
@@ -618,6 +618,9 @@ static DynamicPrintConfig dual_extruder_toolchange_config()
config.set_key_value("nozzle_temperature_range_high", new ConfigOptionInts({240, 240}));
config.set_key_value("flush_multiplier", new ConfigOptionFloats({1}));
config.set_key_value("flush_volumes_matrix", new ConfigOptionFloats({0, 140, 140, 0}));
// Inside the 200x200 test bed; the default y, 220, is not, and generation rejects that.
config.set_key_value("wipe_tower_x", new ConfigOptionFloats({50.}));
config.set_key_value("wipe_tower_y", new ConfigOptionFloats({50.}));
return config;
}
+442
View File
@@ -4,11 +4,18 @@
#include "libslic3r/Print.hpp"
#include "libslic3r/Layer.hpp"
#include "libslic3r/GCodeReader.hpp"
#include "libslic3r/ClipperUtils.hpp"
#include "libslic3r/AABBTreeLines.hpp"
#include "test_helpers.hpp"
#include <cmath>
#include <iterator>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace Slic3r;
using namespace Slic3r::Test;
@@ -130,3 +137,438 @@ TEST_CASE("Initial layer height is honored", "[PrintObject]")
REQUIRE_THAT(*layer_zs.begin(), Catch::Matchers::WithinAbs(0.3, 1e-4));
REQUIRE_THAT(*std::next(layer_zs.begin()), Catch::Matchers::WithinAbs(0.5, 1e-4));
}
static TriangleMesh internal_bridge_step()
{
// Orca: The smaller tower leaves a shoulder whose solid skin needs internal bridges
// over the sparse infill in the base, without relying on an external model file.
TriangleMesh mesh = make_cube(30, 24, 3);
TriangleMesh tower = make_cube(14, 10, 1);
tower.translate(8, 7, 3);
mesh.merge(tower);
return mesh;
}
static DynamicPrintConfig internal_bridge_config(const std::string &pattern, int multiline)
{
auto config = DynamicPrintConfig::full_print_config();
config.set_deserialize_strict({{"sparse_infill_pattern", pattern},
{"fill_multiline", multiline},
{"sparse_infill_density", "15%"},
{"sparse_infill_smooth_factor", "100%"},
{"infill_direction", 45},
{"internal_bridge_angle", 0},
{"thick_internal_bridges", true},
{"top_shell_layers", 3},
{"bottom_shell_layers", 2},
{"top_shell_thickness", 0},
{"bottom_shell_thickness", 0},
{"layer_height", 0.2},
{"initial_layer_print_height", 0.2}});
return config;
}
TEST_CASE("Internal bridge angles follow the lower infill layer and model rotation", "[PrintObject][InternalBridge][Regression]")
{
const std::string pattern = GENERATE("hilbertcurve", "octagramspiral");
// Orca: Cover both a central line (odd counts) and offset pairs (even counts).
const int multiline = GENERATE(1, 2, 3);
CAPTURE(multiline);
const double rotation = GENERATE(23., -123.);
const std::vector<double> cycle{10., 30., 70.};
auto config = internal_bridge_config(pattern, multiline);
config.set_deserialize_strict({{"sparse_infill_rotate_template", "10,30,70"},
{"align_infill_direction_to_model", true},
{"separated_infills", false}});
Print print;
Model model;
init_print({internal_bridge_step()}, print, model, config, nullptr, false);
model.objects.front()->instances.front()->set_rotation(Vec3d(0., 0., Geometry::deg2rad(rotation)));
print.apply(model, config);
print.process();
const PrintObject &object = *print.objects().front();
size_t bridges = 0;
for (size_t i = 1; i < object.layer_count(); ++i) {
// Orca: The support is one layer below the bridge. Check the template and model
// rotation together, including normalization when the resulting angle is negative.
double expected = std::fmod(cycle[(i - 1) % cycle.size()] + 90. + rotation, 180.);
if (expected < 0.) expected += 180.;
for (const LayerRegion *region : object.get_layer(i)->regions())
for (const Surface *surface : region->fill_surfaces.filter_by_type(stInternalBridge)) {
CAPTURE(pattern, rotation, i);
CHECK_THAT(Geometry::rad2deg(surface->bridge_angle), Catch::Matchers::WithinAbs(expected, 0.001));
++bridges;
}
}
REQUIRE(bridges > 0);
}
TEST_CASE("Turning infill does not replace the anchors of another region", "[PrintObject][InternalBridge][Regression]")
{
// Orca: Keep the right-hand region fixed while changing the left-hand pattern in the
// same object. Its bridge areas must be independent of a previous candidate's anchors.
const int multiline = GENERATE(1, 2, 3);
CAPTURE(multiline);
auto right_bridges = [multiline](const std::string &left_pattern) {
auto config = internal_bridge_config(left_pattern, multiline);
Print print;
Model model;
init_print({internal_bridge_step()}, print, model, config, nullptr, false);
TriangleMesh right = internal_bridge_step();
right.translate(50, 0, 0);
ModelVolume *volume = model.objects.front()->add_volume(std::move(right));
volume->config.set_key_value("sparse_infill_pattern", new ConfigOptionEnum<InfillPattern>(ipRectilinear));
volume->config.set_key_value("infill_direction", new ConfigOptionFloat(17.));
print.apply(model, config);
print.process();
std::map<size_t, Polygons> result;
const PrintObject &object = *print.objects().front();
for (size_t i = 0; i < object.layer_count(); ++i)
for (const LayerRegion *region : object.get_layer(i)->regions())
if (region->region().config().infill_direction == 17.)
polygons_append(result[i], to_polygons(region->fill_surfaces.filter_by_type(stInternalBridge)));
return result;
};
const auto baseline = right_bridges("rectilinear");
const auto actual = right_bridges(GENERATE("hilbertcurve", "octagramspiral"));
REQUIRE(actual.size() == baseline.size());
double total_area = 0.;
for (const auto &[layer, expected] : baseline) {
CAPTURE(layer);
const auto &polys = actual.at(layer);
CHECK(area(diff(expected, polys)) < scaled<double>(1.) * scaled<double>(1.) * 1e-6);
CHECK(area(diff(polys, expected)) < scaled<double>(1.) * scaled<double>(1.) * 1e-6);
total_area += area(expected);
}
REQUIRE(total_area > 0.);
}
TEST_CASE("Rounded internal bridges end on printed support", "[PrintObject][InternalBridge][Regression]")
{
const std::string pattern = GENERATE("hilbertcurve", "octagramspiral");
const bool separated = GENERATE(false, true);
CAPTURE(pattern, separated);
auto config = internal_bridge_config(pattern, 1);
config.set_deserialize_strict({{"infill_wall_overlap", "0%"}, {"separated_infills", separated}});
TriangleMesh mesh = internal_bridge_step();
if (separated) {
TriangleMesh second = internal_bridge_step();
second.translate(50, 0, 0);
mesh.merge(second);
}
Print print;
Model model;
init_print({mesh}, print, model, config, nullptr, false);
print.process();
// Orca: Check final extrusion endpoints after polygon cleanup and fill generation.
// A correct bridge angle and correct sparse anchors alone do not guarantee contact.
const PrintObject &object = *print.objects().front();
size_t checked = 0;
for (size_t i = 1; i < object.layer_count(); ++i) {
Polygons support;
Polylines walls;
for (const LayerRegion *region : object.get_layer(i - 1)->regions()) {
region->perimeters.polygons_covered_by_width(support, 0.f);
region->fills.polygons_covered_by_width(support, 0.f);
region->perimeters.collect_polylines(walls);
}
REQUIRE_FALSE(support.empty());
const AABBTreeLines::LinesDistancer<Line> support_tree(to_lines(union_(support)));
const AABBTreeLines::LinesDistancer<Line> wall_tree(to_lines(walls));
for (const LayerRegion *region : object.get_layer(i)->regions())
for (const ExtrusionEntity *entity : region->fills.flatten().entities) {
if (entity->role() != erInternalBridgeInfill)
continue;
const auto *path = dynamic_cast<const ExtrusionPath *>(entity);
REQUIRE(path != nullptr);
for (const Line &line : path->polyline.to_polyline().lines()) {
// Orca: Sample span ends, excluding short connectors and wall overlap.
if (line.length() < scale_(std::max(0.7, 3. * path->width)))
continue;
for (const Point &point : {line.a, line.b}) {
if (wall_tree.distance_from_lines<false>(point) <= scale_(0.5))
continue;
CAPTURE(i, point.x(), point.y());
const double gap = unscale<double>(support_tree.distance_from_lines<true>(point)) - 0.5 * path->width;
CHECK(gap <= 0.1);
++checked;
}
}
}
}
REQUIRE(checked > 0);
}
TEST_CASE("Enabling separated infill recomputes body origins", "[PrintObject][InternalBridge][Regression]")
{
const std::string pattern = GENERATE("hilbertcurve", "octagramspiral", "archimedeanchords");
CAPTURE(pattern);
auto footprint = [&](bool reslice) {
auto config = internal_bridge_config(pattern, 2);
config.set_deserialize_strict({{"separated_infills", !reslice}});
TriangleMesh mesh = internal_bridge_step();
TriangleMesh second = internal_bridge_step();
second.translate(50, 0, 0);
mesh.merge(second);
Print print;
Model model;
init_print({mesh}, print, model, config, nullptr, false);
print.process();
if (reslice) {
// Orca: Enabling centering after a completed slice must rebuild the body
// origins now shared by bridge preparation and printed infill.
config.set_deserialize_strict({{"separated_infills", true}});
print.apply(model, config);
print.process();
}
Polygons result;
for (const LayerRegion *region : print.objects().front()->get_layer(4)->regions())
region->fills.polygons_covered_by_width(result, 0.f);
return union_(result);
};
const Polygons fresh = footprint(false);
const Polygons resliced = footprint(true);
REQUIRE_FALSE(fresh.empty());
CHECK(area(diff(fresh, resliced)) < scaled<double>(1.) * scaled<double>(1.) * 1e-6);
CHECK(area(diff(resliced, fresh)) < scaled<double>(1.) * scaled<double>(1.) * 1e-6);
}
TEST_CASE("Surface centering survives changes to separated infill settings", "[PrintObject][SurfaceInfill][Regression]")
{
const std::string pattern = GENERATE("archimedeanchords", "octagramspiral");
const std::string initial_center = GENERATE("each_surface", "each_model", "each_assembly");
const std::string final_center = GENERATE("each_surface", "each_model", "each_assembly");
const bool separated = GENERATE(false, true);
const std::string top_order = GENERATE("default", "outward", "inward");
const std::string bottom_order = top_order == "outward" ? "inward" : top_order == "inward" ? "outward" : "default";
const std::string density = GENERATE("80%", "100%");
const bool change_center = initial_center != final_center;
CAPTURE(pattern, initial_center, final_center, separated, top_order, bottom_order, density);
auto config = DynamicPrintConfig::full_print_config();
config.set_deserialize_strict({{"top_surface_pattern", pattern},
{"bottom_surface_pattern", pattern},
{"top_surface_fill_order", top_order},
{"bottom_surface_fill_order", bottom_order},
{"top_surface_density", density},
{"bottom_surface_density", density},
{"center_of_surface_pattern", initial_center},
{"separated_infills", change_center ? separated : !separated},
{"sparse_infill_pattern", "rectilinear"},
{"sparse_infill_density", "15%"},
{"top_shell_layers", 2},
{"bottom_shell_layers", 2},
{"top_shell_thickness", 0},
{"bottom_shell_thickness", 0},
{"layer_height", 0.2},
{"initial_layer_print_height", 0.2}});
// Orca: Two disconnected bodies exercise per-body centering. The offset tower also
// makes each-surface and each-model centering differ on the top surfaces.
TriangleMesh mesh = make_cube(30, 24, 2);
TriangleMesh tower = make_cube(12, 10, 1);
tower.translate(4, 3, 2);
mesh.merge(tower);
TriangleMesh second = mesh;
second.translate(50, 0, 0);
mesh.merge(second);
// Orca: Equal footprints can hide reordered or reversed paths. Retain their point
// sequences and ordering protection to cover the directional surface behavior too.
struct SurfaceFillSnapshot {
std::map<bool, std::vector<Points>> paths;
bool protected_order = true;
};
auto surface_fills = [](const Print &print) {
std::map<std::pair<size_t, ExtrusionRole>, SurfaceFillSnapshot> result;
const PrintObject &object = *print.objects().front();
for (size_t i = 0; i < object.layer_count(); ++i) {
auto collect = [&](const auto &self, const ExtrusionEntity &entity, bool no_sort) -> void {
if (const auto *collection = dynamic_cast<const ExtrusionEntityCollection *>(&entity)) {
for (const ExtrusionEntity *child : collection->entities)
self(self, *child, no_sort || collection->no_sort);
} else if (entity.role() == erTopSolidInfill || entity.role() == erBottomSurface) {
const auto *path = dynamic_cast<const ExtrusionPath *>(&entity);
REQUIRE(path != nullptr);
auto &snapshot = result[{i, entity.role()}];
// Orca: The centered test model has one body on either side of X=0.
// Their traversal order may vary; preserve path order within each body.
Points points = path->polyline.to_polyline().points;
REQUIRE_FALSE(points.empty());
snapshot.paths[points.front().x() > 0].push_back(std::move(points));
snapshot.protected_order &= no_sort && !path->can_reverse();
}
};
for (const LayerRegion *region : object.get_layer(i)->regions())
collect(collect, region->fills, false);
}
return result;
};
Print print;
Model model;
init_print({mesh}, print, model, config, nullptr, false);
print.process();
const auto initial = surface_fills(print);
config.set_deserialize_strict({{"center_of_surface_pattern", final_center}, {"separated_infills", separated}});
print.apply(model, config);
// Orca: Preparation owns the body origins, and its invalidation must also force
// regeneration of top/bottom extrusion paths, even when sparse infill is unchanged.
CHECK_FALSE(print.objects().front()->is_step_done(posPrepareInfill));
CHECK_FALSE(print.objects().front()->is_step_done(posInfill));
print.process();
const auto resliced = surface_fills(print);
Print fresh_print;
Model fresh_model;
init_print({mesh}, fresh_print, fresh_model, config, nullptr, false);
fresh_print.process();
const auto fresh = surface_fills(fresh_print);
REQUIRE_FALSE(fresh.empty());
REQUIRE(resliced.size() == fresh.size());
std::set<ExtrusionRole> roles;
bool changed_paths = false;
for (const auto &entry : fresh) {
CAPTURE(entry.first.first, entry.first.second);
REQUIRE_FALSE(entry.second.paths.empty());
roles.insert(entry.first.second);
REQUIRE(resliced.count(entry.first) == 1);
REQUIRE(initial.count(entry.first) == 1);
const auto &actual = resliced.at(entry.first);
const auto &expected = entry.second;
const auto &before = initial.at(entry.first);
CHECK((actual.paths == expected.paths));
if (!change_center)
CHECK((actual.paths == before.paths));
if (top_order != "default") {
CHECK(expected.protected_order);
CHECK(actual.protected_order);
CHECK(before.protected_order);
}
changed_paths |= expected.paths != before.paths;
}
CHECK(roles.count(erTopSolidInfill) == 1);
CHECK(roles.count(erBottomSurface) == 1);
// Orca: Guard against a vacuous comparison: changing surface centering must change
// the printed pattern, while toggling separated sparse infill must leave it alone.
CHECK(changed_paths == change_center);
}
TEST_CASE("Separated infill keeps fragmented and nested bodies independent", "[PrintObject][SurfaceInfill][Regression]")
{
constexpr size_t grid_size = 8;
TriangleMesh mesh;
auto add_box = [&](double x, double y, double width, double depth) {
TriangleMesh box = make_cube(width, depth, 0.6);
box.translate(x, y, 0);
mesh.merge(box);
};
// Orca: Many small islands exercise spatial pruning and the tree's original
// island indices. A pillar inside a frame also overlaps its bounding box,
// but must remain a separate body because it lies entirely inside the hole.
for (size_t x = 0; x < grid_size; ++ x)
for (size_t y = 0; y < grid_size; ++ y)
add_box(6 * x, 6 * y, 3, 3);
add_box(54, 0, 20, 4);
add_box(54, 16, 20, 4);
add_box(54, 0, 4, 20);
add_box(70, 0, 4, 20);
add_box(62, 8, 4, 4);
auto config = DynamicPrintConfig::full_print_config();
config.set_deserialize_strict({{"separated_infills", true},
{"center_of_surface_pattern", "each_surface"},
{"layer_height", 0.2},
{"initial_layer_print_height", 0.2},
{"elefant_foot_compensation", 0},
{"wall_loops", 1}});
Print print;
Model model;
init_print({mesh}, print, model, config, nullptr, false);
// Orca: Prepare body bounds through the public pipeline, then inspect the object read-only.
print.process();
const PrintObject &object = *print.objects().front();
REQUIRE(object.layer_count() > 1);
for (const Layer *layer : object.layers()) {
REQUIRE(layer->lslices.size() == grid_size * grid_size + 2);
REQUIRE(layer->lslices_separated_component_bboxes.size() == layer->lslices.size());
size_t holes = 0;
for (size_t i = 0; i < layer->lslices.size(); ++ i) {
const BoundingBox &body = layer->lslices_separated_component_bboxes[i];
const BoundingBox &island = layer->lslices_bboxes[i];
CHECK(body.min == island.min);
CHECK(body.max == island.max);
holes += layer->lslices[i].holes.size();
}
CHECK(holes == 1);
}
}
TEST_CASE("Body centering survives islands merging and splitting between layers", "[PrintObject][SurfaceInfill][Regression]")
{
const bool separated = GENERATE(false, true);
CAPTURE(separated);
// Orca: Four posts join through horizontal then vertical rails, creating a
// cycle of overlaps before splitting into four islands again. This exercises
// redundant connections and indexing either adjacent layer. A fifth post
// stays separate at every height.
TriangleMesh mesh;
for (int x : {0, 8})
for (int y : {0, 8}) {
TriangleMesh post = make_cube(4, 4, 1);
post.translate(x, y, 0);
mesh.merge(post);
}
for (int y : {0, 8}) {
TriangleMesh rail = make_cube(12, 4, 0.2);
rail.translate(0, y, 0.2);
mesh.merge(rail);
}
for (int x : {0, 8}) {
TriangleMesh rail = make_cube(4, 12, 0.2);
rail.translate(x, 0, 0.4);
mesh.merge(rail);
}
TriangleMesh isolated = make_cube(4, 4, 1);
isolated.translate(20, 0, 0);
mesh.merge(isolated);
auto config = DynamicPrintConfig::full_print_config();
config.set_deserialize_strict({{"separated_infills", separated},
{"center_of_surface_pattern", separated ? "each_surface" : "each_model"},
{"layer_height", 0.2},
{"initial_layer_print_height", 0.2},
{"elefant_foot_compensation", 0},
{"wall_loops", 1}});
Print print;
Model model;
init_print({mesh}, print, model, config, nullptr, false);
// Orca: Prepare body bounds through the public pipeline, then inspect the object read-only.
print.process();
const PrintObject &object = *print.objects().front();
REQUIRE(object.layer_count() == 5);
REQUIRE(object.get_layer(0)->lslices.size() == 5);
REQUIRE(object.get_layer(1)->lslices.size() == 3);
REQUIRE(object.get_layer(2)->lslices.size() == 3);
REQUIRE(object.get_layer(4)->lslices.size() == 5);
BoundingBox isolated_bbox = object.get_layer(0)->lslices_bboxes.front();
for (const BoundingBox &bbox : object.get_layer(0)->lslices_bboxes)
if (bbox.min.x() > isolated_bbox.min.x())
isolated_bbox = bbox;
BoundingBox connected_bbox;
for (const Layer *layer : object.layers())
for (const BoundingBox &bbox : layer->lslices_bboxes)
if (bbox.min.x() < isolated_bbox.min.x())
connected_bbox.merge(bbox);
for (const Layer *layer : object.layers()) {
REQUIRE(layer->lslices_separated_component_bboxes.size() == layer->lslices.size());
for (size_t i = 0; i < layer->lslices.size(); ++ i) {
const BoundingBox &expected = layer->lslices_bboxes[i].min.x() < isolated_bbox.min.x() ? connected_bbox : isolated_bbox;
const BoundingBox &actual = layer->lslices_separated_component_bboxes[i];
CHECK(actual.min == expected.min);
CHECK(actual.max == expected.max);
}
}
}
+1 -1
View File
@@ -1086,7 +1086,7 @@ TEST_CASE("Belt brim lines all have the same width", "[SkirtBrim][belt]")
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));
CHECK_THAT(hi, Catch::Matchers::WithinRel(lo, 1e-4f));
}
TEST_CASE("Belt apron survives another object printing at the same Z", "[SkirtBrim][belt]")
+361
View File
@@ -3,11 +3,103 @@
#include "libslic3r/GCodeReader.hpp"
#include "libslic3r/Layer.hpp"
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include "test_helpers.hpp" // get access to init_print, etc
// Not self-contained: its inline constructor uses PrintObject, PrintRegion, SlicingParameters and
// Geometry, so it must follow the headers (pulled in via test_helpers.hpp) that define them.
#include "libslic3r/Support/SupportParameters.hpp"
using namespace Slic3r::Test;
using namespace Slic3r;
// Distinct layer Z heights carrying support interface extrusion.
static size_t support_interface_layer_count(const std::string &gcode)
{
return layers_with_role(gcode, "support material interface").size();
}
// Distinct layer Z heights carrying support base extrusion. The base G-code label "support material"
// is a substring of "support material interface", so a base line is a support line that is not an
// interface line.
static size_t support_base_layer_count(const std::string &gcode)
{
std::set<double> layers;
GCodeReader parser;
parser.parse_buffer(gcode, [&layers](GCodeReader &self, const GCodeReader::GCodeLine &line) {
if (! line.extruding(self)) return;
const std::string_view comment = line.comment();
if (comment.find("support material") != std::string_view::npos &&
comment.find("interface") == std::string_view::npos)
layers.insert(self.z());
});
return layers.size();
}
// Dominant support-interface fill direction per interface layer, in radians [0, pi). Uses the
// length-weighted axial mean (each segment angle doubled so a line and its reverse agree, then
// halved): the parallel infill lines reinforce while the surrounding perimeter cancels.
static std::map<double, double> interface_fill_angle_by_layer(const std::string &gcode)
{
std::map<double, std::pair<double, double>> acc; // z -> summed length*(cos2a, sin2a)
GCodeReader parser;
parser.parse_buffer(gcode, [&acc](GCodeReader &self, const GCodeReader::GCodeLine &line) {
if (! line.extruding(self)) return;
if (line.comment().find("support material interface") == std::string_view::npos) return;
const double dx = line.dist_X(self), dy = line.dist_Y(self);
const double len = std::hypot(dx, dy);
if (len < 1e-6) return;
const double a2 = 2.0 * std::atan2(dy, dx);
auto &p = acc[self.z()];
p.first += len * std::cos(a2);
p.second += len * std::sin(a2);
});
std::map<double, double> out;
for (const auto &kv : acc) {
double a = 0.5 * std::atan2(kv.second.second, kv.second.first);
if (a < 0) a += M_PI;
out[kv.first] = a;
}
return out;
}
// Acute angle (degrees) between two axial fill directions in [0, pi).
static double axial_angle_diff_deg(double a, double b)
{
const double d = std::fmod(std::fabs(a - b), M_PI);
return std::min(d, M_PI - d) * 180.0 / M_PI;
}
// Denser interface spacing yields more extruded length.
static double support_interface_extrusion_length(const std::string &gcode)
{
double len = 0;
GCodeReader parser;
parser.parse_buffer(gcode, [&len](GCodeReader &self, const GCodeReader::GCodeLine &line) {
if (! line.extruding(self)) return;
if (line.comment().find("support material interface") == std::string_view::npos) return;
len += std::hypot(line.dist_X(self), line.dist_Y(self));
});
return len;
}
// A cap slab overhanging a base, joined by a central stem: the cap can only be supported by resting on the
// base, forcing a genuine bottom contact. A horizontal tunnel does not work here -- tree/organic can arch a
// branch in from the opening and avoid the floor entirely.
static TriangleMesh support_capital()
{
TriangleMesh model = make_cube(40, 40, 2); // base [0,40]x[0,40]x[0,2]
TriangleMesh stem = make_cube(8, 8, 12); stem.translate(16, 16, 1); // stem centered, z 1..13
TriangleMesh cap = make_cube(40, 40, 2); cap.translate(0, 0, 12); // cap z 12..14
model.merge(stem);
model.merge(cap);
return model;
}
TEST_CASE("Three raft layers are created", "[SupportMaterial]")
{
Slic3r::Print print;
@@ -104,3 +196,272 @@ TEST_CASE("Support G-code emission survives a second slice in the same process",
const std::string second = slice({ TestMesh::overhang }, { { "enable_support", 1 } });
REQUIRE(! layers_with_role(second, "support").empty());
}
// The contact layer counts toward the configured interface layer count, so N configured top
// interface layers produce exactly N interface layers, not N+1.
TEST_CASE("Support top interface layer count matches the configured value", "[SupportMaterial]")
{
const int top = GENERATE(1, 2, 3, 4, 6);
const std::string g = slice({ TestMesh::overhang }, {
{ "enable_support", 1 },
{ "layer_height", 0.2 },
{ "support_on_build_plate_only", 1 },
{ "support_interface_top_layers", top },
{ "support_interface_bottom_layers", 0 },
});
CAPTURE(top);
REQUIRE(support_base_layer_count(g) > 0); // support actually formed
REQUIRE(support_interface_layer_count(g) == size_t(top));
}
// A rotated cube-with-hole is a horizontal tunnel whose ceiling and floor both receive support, so top
// and bottom interfaces can be exercised independently (the floor is the bottom contact).
static TriangleMesh support_tunnel()
{
TriangleMesh tunnel = Slic3r::Test::mesh(TestMesh::cube_with_hole);
tunnel.rotate_x(float(M_PI / 2));
return tunnel;
}
static size_t tunnel_interface_layers(const TriangleMesh &tunnel, int top, int bottom)
{
const std::string g = slice({ tunnel }, {
{ "enable_support", 1 },
{ "layer_height", 0.2 },
{ "support_on_build_plate_only", 0 },
{ "support_interface_top_layers", top },
{ "support_interface_bottom_layers", bottom },
});
REQUIRE(support_base_layer_count(g) > 0); // support actually formed
return support_interface_layer_count(g);
}
TEST_CASE("No support interface is generated when neither top nor bottom is configured", "[SupportMaterial]")
{
REQUIRE(tunnel_interface_layers(support_tunnel(), 0, 0) == 0);
}
TEST_CASE("Bottom interface layer count matches its setting with top interface off", "[SupportMaterial]")
{
const int bottom = GENERATE(1, 3, 6);
CAPTURE(bottom);
REQUIRE(tunnel_interface_layers(support_tunnel(), 0, bottom) == size_t(bottom));
}
// support_interface_bottom_layers = -1 means "same as top".
TEST_CASE("Support interface bottom layers default to the top layer count", "[SupportMaterial]")
{
const TriangleMesh tunnel = support_tunnel();
REQUIRE(tunnel_interface_layers(tunnel, 0, -1) == tunnel_interface_layers(tunnel, 0, 0));
REQUIRE(tunnel_interface_layers(tunnel, 3, -1) == tunnel_interface_layers(tunnel, 3, 3));
}
TEST_CASE("Default support still emits base and interface material", "[SupportMaterial][Regression]")
{
const std::string g = slice({ TestMesh::overhang }, { { "enable_support", 1 } });
REQUIRE(support_base_layer_count(g) > 0);
REQUIRE(support_interface_layer_count(g) > 0);
}
// Organic runs TreeSupport3D + TreeModelVolumes, the others the classic TreeSupport.cpp path.
TEST_CASE("Every tree support style produces base and interface material", "[SupportMaterial]")
{
const char *style = GENERATE("organic", "tree_slim", "tree_strong", "tree_hybrid");
INFO("style=" << style);
const std::string g = slice({ TestMesh::overhang }, {
{ "enable_support", 1 },
{ "layer_height", 0.2 },
{ "support_type", "tree(auto)" },
{ "support_style", style },
{ "support_interface_top_layers", 3 },
});
CHECK(support_base_layer_count(g) > 0);
CHECK(support_interface_layer_count(g) > 0);
}
TEST_CASE("Raft interface angle alternates by 45 degrees per interface id", "[SupportMaterial]")
{
Slic3r::Print print;
Slic3r::Test::init_and_process_print({ TestMesh::overhang }, print, { { "enable_support", 1 } });
SupportParameters sp(*print.objects().front());
sp.raft_angle_interface = 0.5f;
REQUIRE_THAT(sp.raft_interface_angle(0), Catch::Matchers::WithinAbs(0.5 + M_PI / 4., 1e-6));
REQUIRE_THAT(sp.raft_interface_angle(1), Catch::Matchers::WithinAbs(0.5 - M_PI / 4., 1e-6));
}
// The angle inputs are overwritten directly, so the pattern-to-angle mapping is checked
// independently of the sliced object's configuration.
TEST_CASE("Support interface fill angle follows the configured interface pattern", "[SupportMaterial]")
{
Slic3r::Print print;
Slic3r::Test::init_and_process_print({ TestMesh::overhang }, print, { { "enable_support", 1 } });
SupportParameters sp(*print.objects().front());
sp.interface_angle = 0.3f;
sp.base_angle = 1.1f;
const double tol = 1e-6;
SECTION("Rectilinear shifts the interface angle by -45deg for snug support") {
sp.support_interface_pattern = smipRectilinear;
sp.support_style = smsSnug;
REQUIRE_THAT(sp.support_interface_angle(0), Catch::Matchers::WithinAbs(sp.interface_angle - M_PI_4, tol));
REQUIRE_THAT(sp.support_interface_angle(3), Catch::Matchers::WithinAbs(sp.interface_angle - M_PI_4, tol));
}
SECTION("Rectilinear leaves the interface angle alone for the other styles") {
sp.support_interface_pattern = smipRectilinear;
sp.support_style = smsGrid;
REQUIRE_THAT(sp.support_interface_angle(0), Catch::Matchers::WithinAbs(sp.interface_angle, tol));
}
SECTION("Rectilinear interlaced alternates -/+45deg by interface id parity") {
sp.support_interface_pattern = smipRectilinearInterlaced;
REQUIRE_THAT(sp.support_interface_angle(0), Catch::Matchers::WithinAbs(sp.interface_angle - M_PI_4, tol));
REQUIRE_THAT(sp.support_interface_angle(1), Catch::Matchers::WithinAbs(sp.interface_angle + M_PI_4, tol));
}
SECTION("Grid uses the base angle") {
sp.support_interface_pattern = smipGrid;
REQUIRE_THAT(sp.support_interface_angle(0), Catch::Matchers::WithinAbs(sp.base_angle, tol));
}
SECTION("Auto and concentric use the interface angle unchanged") {
sp.support_interface_pattern = smipAuto;
REQUIRE_THAT(sp.support_interface_angle(0), Catch::Matchers::WithinAbs(sp.interface_angle, tol));
sp.support_interface_pattern = smipConcentric;
REQUIRE_THAT(sp.support_interface_angle(0), Catch::Matchers::WithinAbs(sp.interface_angle, tol));
}
}
// End-to-end that the pattern reaches the emitted fill, not just support_interface_angle().
TEST_CASE("Interlaced support interface alternates fill angle while rectilinear does not", "[SupportMaterial]")
{
auto interface_angles = [](const char *pattern) {
std::vector<double> a;
for (const auto &kv : interface_fill_angle_by_layer(slice({ TestMesh::overhang }, {
{ "enable_support", 1 },
{ "layer_height", 0.2 },
{ "support_on_build_plate_only", 1 },
{ "support_interface_top_layers", 6 },
{ "support_interface_pattern", pattern } })))
a.push_back(kv.second);
return a;
};
const std::vector<double> rectilinear = interface_angles("rectilinear");
const std::vector<double> interlaced = interface_angles("rectilinear_interlaced");
REQUIRE(rectilinear.size() >= 3);
REQUIRE(interlaced.size() >= 3);
for (size_t i = 1; i < rectilinear.size(); ++i)
REQUIRE(axial_angle_diff_deg(rectilinear[i], rectilinear[0]) < 15.0);
for (size_t i = 1; i < interlaced.size(); ++i)
REQUIRE(axial_angle_diff_deg(interlaced[i], interlaced[i - 1]) > 60.0);
}
// Normal and non-organic tree support share the same interface angle logic: with a rectilinear interface
// pattern both emit their interface fill at the same angle (both go through support_interface_angle()).
TEST_CASE("Normal and tree support use the same interface fill angle", "[SupportMaterial]")
{
auto mean_interface_angle = [](const char *type, const char *style) {
const auto angles = interface_fill_angle_by_layer(slice({ TestMesh::overhang }, {
{ "enable_support", 1 }, { "layer_height", 0.2 }, { "support_on_build_plate_only", 1 },
{ "support_type", type }, { "support_style", style },
{ "support_interface_top_layers", 6 }, { "support_interface_pattern", "rectilinear" } }));
REQUIRE(angles.size() >= 3);
// Axial mean, as in interface_fill_angle_by_layer: a plain mean would split angles either
// side of the [0, pi) wrap.
double x = 0, y = 0;
for (const auto &kv : angles) {
x += std::cos(2.0 * kv.second);
y += std::sin(2.0 * kv.second);
}
double mean = 0.5 * std::atan2(y, x);
if (mean < 0) mean += M_PI;
return mean;
};
REQUIRE(axial_angle_diff_deg(mean_interface_angle("normal(auto)", "default"),
mean_interface_angle("tree(auto)", "tree_slim")) < 10.0);
}
// Every style, because the non-organic tree styles once emitted one more top interface layer than the rest.
TEST_CASE("Top interface layer count equals the configured value for every support style", "[SupportMaterial]")
{
auto [type, style] = GENERATE(table<const char *, const char *>({
{ "normal(auto)", "grid" }, { "normal(auto)", "snug" },
{ "tree(auto)", "organic" }, { "tree(auto)", "tree_slim" },
{ "tree(auto)", "tree_strong" }, { "tree(auto)", "tree_hybrid" },
}));
CAPTURE(style);
const std::string g = slice({ TestMesh::overhang }, {
{ "enable_support", 1 },
{ "layer_height", 0.2 },
{ "support_type", type },
{ "support_style", style },
{ "support_interface_top_layers", 4 },
});
REQUIRE(support_interface_layer_count(g) == 4u);
}
// The bottom interface was dropped in earlier versions when support started on the model rather
// than the plate.
TEST_CASE("Non-organic tree support generates a bottom interface on internal geometry", "[SupportMaterial]")
{
const std::string g = slice({ support_tunnel() }, {
{ "enable_support", 1 },
{ "layer_height", 0.2 },
{ "support_on_build_plate_only", 0 },
{ "support_type", "tree(auto)" },
{ "support_style", "tree_slim" },
{ "support_interface_top_layers", 0 },
{ "support_interface_bottom_layers", 6 },
});
REQUIRE(support_base_layer_count(g) > 0);
REQUIRE(support_interface_layer_count(g) > 0);
}
// The capital forces the model contact; on a horizontal tunnel organic can arch a branch in and make none.
TEST_CASE("A bottom interface is produced for every support style on a forced model contact", "[SupportMaterial]")
{
auto [type, style] = GENERATE(table<const char *, const char *>({
{ "normal(auto)", "default" }, { "tree(auto)", "tree_slim" },
{ "tree(auto)", "tree_strong" }, { "tree(auto)", "tree_hybrid" },
{ "tree(auto)", "organic" },
}));
CAPTURE(style);
REQUIRE(support_interface_layer_count(slice({ support_capital() }, {
{ "enable_support", 1 }, { "layer_height", 0.2 }, { "support_on_build_plate_only", 0 },
{ "support_type", type }, { "support_style", style },
{ "support_interface_top_layers", 0 }, { "support_interface_bottom_layers", 6 } })) > 0);
}
TEST_CASE("Bottom interface spacing controls bottom interface density for every support style", "[SupportMaterial]")
{
auto [type, style] = GENERATE(table<const char *, const char *>({
{ "normal(auto)", "default" }, { "tree(auto)", "tree_slim" },
{ "tree(auto)", "tree_strong" }, { "tree(auto)", "tree_hybrid" },
{ "tree(auto)", "organic" },
}));
CAPTURE(style);
const TriangleMesh model = support_capital();
auto len = [&model](const char *support_type, const char *support_style, double spacing) {
return support_interface_extrusion_length(slice({ model }, {
{ "enable_support", 1 }, { "layer_height", 0.2 }, { "support_on_build_plate_only", 0 },
{ "support_type", support_type }, { "support_style", support_style }, { "support_interface_top_layers", 0 },
{ "support_interface_bottom_layers", 6 }, { "support_bottom_interface_spacing", spacing } }));
};
REQUIRE(len(type, style, 0.0) > len(type, style, 4.0) * 1.5);
}
// Interface and base flows are identical in width and rate unless a separate support-interface
// filament is used, so density is the observable here, not flow.
TEST_CASE("Bottom-only support interface keeps the dense interface density", "[SupportMaterial]")
{
Slic3r::Print print;
Slic3r::Test::init_and_process_print({ TestMesh::overhang }, print, {
{ "enable_support", 1 },
{ "support_interface_top_layers", 0 },
{ "support_interface_bottom_layers", 6 },
{ "support_bottom_interface_spacing", 0.0 }, // solid: density resolves to 1.0
{ "support_base_pattern_spacing", 2.5 }, // sparse: density stays below 1.0
});
SupportParameters sp(*print.objects().front());
REQUIRE(sp.bottom_interface_density > sp.support_density);
}
+190
View File
@@ -0,0 +1,190 @@
#include <catch2/catch_all.hpp>
#include <algorithm>
#include "libslic3r/Layer.hpp"
#include "libslic3r/TriangleMesh.hpp"
#include "test_helpers.hpp"
using namespace Slic3r::Test;
using namespace Slic3r;
namespace {
// The upper plate overhangs both the lower plate and open air, so branches land on the model and on
// the bed in the same slice.
TriangleMesh two_tier_mesh()
{
TriangleMesh lower = make_cube(30, 30, 3);
TriangleMesh column = make_cube(8, 8, 15);
TriangleMesh upper = make_cube(50, 50, 3);
// Each part overlaps the one below rather than resting on it; a coplanar join slices ambiguously.
column.translate(11.f, 11.f, 2.f);
upper.translate(-10.f, -10.f, 16.f);
TriangleMesh mesh = lower;
mesh.merge(column);
mesh.merge(upper);
return mesh;
}
TriangleMesh scaled(TestMesh id, float scale)
{
TriangleMesh mesh = Slic3r::Test::mesh(id);
mesh.scale(scale);
return mesh;
}
// `extra` is applied last, so a caller can add or override any key.
void slice_with_tree_support(const TriangleMesh &mesh, Slic3r::Print &print, const char *style,
int threshold_angle = 30, int build_plate_only = 0, int raft_layers = 0,
std::initializer_list<Slic3r::ConfigBase::SetDeserializeItem> extra = {})
{
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
config.set_deserialize_strict({
{ "enable_support", 1 },
{ "support_type", "tree(auto)" },
{ "support_style", style },
{ "support_on_build_plate_only", build_plate_only },
{ "support_threshold_angle", threshold_angle },
{ "raft_layers", raft_layers },
{ "layer_height", 0.2 },
});
config.set_deserialize_strict(extra);
Slic3r::Test::init_and_process_print({ mesh }, print, config);
}
Points support_points(const Slic3r::Print &print)
{
Points points;
for (const SupportLayer *layer : print.objects().front()->support_layers())
layer->support_fills.collect_points(points);
return points;
}
size_t support_point_count(const TriangleMesh &mesh, const char *style, int threshold_angle = 30,
int build_plate_only = 0)
{
Slic3r::Print print;
slice_with_tree_support(mesh, print, style, threshold_angle, build_plate_only);
return support_points(print).size();
}
// Index of the first differing point, or the common length when they match. An index keeps a
// failure readable; comparing the vectors themselves dumps thousands of points.
size_t first_difference(const Points &a, const Points &b)
{
const size_t common = std::min(a.size(), b.size());
for (size_t i = 0; i < common; ++i)
if (a[i] != b[i])
return i;
return common;
}
// Slice `mesh` twice and require an identical support point sequence. Point counts and total
// length are order insensitive, so the sequence is what a reordering shows up in.
void sliced_twice_matches(const TriangleMesh &mesh, int build_plate_only, const char *style = "tree_slim",
std::initializer_list<Slic3r::ConfigBase::SetDeserializeItem> extra = {})
{
Slic3r::Print first_print, second_print;
slice_with_tree_support(mesh, first_print, style, 30, build_plate_only, 0, extra);
slice_with_tree_support(mesh, second_print, style, 30, build_plate_only, 0, extra);
const Points first = support_points(first_print);
const Points second = support_points(second_print);
REQUIRE(first.size() > 1000); // without support the comparison below passes vacuously
REQUIRE(second.size() == first.size());
REQUIRE(first_difference(first, second) == first.size());
}
} // namespace
TEST_CASE("Tree support is generated for an overhang and not for a plain cube", "[TreeSupport]")
{
REQUIRE(support_point_count(scaled(TestMesh::overhang, 2.f), "tree_slim") > 1000);
REQUIRE(support_point_count(Slic3r::Test::cube(20), "tree_slim") == 0);
}
TEST_CASE("Restricting tree support to the build plate changes what is generated", "[TreeSupport]")
{
const TriangleMesh mesh = two_tier_mesh();
const size_t anywhere = support_point_count(mesh, "tree_slim", 30, 0);
const size_t plate_only = support_point_count(mesh, "tree_slim", 30, 1);
REQUIRE(anywhere > 1000);
REQUIRE(plate_only > 1000);
// The upper plate overhangs the lower one, so some branches would land on the model.
REQUIRE(plate_only != anywhere);
}
TEST_CASE("Tree support layers rise monotonically within the layer height limits", "[TreeSupport]")
{
Slic3r::Print print;
slice_with_tree_support(scaled(TestMesh::overhang, 2.f), print, "tree_slim");
const double nozzle = print.config().nozzle_diameter.values.front();
size_t checked = 0;
double previous = 0;
bool previous_was_adjacent = false;
for (const SupportLayer *layer : print.objects().front()->support_layers()) {
if (layer->print_z <= 0 || layer->height <= 0) {
// Layers with no nodes are left at zero. Skipping one leaves a hole, so the next pair
// spans more than one layer and its gap says nothing about the layer height limit.
previous_was_adjacent = false;
continue;
}
if (previous > 0) {
CAPTURE(previous, layer->print_z);
REQUIRE(layer->print_z > previous);
if (previous_was_adjacent)
REQUIRE(layer->print_z - previous <= nozzle + EPSILON);
}
previous = layer->print_z;
previous_was_adjacent = true;
++checked;
}
REQUIRE(checked > 10);
}
TEST_CASE("A raft is still generated under tree support", "[TreeSupport]")
{
// The mesh supports itself, so a layer count alone passes with no raft at all.
Slic3r::Print rafted, unrafted;
slice_with_tree_support(scaled(TestMesh::overhang, 2.f), rafted, "tree_slim", 30, 0, 3);
slice_with_tree_support(scaled(TestMesh::overhang, 2.f), unrafted, "tree_slim", 30, 0, 0);
const PrintObject *rafted_object = rafted.objects().front();
const PrintObject *unrafted_object = unrafted.objects().front();
REQUIRE(rafted_object->support_layers().size() > unrafted_object->support_layers().size());
// The raft goes under the object.
REQUIRE(rafted_object->layers().front()->print_z > unrafted_object->layers().front()->print_z);
}
// drop_nodes() decides the node merges and spawns the next layer's nodes in parallel. Every one of
// those decisions has to be applied in a fixed order, or the same model gives different branches on
// each slice.
TEST_CASE("Tree support toolpaths do not depend on thread scheduling", "[TreeSupport][Regression]")
{
// Scaled up so that a layer holds enough nodes for the parallel range to be split. At stock
// size it stays in one chunk and the order never varies.
SECTION("overhang") { sliced_twice_matches(scaled(TestMesh::overhang, 2.f), 0); }
SECTION("bridge with hole") { sliced_twice_matches(scaled(TestMesh::bridge_with_hole, 3.f), 0); }
// Dropping every branch that cannot reach the bed leaves the survivors dense enough that the
// neighbour merge fires in bulk.
SECTION("on the build plate") { sliced_twice_matches(scaled(TestMesh::overhang, 4.f), 1); }
// Branches resting on the model are what put nodes in a part group other than 0, which is the
// only way to reach the prune in the second pass. tree_hybrid additionally builds polygon
// nodes, so it is the only style that exercises the overhang merge.
SECTION("resting on the model") { sliced_twice_matches(two_tier_mesh(), 0); }
SECTION("hybrid on the model") { sliced_twice_matches(two_tier_mesh(), 0, "tree_hybrid"); }
}
// Prim breaks equal-distance ties by heap address. A 1 mm branch diameter puts neighbours close
// enough to tie, and an explicit line width pins max_move_dist, so the moved tie winner reaches
// the support toolpaths.
TEST_CASE("Tree support toolpaths do not depend on the MST tie order", "[TreeSupport][Regression]")
{
sliced_twice_matches(two_tier_mesh(), 0, "tree_hybrid", {
{ "tree_support_branch_diameter", 1.0 },
{ "tree_support_branch_distance", 5.0 },
{ "tree_support_branch_angle", 40 },
{ "support_line_width", 0.4 },
});
}
+147
View File
@@ -152,6 +152,8 @@ static DynamicPrintConfig wipe_tower_toolchange_config(const std::string &gcode_
{ "outer_wall_filament_id", 2 },
{ "inner_wall_filament_id", 2 },
{ "enable_prime_tower", true },
{ "wipe_tower_x", 50 }, // inside the 200x200 test bed
{ "wipe_tower_y", 50 }, // (the default y, 220, is not)
{ "layer_height", 0.3 },
{ "gcode_flavor", gcode_flavor },
});
@@ -182,3 +184,148 @@ TEST_CASE("The wipe tower's toolchange planner flush follows the gcode flavor",
CHECK_THAT(tower, !Catch::Matchers::ContainsSubstring(unexpected));
}
}
// What Print feeds the shared estimate. The libslic3r WipeTowerEstimate cases cannot see this:
// they call the estimator directly. The estimate counts the filaments the print really uses,
// so the two-filament shape gives the outer wall the second one.
static DynamicPrintConfig tower_estimate_config(const char *wall_type, unsigned int filaments = 2)
{
// 100 mm3 per purge on a 50 mm wide tower: one purge is 100/(layer_height * 50) of depth.
return multifilament_config(filaments, {
{ "outer_wall_filament_id", filaments == 2 ? "2" : "1" },
{ "enable_prime_tower", "1" },
{ "wipe_tower_wall_type", wall_type },
{ "prime_tower_width", "50" },
{ "prime_volume", "100" },
{ "prime_tower_infill_gap", "100%" },
{ "prime_tower_brim_width", "3" },
{ "purge_in_prime_tower", "0" },
{ "single_extruder_multi_material", "0" },
{ "timelapse_type", "0" },
{ "layer_height", "0.2" },
{ "enable_wrapping_detection", "0" },
{ "raft_layers", "0" } });
}
TEST_CASE("The tower is sized for the thinnest layer any object on the plate is sliced at", "[WipeTower]")
{
// The tower has to survive its thinnest layer, so an override finer than the preset drives
// the estimate even on the second object. Two 20 mm cubes, the second at 0.1 mm.
const DynamicPrintConfig config = tower_estimate_config("rectangle");
const std::vector<std::vector<ConfigBase::SetDeserializeItem>> overrides = {
{}, { { "layer_height", "0.1" } } };
Print print;
Model model;
init_print({ cube(20), cube(20) }, print, model, config, &overrides);
// One purge at 0.1 mm: 100 / (0.1 * 50) = 20 mm, above the 20 mm-tall tower's stability
// floor. At the preset's 0.2 mm it would be half that, so the two are easy to tell apart.
const float floor_20mm = WipeTower::get_limit_depth_by_height(20.f);
REQUIRE(floor_20mm < 10.f);
CHECK_THAT(print.wipe_tower_data(2).depth, Catch::Matchers::WithinAbs(20., 1e-4));
}
TEST_CASE("Validation is given the tower's effective width, not the configured one", "[WipeTower]")
{
// A rib wall squares the tower, so its width is its depth. Validation reads this rather
// than re-deriving the rule from the wall type.
Print print;
Model model;
SECTION("a rectangle wall keeps the configured width") {
const DynamicPrintConfig config = tower_estimate_config("rectangle");
init_print({ cube(20) }, print, model, config);
const WipeTowerData &data = print.wipe_tower_data(2);
CHECK_THAT(data.width, Catch::Matchers::WithinAbs(50., 1e-4));
CHECK(data.depth < data.width);
}
SECTION("a rib wall reports the squared footprint") {
const DynamicPrintConfig config = tower_estimate_config("rib");
init_print({ cube(20) }, print, model, config);
const WipeTowerData &data = print.wipe_tower_data(2);
CHECK_THAT(data.width, Catch::Matchers::WithinAbs(data.depth, 1e-4));
CHECK(data.width > 0.f);
}
}
TEST_CASE("Generating the tower keeps its reported width current", "[WipeTower]")
{
// width is handed out after the slice, so leaving it at the estimate reports a zero-width
// tower to every post-generation consumer.
const DynamicPrintConfig config = wipe_tower_toolchange_config("marlin");
Print print;
Model model;
init_print({ cube(10) }, print, model, config);
print.apply(model, config);
REQUIRE(print.wipe_tower_data(2).width > 0.f);
print.process();
REQUIRE(print.is_step_done(psWipeTower));
const WipeTowerData &data = print.wipe_tower_data();
// A width the generator never wrote reads as zero. A rib wall squares the tower, so the
// generated width is the body square: under the configured 50 mm, and inside the depth.
CHECK(data.width > 0.f);
CHECK(data.width < 50.f);
CHECK(data.width <= data.depth + EPSILON);
}
TEST_CASE("A single-filament plate reserves a tower only when one is actually printed", "[WipeTower]")
{
// The estimate has to answer this the way Print::apply does: reporting no tower for one
// that is built collapses the validation hull to a point, and reporting one for a tower
// that is not built takes that bed area away from the arranger and draws a preview box
// over nothing.
Print print;
Model model;
SECTION("no tool change and nothing else that prints one") {
const DynamicPrintConfig config = tower_estimate_config("rib", 1);
init_print({ cube(20) }, print, model, config);
REQUIRE_FALSE(print.has_wipe_tower());
CHECK_THAT(print.wipe_tower_data(1).depth, Catch::Matchers::WithinAbs(0., 1e-6));
}
// A raft puts the tower on every layer below the object, but only where there is a tower:
// Print::apply runs normalize_fdm_2, which clears enable_prime_tower for a plate that
// purges one filament and has neither smooth timelapse nor wrapping detection on.
SECTION("a raft alone does not print one") {
DynamicPrintConfig config = tower_estimate_config("rib", 1);
config.set_deserialize_strict({ { "raft_layers", "3" } });
init_print({ cube(20) }, print, model, config);
REQUIRE_FALSE(print.config().enable_prime_tower.value);
REQUIRE_FALSE(print.has_wipe_tower());
CHECK_THAT(print.wipe_tower_data(1).depth, Catch::Matchers::WithinAbs(0., 1e-6));
}
SECTION("smooth timelapse prints one, and keeps enable_prime_tower on") {
DynamicPrintConfig config = tower_estimate_config("rib", 1);
config.set_deserialize_strict({ { "timelapse_type", "1" } });
init_print({ cube(20) }, print, model, config);
REQUIRE(print.has_wipe_tower());
CHECK(print.wipe_tower_data(1).depth > 0.f);
}
}
TEST_CASE("A tower printed without a tool change is still validated against the bed", "[WipeTower]")
{
// Wrapping detection prints a tower on a plate that purges one filament. Neither the old
// estimate (which read the wall type and smooth timelapse) nor the old containment gate (the
// filament count or smooth timelapse) knew about it, so between them that tower was never
// checked against the bed.
Print print;
Model model;
DynamicPrintConfig config = tower_estimate_config("rectangle", 1);
// Relative E without a per-layer G92 is rejected before the tower is ever looked at, and
// has_wipe_tower() wants a real exclusion polygon before it honours wrapping detection.
config.set_deserialize_strict({ { "enable_wrapping_detection", "1" },
{ "wrapping_exclude_area", "180x180,190x180,190x190,180x190" },
{ "wipe_tower_x", "500" }, { "wipe_tower_y", "500" }, { "use_relative_e_distances", "0" } });
init_print({ cube(20) }, print, model, config);
REQUIRE(print.extruders(true).size() == 1);
REQUIRE(print.has_wipe_tower());
CHECK(print.wipe_tower_data(1).depth > 0.f);
CHECK_THAT(print.validate().string, Catch::Matchers::ContainsSubstring("printable area"));
}