Part 2.6: Add belt floor support clipping for all support types

- Fix support clipping z-shift calculation by removing coordinate-space
  mismatch and sync belt_floor_z_shift with global_z_offset; fix
  invalidation so posSupportMaterial no longer resets slicing params
- Add belt floor polygon clipping to non-organic tree support
  (slim/strong/hybrid) with collision surface integration in
  TreeSupportData, belt extension layers, and first-layer brim
  suppression
- Add belt floor clipping to organic tree support pipeline with virtual
  belt raft layers, per-layer polygons in TreeModelVolumes, and
  post-generation layer trimming; fix pre-existing processing_last_mesh
  bug in calculateCollision()

Fix belt floor support clipping: z-shift, invalidation, and global offset

- Fix support clipping z-shift calculation by removing coordinate-space
  mismatch (raw_bounding_box min.z vs trafo_centered m_belt_min_z) and
  sync belt_floor_z_shift with global_z_offset in global shear mode
- Fix invalidation so posSupportMaterial no longer resets slicing params,
  preventing the exact posSlice z-shift from being overwritten by the
  bounding-box approximation on support-only setting changes
- Remove double-counting of global z_offset on support layers — support
  already inherits the offset from object layers during generation

This Work Was Co-Authored-By Claude Opus 4.6 (1M context) <noreply@anthropic.com>

UI: gray out inactive belt sub-options, rename to mesh transforms, move to Advanced

Fix mesh clipping through build plate after belt shear/scale transform

Generalize G-code viewer designed-view toggle for full belt transform

Clip support layers to transformed belt floor plane

Supports below the tilted build plate (Z = shear_factor * from_axis - min_z)
are now clipped via half-plane intersection after generation. Belt floor
parameters stored in SlicingParameters and populated in both update_slicing_parameters()
and the static slicing_parameters() overload.

Make belt G-code viewer toggle more prominent, add B keyboard shortcut

- Add separator + teal "Belt Printer" header in legend panel
- Append [B] hint to checkbox label
- Add B key shortcut in GLCanvas3D to toggle designed/machine view
- Read belt_printer_angle from loaded G-code headers to enable belt view

Add per-axis global transform option for belt printer shear

New belt_shear_{x,y,z}_global bool configs. When enabled, shear incorporates
instance shift so objects at different bed positions get position-aware
transform (Z += factor * instance_shift_on_from_axis).

Fix global shear: use layer Z offset instead of mesh transform, add config invalidation

- Global shear offset applied as post-slicing layer print_z adjustment
  instead of mesh transform (which was absorbed by min_z normalization
  or shifted mesh out of slice range)
- Register all belt transform options in Print::invalidate_state_by_config_options
  to trigger posSlice re-slicing (the fallback only invalidated Print steps,
  not PrintObject steps — belt changes had no effect without manual re-slice)
- Belt gcode remap options added to steps_gcode (gcode-export only)
- Skip empty-first-layer check for belt objects with global Z offset

WIP: split instances for global shear, relative Z offsets, debug logging

- PrintApply: when belt global mode active, prevent instance grouping by
  adding unique Z perturbation to trafo — each copy becomes its own
  PrintObject with independent layers
- PrintObjectSlice: compute global Z offset relative to minimum Y shift
  across all PrintObjects (lowest-Y object stays at Z=0)
- Debug logging (warning level) for belt global shift values and offsets

Known issues:
- Cached posSlice results cause stale offsets when mixing copies with
  individually-added objects — need to compute min baseline outside slice()
- Supports still generate to Z=0 instead of object's global Z offset

Fix global shear for copied objects: disable shared-object layer optimization

When belt global Z shear is active, each object needs unique layer Z
values based on its bed position. The shared-object optimization was
causing copies to reuse the source object's layers (and its Z offset)
instead of computing their own position-based offset.

started work on getting supports to work properly

one step forward, one step back

this version didn't quite work.  Getting somewhere though

about to add UI controllable tests

