Skip to content

Revamp tree support: anatomically-correct trunk → branch → twig structure at ≤45° with circular cross-sections#172

Merged
jgphilpott merged 7 commits intomainfrom
copilot/revamp-tree-support-module
Mar 3, 2026
Merged

Revamp tree support: anatomically-correct trunk → branch → twig structure at ≤45° with circular cross-sections#172
jgphilpott merged 7 commits intomainfrom
copilot/revamp-tree-support-module

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

  • Vary cross-section size by type and render circular O+X shape
  • Fix translation-dependent clustering (anchor to minX/minY with floor)
  • Emit single shared trunk segment (not one per branch)
  • Always guarantee a trunk segment even when branchRootZ is clamped
  • Update 45° constraint comment to accurately describe clamping behaviour
  • Fix conditional (silent) test assertion for circle closure
  • 31 tree tests pass; 811/811 total tests pass

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ch/twig structure

Co-authored-by: jgphilpott <4128208+jgphilpott@users.noreply.github.com>
Copilot AI changed the title [WIP] Revamp tree support module for realistic tree structure Revamp tree support: anatomically-correct trunk → branch → twig structure at ≤45° Mar 3, 2026
@jgphilpott
Copy link
Owner

This is a fantastic start @copilot, we are definitely on the right track here, the supports actually look like real trees now! However, many issues still remain:

  • To start with, I noticed that all the components (trunk, branch, twig) are all the same size. For structural support reasons, and also like trees in real life, the size should decrease the further you get from the trunk (the largest component). The current size is okay for twigs but the branch and trunk need to be increased in size.
  • The shape of the support should be round (like a tree) not just the simple X shape we have now. It should be circular like an O with an X shaped infill in the center.

More suggestions to come but I think two at a time is enough for now.

Co-authored-by: jgphilpott <4128208+jgphilpott@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 3, 2026

This is a fantastic start @copilot, we are definitely on the right track here, the supports actually look like real trees now! However, many issues still remain:

  • To start with, I noticed that all...

Both changes are in commit 801c769:

Varying size by type — three radius multipliers replace the old fixed constant:

Type Radius
Trunk 3.0 × nozzle diameter
Branch 1.8 × nozzle diameter
Twig 0.8 × nozzle diameter (unchanged)

Circular O + diagonal X shaperenderCrossAt is replaced by renderNodeAt which renders:

  1. A 12-segment polygon perimeter (the circle/O) at the full radius
  2. Two diagonal lines crossing the center at ±45° inside it (the X infill)

Example output for a trunk node (nozzle = 0.4 mm, radius = 1.2 mm):

G0 X1.2 Y0 Z1 F9000          ; travel to circle start (3 o'clock)
G1 X1.039 Y0.6 Z1 E0.017 F900  ; circle segment 1
G1 X0.6 Y1.039 Z1 E0.033 F900  ; …
...
G1 X1.2 Y0 Z1 E0.198 F900    ; circle closes at start
G0 X-0.849 Y-0.849 Z1 F9000  ; travel to X arm start
G1 X0.849 Y0.849 Z1 E0.262 F900  ; X arm 1
G0 X-0.849 Y0.849 Z1 F9000   ; travel to X arm 2 start
G1 X0.849 Y-0.849 Z1 E0.326 F900  ; X arm 2

Copilot AI changed the title Revamp tree support: anatomically-correct trunk → branch → twig structure at ≤45° Revamp tree support: anatomically-correct trunk → branch → twig structure at ≤45° with circular cross-sections Mar 3, 2026
@jgphilpott jgphilpott marked this pull request as ready for review March 3, 2026 11:03
Copilot AI review requested due to automatic review settings March 3, 2026 11:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR overhauls the tree support generator to produce a converging trunk→branch→twig segment structure (≤45° target) and renders each node as a circular “O + X” cross-section, replacing the previous grid-like behavior so tree supports look and behave distinctly from normal supports.

Changes:

  • Replaced trunk-grid / line-grouping approach with a precomputed segment tree (buildTreeStructure) + per-layer segment intersection rendering (generateTreePattern).
  • Added node rendering as circular perimeter + diagonal X infill (renderNodeAt) and point convergence via deduplicatePoints.
  • Updated/expanded tree support tests and refreshed LFS G-code fixtures for tree-support examples.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/slicer/support/tree/tree.coffee Implements precomputed trunk/branch/twig segments and per-layer node rendering (O+X circle nodes).
src/slicer/support/tree/tree.test.coffee Replaces old trunk-grid/line-grouping tests with new structure/rendering/deduplication tests and cache assertions.
resources/gcode/support/tree/dome/upright.gcode Updates stored tree-support example output (LFS pointer).
resources/gcode/support/tree/dome/sideways-everywhere.gcode Updates stored tree-support example output (LFS pointer).
resources/gcode/support/tree/arch/upright.gcode Updates stored tree-support example output (LFS pointer).
resources/gcode/support/tree/arch/sideways-everywhere.gcode Updates stored tree-support example output (LFS pointer).

@jgphilpott
Copy link
Owner

@copilot apply changes based on the comments in this thread

…conditional test assertion

Co-authored-by: jgphilpott <4128208+jgphilpott@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 3, 2026

@copilot apply changes based on the comments in this thread

All four issues from that review thread are addressed in commit cd147f9:

  1. Clustering stability — changed from Math.round(tip.x / clusterSpacing) to Math.floor((tip.x - minX) / clusterSpacing) to anchor cluster boundaries to the region's own minX/minY instead of world origin. Added a test that verifies two identical regions at different absolute positions produce the same segment count.

  2. Duplicate trunk segments — now computes all branchRootZ values first, then emits a single trunk segment from buildPlateZmax(branchRootZs). Added a test asserting exactly one trunk segment regardless of branch count.

  3. Missing trunk when branchRootZ clamped — the old guard (if branchRootZ > buildPlateZ + layerHeight) suppressed the trunk for wide/low overhangs. The new design seeds trunkTopZ from buildPlateZ + layerHeight so the trunk is always emitted. Added a test for this exact scenario.

  4. Misleading 45° comment — removed the "Enforce 45-degree constraint" wording; new comment accurately states the ideal height uses the 45° rule but the clamp may reduce the effective angle for wide or low overhangs.

  5. Silent conditional test — replaced if startMatch and endMatch { expect... } with unconditional expect(startMatch).toBeTruthy() / expect(endMatch).toBeTruthy() so a G-code format change fails loudly.

Copilot AI mentioned this pull request Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants