Fix organic tree smoothing drift and layer mapping (#14069) - #680
Open
bluetianyu wants to merge 1 commit into
Open
Fix organic tree smoothing drift and layer mapping (#14069)#680bluetianyu wants to merge 1 commit into
bluetianyu wants to merge 1 commit into
Conversation
bluetianyu
requested review from
fire2wind,
lujiaxin001,
mwz-iot and
zackaree-shen
August 7, 2026 11:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR OrcaSlicer#14069 — Fix organic tree smoothing drift and layer mapping
Summary
This PR fixes two defects in the organic tree support post-processing pipeline:
Smoothing drift: During iterative collision avoidance + Laplacian smoothing, node positions could drift without bound because only per-iteration step caps were enforced—cumulative displacement had no constraint. Over up to 100 iterations, a node could theoretically drift up to 70mm, breaking the 3D branch structure.
Layer mapping for raft layers:
layer_idx_ceil()andlayer_idx_floor()used a uniform-spacing formula that failed for all Z values falling within the raft-layer range. The formula returnedraft_layers.size()(the first object-layer index) for every raft-zone Z, causing collision detection to skip raft layers entirely.Changes
TreeSupport3D.cpp— Add vertical-structure constraintsAdded
limit_candidate_to_linked_layerslambda insideorganic_smooth_branches_avoid_collisions(). After each collision-avoidance or Laplacian-smoothing nudge, the candidate position is now constrained by the physically reachable range from its linked upper (parent) and lower (child) nodes:allowed_shift = max(0, neighbor_radius - current_radius) + maximum_move_distance_slow; candidate = constrain_to_anchor(candidate, neighbor.prev_position, allowed_shift);constrain_to_anchoris a simple clamp: if the candidate exceedsallowed_shiftfrom the anchor, it is pulled back along the same direction to the boundary; otherwise it passes through unchanged.allowed_shiftformula is physically meaningful: the radius difference between connected nodes represents the lateral clearance the branch geometry can accommodate, plus the configured slow-move margin.TreeSupportCommon.hpp— Fix Z-to-layer-index mapping for raft layersRewrote
layer_idx_ceil()andlayer_idx_floor()to handle raft layers and object layers separately:z < first_object_z): Usesstd::lower_bound/std::upper_boundbinary search on the orderedconfig.raft_layersarray to find the exact index.z >= first_object_z): Uses the existing linear formula (which was correct for this zone).first_object_support_layer_z()helper to clarify the boundary between raft and object layers.Before / After
layer_idx_ceil(0.35)with raft at [0.20, 0.40, 0.55]layer_idx_floor(0.35)with raft at [0.20, 0.40, 0.55]allowed_shiftof linked layersScope of impact
organic_smooth_branches_avoid_collisions()andlayer_idx_ceil/floor()Testing
num_movedreaches zero) within the iteration limit.layer_idx_ceil/floorreturn correct indices for Z values across raft layers, the raft-object boundary, and object layers.Files changed
src/libslic3r/Support/TreeSupport3D.cppsrc/libslic3r/Support/TreeSupportCommon.hppBefore fix:
default.mp4
After fix:
default.mp4