added configuration options for supports

tweak CLAUDE.md to be more aggressive for my machine.  This commit should probably be pulled out before contributing upstream

still chasing down some bugs

moving objects between slices no longer results in improper Z-height because of caching

added more data to the debug logs

Z offset is getting more global again

still not quite there, I think there's a fundamental logic flaw?

hunting for bugs

finally have a functional fix

Add belt floor clipping to tree supports (organic and non-organic)

- Add belt floor polygon clipping to non-organic tree support
  (slim/strong/hybrid) in draw_circles() and terminate nodes at the
  belt surface instead of the horizontal build plate
- Add belt floor clipping to organic tree support pipeline with virtual
  belt raft layers for sub-floor branch generation, per-layer belt
  floor polygons in TreeModelVolumes, and post-generation layer trimming
- Fix pre-existing processing_last_mesh bug in TreeModelVolumes that
  prevented m_anti_overhang (support blockers) from ever being applied;
  skip empty first layer check for belt printers

Commits:

current approach: make a face surface to build supports to

closer!

supports now terminate on shear plane, now need to get shear plane to correct Z height

nearly there

chasing down logic issues still

committing for checkpoint, this still does not work

still got logic problems...

cull support clipping

stashing changes for now.  Going to focus on getting the global shear OFF support generation dialed first.

beginning per object shear calcs

Local shear transform is on correct Z offset now

local shear finally works now and needs more testing

global shear works now, needs thorough testing

debugging non-45 degree angles

debugging part 2

supports at all angles work now

remove debug logging

Add belt floor collision to non-organic tree support pipeline

- Integrate belt floor as a collision surface in TreeSupportData so
  branches route around the belt naturally, replacing the explicit
  termination checks in drop_nodes()
- Add belt extension layers below the object after draw_circles() to
  allow support geometry to extend to the diagonal belt surface instead
  of terminating at a horizontal first layer
- Fix coordinate overflow in belt floor polygons (scale_(1e4) exceeds
  int32), skip first-layer brim expansion for belt printers, and
  extend empty first layer check bypass to all belt modes

add debug logging, Z translate for tree supports

still not seeing any cutoff surface yet

adding debug options

attempt #2 at trees

if hit Z buildplate stop but don't set to_buildplate true

getting closer

tree support almost there, just need to get rid of the circles at the beginning

getting closer

belt / shear plane clip works, need to figure out the buidlplate plane issues

more logic, added debugging logs

supports now extend somewhat below Z=0 in global shear mode

fix bad alloc, add 10mm below build plate

fully works now

shear transform + prusa tree support generation works now.

