Fix bug with nonuniform scaling in mesh vs convex collisions#2745
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughThis PR fixes a bug where triangle-mesh-vs-convex collisions could drop contacts under non-uniform or large uniform mesh scaling by converting scaled AABBs into the BVH's unscaled mesh-local space and applying per-axis contact gap adjustments; helpers and tests are added. ChangesMesh Scaling Collision Detection
Sequence Diagram(s)sequenceDiagram
participant Convex
participant Mesh
participant aabb_to_unscaled
participant BVH
participant NarrowPhase
Convex->>Mesh: compute tight AABB in mesh scaled-local frame
Mesh->>aabb_to_unscaled: convert scaled AABB -> BVH unscaled space
aabb_to_unscaled->>BVH: submit AABB query (with per-axis margins)
BVH-->>NarrowPhase: triangle list
NarrowPhase-->>Convex: contact buffer / normals
Possibly related PRs
Suggested reviewers
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Description
Fix triangle-mesh-vs-convex collisions silently dropping all contacts under non-uniform (and even large uniform) mesh scale. The mesh BVH is built over unscaled
mesh.points, but the AABB query inmesh_vs_convex_midphasewas performed in scaled mesh-local space. Any convex shape whose unscaled-space AABB lay outside the BVH bounds received 0 triangles and 0 contacts. The query AABB and per-axis contact gap are now converted from scaled to unscaled (BVH) space before the BVH overlap test.Also adds two small helper funcs in
collision_core.py:aabb_to_unscaled— convert an AABB from a component-wise scaled frame to the unscaled frame, swapping per-axis min/max under negative scale.transform_normal_with_scale— correct normal transform under non-uniform component-wise scale (R · (n / scale), normalized).Checklist
CHANGELOG.mdhas been updated (if user-facing change)Test plan
New regression class
TestMeshNonUniformScalinginnewton/tests/test_narrow_phase.pydrops a sphere onto a unit-quad mesh with various scales (uniform, large uniform, pancake(10,10,1), thin(1,1,0.1), extreme(50,0.5,1)) and asserts contacts are produced with sane unit-length, roughly +Z normals; a far-separated case asserts 0 contacts (no false positives).Bug fix
Triangle-mesh-vs-convex collisions silently produce zero contacts whenever the mesh shape uses a non-uniform scale (e.g.
(10, 10, 1)), and even for sufficiently large uniform scales. Mesh-averaging of the scale caused the AABB query against the BVH (which lives in unscaled mesh-local space) to miss all triangles.Steps to reproduce:
scale=(sx, sy, sz)(e.g.(10, 10, 1)).contact_count == 0.Minimal reproduction:
Summary by CodeRabbit
Bug Fixes
Tests