Skip to content

Improve merge cost metric and fix a clip crash - #110

Merged
SarahWeiii merged 2 commits into
mainfrom
merge-cost-metric
Aug 19, 2026
Merged

SarahWeiii merged 2 commits into
mainfrom
merge-cost-metric

Conversation

@SarahWeiii

Copy link
Copy Markdown
Owner

Two independent changes to CoACD’s core.

  1. Merge cost measured against the part meshes instead of their hulls (src/process.cpp, +28/−31)

MergeConvexHulls scored a candidate merge as the concavity it adds relative to the two hulls being merged. That’s an increment, not the concavity of the result — the hulls are already approximations, so successive merges stack error that no single step ever sees. precostMatrix existed to compensate, tracking each part’s spent budget and refusing merges whose increment exceeded the remainder.

Scoring the merged hull against the union of the two parts’ original meshes is an absolute measure — how concave the result is w.r.t. the geometry it must cover, regardless of how many merges produced it. The error can’t accumulate unnoticed, so the precost bookkeeping is dropped, along with two ComputeHCost calls per pair at resolution 3000 in the setup loop.

61-mesh V-HACD benchmark: 34.10 → 31.49 hulls (−7.6%), max concavity 0.0493 → 0.0486, runtime 16.4s → 15.7s. 27 meshes improve, 9 regress by at most 2 hulls, 25 unchanged. ⚠️ This changes default output — decompositions generally come back with fewer hulls.

  1. Don’t abort when a cutting plane passes through a vertex (src/clip.cpp, +24/−5)

A plane cutting a triangle through one of its vertices makes all three edges report an intersection. Clip handles this, identifying the vertex via two tests with inconsistent tolerances (Side 1e-6, SamePointDetect 1e-5). A plane missing a vertex by an amount between them satisfies neither and fell through to a throw that aborts the process (called from an OpenMP region, nothing catches it). Real occurrence in Octocat-v2: vertex 1.13e-6 from the plane, intersection points 1.24e-5 apart. Now falls back to the closest vertex; existing tests run first and are unchanged, so only previously-aborting inputs behave differently. screwdriver.off from the V-HACD set used to SIGABRT and now decomposes into 20 hulls.

MergeConvexHulls scored a candidate merge with ComputeHCost(cvx1, cvx2,
combinedCH), i.e. the concavity the merge adds relative to the two hulls
being merged. That is an increment, not the concavity of the result: the
hulls are already approximations, so successive merges stack error that
no single step ever sees. precostMatrix existed to compensate, tracking
the budget each part had spent and refusing merges whose increment
exceeded the remainder.

Score the merged hull against the union of the two parts' original
meshes instead. That is an absolute measure - it states how concave the
resulting hull is with respect to the geometry it must cover, no matter
how many merges produced it - so the error cannot accumulate unnoticed
and the precost bookkeeping is no longer needed. It also removes two
ComputeHCost calls per pair at resolution 3000 from the setup loop.

On the 61-mesh vhacd benchmark: 34.10 -> 31.49 hulls (-7.6%), max
concavity 0.0493 -> 0.0486, runtime 16.4s -> 15.7s. 27 meshes improve,
9 regress by at most 2 hulls, 25 are unchanged.

Note this changes default output: decompositions generally come back
with fewer hulls than before.
A plane that cuts a triangle while passing through one of its vertices
makes all three edges report an intersection: the opposite edge is
genuinely crossed, and the two edges sharing that vertex both intersect
at the vertex itself. Clip recognises this and merges the duplicate
intersection into a single border vertex, deciding which vertex is
involved from two tests - the vertex lies on the plane (Side, eps 1e-6),
or two intersection points coincide (SamePointDetect, eps 1e-5).

Those tolerances do not agree, so a plane that misses a vertex by an
amount between them satisfies neither test and the case fell through to
a throw that aborts the process (it is called from an OpenMP region, so
nothing catches it). A real occurrence from Octocat-v2: the vertex sits
1.13e-6 from the plane, just past Side's 1e-6, and the two intersection
points are 1.24e-5 apart, just past SamePointDetect's 1e-5.

Resolve the vertex by falling back to whichever one is closest to the
plane when neither test fires. The existing tests are unchanged and run
first, so inputs that already worked take exactly the same path; only
inputs that used to abort behave differently, and the geometric error
introduced equals the vertex-to-plane distance - 1.13e-6 above, against
a mesh normalised to [-1,1].

screwdriver.off from the V-HACD set aborted with SIGABRT before this and
now decomposes into 20 hulls.
@SarahWeiii
SarahWeiii merged commit b6969c2 into main Aug 19, 2026
8 of 9 checks passed
SarahWeiii added a commit that referenced this pull request Aug 19, 2026
MergeConvexHulls scored a candidate merge with ComputeHCost(cvx1, cvx2,
combinedCH), i.e. the concavity the merge adds relative to the two hulls
being merged. That is an increment, not the concavity of the result: the
hulls are already approximations, so successive merges stack error that
no single step ever sees. precostMatrix existed to compensate, tracking
the budget each part had spent and refusing merges whose increment
exceeded the remainder.

Score the merged hull against the union of the two parts' original
meshes instead. That is an absolute measure - it states how concave the
resulting hull is with respect to the geometry it must cover, no matter
how many merges produced it - so the error cannot accumulate unnoticed
and the precost bookkeeping is no longer needed. It also removes two
ComputeHCost calls per pair at resolution 3000 from the setup loop.

On the 61-mesh vhacd benchmark: 34.10 -> 31.49 hulls (-7.6%), max
concavity 0.0493 -> 0.0486, runtime 16.4s -> 15.7s. 27 meshes improve,
9 regress by at most 2 hulls, 25 are unchanged.

Note this changes default output: decompositions generally come back
with fewer hulls than before.
@SarahWeiii
SarahWeiii deleted the merge-cost-metric branch August 19, 2026 03:26
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.

1 participant