pull out debug logging
This commit is contained in:
harrierpigeon
2026-03-30 13:25:40 -05:00
committed by Joseph Robertson
parent 719af2d81d
commit 7ff6bc42b1
27 changed files with 1337 additions and 137 deletions
+286 -4
View File
@@ -367,10 +367,21 @@ inline void layers_append(SupportGeneratorLayersPtr &dst, const SupportGenerator
}
// Support layer that is covered by some form of dense interface.
static constexpr const std::initializer_list<SupporLayerType> support_types_interface {
static constexpr const std::initializer_list<SupporLayerType> support_types_interface {
SupporLayerType::RaftInterface, SupporLayerType::BottomContact, SupporLayerType::BottomInterface, SupporLayerType::TopContact, SupporLayerType::TopInterface
};
// Forward declarations for belt floor helpers (defined later in this file).
// belt_floor_surface_polygon is declared in SupportCommon.hpp (non-static,
// shared with TreeSupport.cpp).
static Polygons belt_floor_valid_region_polygon(
const SlicingParameters &slicing_params, const PrintConfig &print_config,
const PrintObject &object, coordf_t print_z);
static void trim_support_layers_by_belt_floor(
const SlicingParameters &slicing_params, const PrintConfig &print_config,
const PrintObject &object, SupportGeneratorLayersPtr &support_layers);
void PrintObjectSupportMaterial::generate(PrintObject &object)
{
BOOST_LOG_TRIVIAL(info) << "Support generator - Start";
@@ -443,11 +454,12 @@ void PrintObjectSupportMaterial::generate(PrintObject &object)
object, bottom_contacts, top_contacts, layer_storage);
this->trim_support_layers_by_object(object, top_contacts, m_slicing_params.gap_support_object, m_slicing_params.gap_object_support, m_support_params.gap_xy);
trim_support_layers_by_belt_floor(m_slicing_params, *m_print_config, object, top_contacts);
#ifdef SLIC3R_DEBUG
for (const SupportGeneratorLayer *layer : top_contacts)
Slic3r::SVG::export_expolygons(
debug_out_path("support-top-contacts-trimmed-by-object-%d-%lf.svg", iRun, layer->print_z),
debug_out_path("support-top-contacts-trimmed-by-object-%d-%lf.svg", iRun, layer->print_z),
union_ex(layer->polygons));
#endif
@@ -603,6 +615,139 @@ Polygons collect_region_slices_by_type(const Layer &layer, SurfaceType surface_t
return out;
}
// Belt printer: compute the belt-side half-plane polygon at a given print_z.
// This represents the region where the belt surface exists (the "phantom top surface").
// Support that overlaps with this polygon should terminate with a bottom contact.
// Returns empty if belt floor is not active.
Polygons belt_floor_surface_polygon(
const SlicingParameters &slicing_params,
const PrintConfig &print_config,
const PrintObject &object,
coordf_t print_z)
{
const double shear_factor = slicing_params.belt_floor_shear_factor;
if (std::abs(shear_factor) < EPSILON)
return {};
const int from_axis = slicing_params.belt_floor_from_axis; // 0=X, 1=Y
const double floor_offset = print_config.belt_support_floor_offset.value;
// Belt floor line in slicing coordinates: Z = sf * Y + z_shift.
// z_shift accounts for the upward shift applied when post-shear geometry
// extends below the bed (overhangs). Solving for Y:
// cutoff = (print_z - z_shift - floor_offset) / sf
const double z_shift = slicing_params.belt_floor_z_shift;
const double cutoff = (print_z - z_shift - floor_offset) / shear_factor;
const coord_t cutoff_scaled = scale_(cutoff);
const coord_t large_bound = scale_(1e4);
// Build the belt-side half-plane (inverted from the valid region).
// If shear_factor > 0: valid region is from_axis < cutoff, so belt surface is from_axis >= cutoff.
// If shear_factor < 0: valid region is from_axis > cutoff, so belt surface is from_axis <= cutoff.
Polygon belt_poly;
if (from_axis == 0) {
if (shear_factor > 0) {
// Belt surface: X >= cutoff
belt_poly.points = {
Point(cutoff_scaled, -large_bound),
Point(large_bound, -large_bound),
Point(large_bound, large_bound),
Point(cutoff_scaled, large_bound)
};
} else {
// Belt surface: X <= cutoff
belt_poly.points = {
Point(-large_bound, -large_bound),
Point(cutoff_scaled, -large_bound),
Point(cutoff_scaled, large_bound),
Point(-large_bound, large_bound)
};
}
} else {
if (shear_factor > 0) {
// Belt surface: Y >= cutoff
belt_poly.points = {
Point(-large_bound, cutoff_scaled),
Point( large_bound, cutoff_scaled),
Point( large_bound, large_bound),
Point(-large_bound, large_bound)
};
} else {
// Belt surface: Y <= cutoff
belt_poly.points = {
Point(-large_bound, -large_bound),
Point( large_bound, -large_bound),
Point( large_bound, cutoff_scaled),
Point(-large_bound, cutoff_scaled)
};
}
}
return { belt_poly };
}
// Belt printer: compute the valid-region half-plane polygon at a given print_z.
// This is the region where support is allowed to exist (above the belt).
// Used to clip the downward-propagating support projection.
static Polygons belt_floor_valid_region_polygon(
const SlicingParameters &slicing_params,
const PrintConfig &print_config,
const PrintObject &object,
coordf_t print_z)
{
const double shear_factor = slicing_params.belt_floor_shear_factor;
if (std::abs(shear_factor) < EPSILON)
return {};
const int from_axis = slicing_params.belt_floor_from_axis;
const double floor_offset = print_config.belt_support_floor_offset.value;
const double z_shift = slicing_params.belt_floor_z_shift;
const double cutoff = (print_z - z_shift - floor_offset) / shear_factor;
const coord_t cutoff_scaled = scale_(cutoff);
const coord_t large_bound = scale_(1e4);
// Valid region: the complement of the belt surface polygon.
Polygon valid_poly;
if (from_axis == 0) {
if (shear_factor > 0) {
// Valid: X < cutoff
valid_poly.points = {
Point(-large_bound, -large_bound),
Point(cutoff_scaled, -large_bound),
Point(cutoff_scaled, large_bound),
Point(-large_bound, large_bound)
};
} else {
// Valid: X > cutoff
valid_poly.points = {
Point(cutoff_scaled, -large_bound),
Point(large_bound, -large_bound),
Point(large_bound, large_bound),
Point(cutoff_scaled, large_bound)
};
}
} else {
if (shear_factor > 0) {
// Valid: Y < cutoff
valid_poly.points = {
Point(-large_bound, -large_bound),
Point( large_bound, -large_bound),
Point( large_bound, cutoff_scaled),
Point(-large_bound, cutoff_scaled)
};
} else {
// Valid: Y > cutoff
valid_poly.points = {
Point(-large_bound, cutoff_scaled),
Point( large_bound, cutoff_scaled),
Point( large_bound, large_bound),
Point(-large_bound, large_bound)
};
}
}
return { valid_poly };
}
// Collect outer contours of all slices of this layer.
// This is useful for calculating the support base with holes filled.
Polygons collect_slices_outer(const Layer &layer)
@@ -2516,6 +2661,82 @@ static inline SupportGeneratorLayer* detect_bottom_contacts(
return &layer_new;
}
// Belt printer: detect bottom contacts where support meets the belt floor plane.
// Modeled on detect_bottom_contacts() but uses the belt plane polygon instead of stTop surfaces.
static inline SupportGeneratorLayer* detect_belt_floor_bottom_contacts(
const SlicingParameters &slicing_params,
const SupportParameters &support_params,
const PrintConfig &print_config,
const PrintObject &object,
const Layer &layer,
// Existing top contact layers, for snapping.
const SupportGeneratorLayersPtr &top_contacts,
size_t contact_idx,
SupportGeneratorLayerStorage &layer_storage,
std::vector<Polygons> &layer_support_areas,
const Polygons &supports_projected)
{
// Compute the belt surface polygon at this layer's Z.
Polygons belt_surface = belt_floor_surface_polygon(slicing_params, print_config, object, layer.print_z);
if (belt_surface.empty())
return nullptr;
// Find where projected support overlaps the belt surface.
Polygons touching = intersection(belt_surface, supports_projected);
if (touching.empty())
return nullptr;
assert(layer.id() >= slicing_params.raft_layers());
size_t layer_id = layer.id() - slicing_params.raft_layers();
// Allocate a new bottom contact layer resting on the belt plane.
SupportGeneratorLayer &layer_new = layer_storage.allocate_unguarded(SupporLayerType::BottomContact);
// No object layer to sync with -- compute heights directly from flow parameters.
layer_new.height = support_params.support_material_bottom_interface_flow.height();
layer_new.print_z = layer.print_z + layer_new.height + slicing_params.gap_object_support;
layer_new.bottom_z = layer.print_z;
layer_new.idx_object_layer_below = layer_id;
layer_new.bridging = ! slicing_params.soluble_interface && object.config().thick_bridges;
layer_new.polygons = expand(touching, float(support_params.support_material_flow.scaled_width()), SUPPORT_SURFACES_OFFSET_PARAMETERS);
if (! slicing_params.soluble_interface) {
// Snap to nearby top contact layers to avoid very thin support layers.
for (size_t top_idx = size_t(std::max<int>(0, int(contact_idx)));
top_idx < top_contacts.size() && top_contacts[top_idx]->print_z < layer_new.print_z + support_params.support_layer_height_min + EPSILON;
++ top_idx) {
if (top_contacts[top_idx]->print_z > layer_new.print_z - support_params.support_layer_height_min - EPSILON) {
coordf_t diff = layer_new.print_z - top_contacts[top_idx]->print_z;
assert(std::abs(diff) <= support_params.support_layer_height_min + EPSILON);
if (diff > 0.F) {
if (layer_new.height - diff > support_params.support_layer_height_min) {
layer_new.print_z = top_contacts[top_idx]->print_z;
layer_new.height -= diff;
} else {
continue;
}
} else {
layer_new.print_z = top_contacts[top_idx]->print_z;
layer_new.height -= diff;
}
break;
}
}
}
// Trim the already created base layers above this belt contact.
touching = expand(touching, float(SCALED_EPSILON));
for (int layer_id_above = int(layer_id) + 1; layer_id_above < int(object.total_layer_count()); ++ layer_id_above) {
const Layer &layer_above = *object.layers()[layer_id_above];
if (layer_above.print_z > layer_new.print_z - EPSILON)
break;
if (Polygons &above = layer_support_areas[layer_id_above]; ! above.empty())
above = diff(above, touching);
}
return &layer_new;
}
// Returns polygons to print + polygons to propagate downwards.
// Called twice: First for normal supports, possibly trimmed by "on build plate only", second for support enforcers not trimmed by "on build plate only".
static inline std::pair<Polygons, Polygons> project_support_to_grid(const Layer &layer, const SupportGridParams &grid_params, const Polygons &overhangs, Polygons *layer_buildplate_covered
@@ -2615,6 +2836,8 @@ SupportGeneratorLayersPtr PrintObjectSupportMaterial::bottom_contact_layers_and_
//const auto expansion_to_slice = m_support_material_flow.scaled_spacing() / 2 + 25;
const SupportGridParams grid_params(*m_object_config, m_support_params.support_material_flow);
const bool buildplate_only = ! buildplate_covered.empty();
const bool has_belt_floor = std::abs(m_slicing_params.belt_floor_shear_factor) > EPSILON
&& m_print_config->belt_support_floor_mode.value == BeltSupportFloorMode::GeneratorOnly;
// Allocate empty surface areas, one per object layer.
layer_support_areas.assign(object.total_layer_count(), Polygons());
@@ -2675,8 +2898,9 @@ SupportGeneratorLayersPtr PrintObjectSupportMaterial::bottom_contact_layers_and_
tbb::task_group task_group;
const Polygons &overhangs_for_bottom_contacts = buildplate_only ? enforcers_projection_raw : overhangs_projection_raw;
if (! overhangs_for_bottom_contacts.empty())
// Find the bottom contact layers above the top surfaces of this layer.
task_group.run([this, &object, &layer, &top_contacts, contact_idx, &layer_storage, &layer_support_areas, &bottom_contacts, &overhangs_for_bottom_contacts
// Find the bottom contact layers above the top surfaces of this layer,
// and also detect belt floor contacts if belt mode is active.
task_group.run([this, &object, &layer, &top_contacts, contact_idx, &layer_storage, &layer_support_areas, &bottom_contacts, &overhangs_for_bottom_contacts, has_belt_floor
#ifdef SLIC3R_DEBUG
, iRun, &polygons_new
#endif // SLIC3R_DEBUG
@@ -2690,6 +2914,15 @@ SupportGeneratorLayersPtr PrintObjectSupportMaterial::bottom_contact_layers_and_
);
if (layer_new)
bottom_contacts.push_back(layer_new);
// Belt floor phantom surface: detect where support meets the belt plane.
if (has_belt_floor) {
SupportGeneratorLayer *belt_layer = detect_belt_floor_bottom_contacts(
m_slicing_params, m_support_params, *m_print_config, object,
layer, top_contacts, contact_idx, layer_storage,
layer_support_areas, overhangs_for_bottom_contacts);
if (belt_layer)
bottom_contacts.push_back(belt_layer);
}
});
Polygons &layer_support_area = layer_support_areas[layer_id];
@@ -2728,6 +2961,23 @@ SupportGeneratorLayersPtr PrintObjectSupportMaterial::bottom_contact_layers_and_
task_group.wait();
// Belt floor: clip projections and support areas so support doesn't
// propagate below the belt plane.
if (has_belt_floor) {
Polygons valid_region = belt_floor_valid_region_polygon(
m_slicing_params, *m_print_config, object, layer.print_z);
if (! valid_region.empty()) {
if (! overhangs_projection.empty())
overhangs_projection = intersection(overhangs_projection, valid_region);
if (! enforcers_projection.empty())
enforcers_projection = intersection(enforcers_projection, valid_region);
if (! layer_support_area.empty())
layer_support_area = intersection(layer_support_area, valid_region);
if (! layer_support_area_enforcers.empty())
layer_support_area_enforcers = intersection(layer_support_area_enforcers, valid_region);
}
}
if (! layer_support_area_enforcers.empty()) {
if (layer_support_area.empty())
layer_support_area = std::move(layer_support_area_enforcers);
@@ -2738,6 +2988,7 @@ SupportGeneratorLayersPtr PrintObjectSupportMaterial::bottom_contact_layers_and_
std::reverse(bottom_contacts.begin(), bottom_contacts.end());
trim_support_layers_by_object(object, bottom_contacts, m_slicing_params.gap_support_object, m_slicing_params.gap_object_support, m_support_params.gap_xy);
trim_support_layers_by_belt_floor(m_slicing_params, *m_print_config, object, bottom_contacts);
return bottom_contacts;
}
@@ -3108,6 +3359,37 @@ void PrintObjectSupportMaterial::generate_base_layers(
#endif /* SLIC3R_DEBUG */
this->trim_support_layers_by_object(object, intermediate_layers, m_slicing_params.gap_support_object, m_slicing_params.gap_object_support, m_support_params.gap_xy);
trim_support_layers_by_belt_floor(m_slicing_params, *m_print_config, object, intermediate_layers);
}
// Belt printer: trim support layer polygons by the belt floor plane.
// For each support layer, computes the belt floor half-plane at that layer's print_z
// and subtracts it from the support polygons. This follows the same diff() pattern
// as trim_support_layers_by_object() so that interface layers derived from trimmed
// intermediates automatically inherit the belt floor trimming.
static void trim_support_layers_by_belt_floor(
const SlicingParameters &slicing_params,
const PrintConfig &print_config,
const PrintObject &object,
SupportGeneratorLayersPtr &support_layers)
{
if (std::abs(slicing_params.belt_floor_shear_factor) < EPSILON)
return;
if (print_config.belt_support_floor_mode.value != BeltSupportFloorMode::GeneratorOnly)
return;
tbb::parallel_for(tbb::blocked_range<size_t>(0, support_layers.size()),
[&](const tbb::blocked_range<size_t> &range) {
for (size_t i = range.begin(); i < range.end(); ++ i) {
SupportGeneratorLayer *layer = support_layers[i];
if (layer->polygons.empty())
continue;
Polygons belt_surface = belt_floor_surface_polygon(
slicing_params, print_config, object, layer->print_z);
if (! belt_surface.empty())
layer->polygons = diff(layer->polygons, belt_surface);
}
});
}
void PrintObjectSupportMaterial::trim_support_layers_by_object(