Repository navigation
Improve merge cost metric and fix a clip crash - #110
Merged
Merged
Conversation
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
force-pushed
the
merge-cost-metric
branch
from
August 19, 2026 03:12
76d362e to
1b672cd
Compare
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.
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.
Two independent changes to CoACD’s core.
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.
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.