fix: BvhNode::scale now handles negative scale components correctly#406
Open
robtfm wants to merge 1 commit intodimforge:masterfrom
Open
fix: BvhNode::scale now handles negative scale components correctly#406robtfm wants to merge 1 commit intodimforge:masterfrom
robtfm wants to merge 1 commit intodimforge:masterfrom
Conversation
Previously, scaling an AABB by a negative factor would produce an inverted AABB (mins > maxs on the negated axis), breaking the BVH invariant and causing all intersection/shapecast queries to silently miss geometry. Fix by taking component-wise min/max of the two scaled corners, so the AABB invariant is preserved regardless of sign. The parent-child containment property of the BVH is maintained since scale(merge(A,B)) == merge(scale(A),scale(B)) holds for any non-zero scale. This unblocks use of TriMesh::scaled with negative scale (e.g. reflections).
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.
check/update bvh for negative scales and remove arg condition. this condition was not mentioned in (at least)
TriMesh::scaled_by, doesn't seem expensive to check correctly, and is on an infrequent codepath.--
Previously, scaling an AABB by a negative factor would produce an inverted AABB (mins > maxs on the negated axis), breaking the BVH invariant and causing all intersection/shapecast queries to silently miss geometry.
Fix by taking component-wise min/max of the two scaled corners, so the AABB invariant is preserved regardless of sign. The parent-child containment property of the BVH is maintained since scale(merge(A,B)) == merge(scale(A),scale(B)) holds for any non-zero scale.
This unblocks use of TriMesh::scaled with negative scale (e.g. reflections).