Rebuild mesh collision shapes when the entity world scale changes#9049
Open
willeastcott wants to merge 1 commit into
Open
Rebuild mesh collision shapes when the entity world scale changes#9049willeastcott wants to merge 1 commit into
willeastcott wants to merge 1 commit into
Conversation
The rebuild-on-scale-change check in updateMeshTransform has been dead code since the Designer livelink was removed in 2015 - onTransformChanged had no callers, so scaling an entity with a mesh collider at runtime never rebuilt the shape. The collision system now watches mesh components with a built shape and rebuilds them from the rigid body update loop when their world scale drifts from the scale the shape was built with. The Ammo backend also no longer caches triangle data that has a bake scale: the cache is keyed by mesh id alone, so baked-scale data leaked the first builder's scale into every other user of the mesh and made rebuilds return stale geometry (the reason the manual doRecreatePhysicalShape workaround stopped working after #6087). Scaled builds are now owned by their shape and destroyed with it, so continuous scale tweens don't grow the cache. Fixes #6212 Fixes #3062 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Build size reportThis PR changes the size of the minified bundles.
|
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.
Scaling an entity with a mesh collider at runtime never rebuilt the shape: the
updateMeshTransformscale check was only reachable throughonTransformChanged, whose last caller (the Designer livelink) was removed in 2015. This PR wires that check up for real: the collision system keeps a list of mesh components with a built shape, and the rigid body update loop rebuilds any whose entity world scale has drifted from the scale the shape was built with (compared with a relative tolerance, so rotation-induced float noise in the extracted scale doesn't churn shapes).Two supporting fixes in the Ammo backend:
doRecreatePhysicalShapeworkaround stopped working after Mesh collision optimization #6087 (Mesh collider no longer scales in real time #6212). Unit-scale sources still share cached data as before.Compound children are skipped by the watch (their rebuild path doesn't detach the old shape from the parent compound), and the legacy model-asset path is untouched.
Verified headlessly against real ammo.js with raycast probes: rescale 1→2 moves the hit surface accordingly (and only after the physics tick), same-mesh entities at scales 2 and 3 coexist, a 200-step scale tween leaves the cache at one entry, convex hulls rebuild too, and rotation alone doesn't recreate the shape. All checks fail on main as described in the issues.
Fixes #6212
Fixes #3062
🤖 Generated with Claude Code