Skip to content

Rebuild mesh collision shapes when the entity world scale changes#9049

Open
willeastcott wants to merge 1 commit into
mainfrom
mesh-collision-scale-rebuild
Open

Rebuild mesh collision shapes when the entity world scale changes#9049
willeastcott wants to merge 1 commit into
mainfrom
mesh-collision-scale-rebuild

Conversation

@willeastcott

Copy link
Copy Markdown
Contributor

Scaling an entity with a mesh collider at runtime never rebuilt the shape: the updateMeshTransform scale check was only reachable through onTransformChanged, 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:

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

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>
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Build size report

This PR changes the size of the minified bundles.

Bundle Minified Gzip Brotli
playcanvas.min.js 2280.3 KB (+0.6 KB, +0.03%) 587.8 KB (+0.3 KB, +0.05%) 456.9 KB (+0.3 KB, +0.05%)
playcanvas.min.mjs 2277.7 KB (+0.6 KB, +0.03%) 586.9 KB (+0.3 KB, +0.05%) 456.7 KB (+0.2 KB, +0.04%)

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.

Mesh collider no longer scales in real time Multiple Mesh Colliders of Different Scales don't behave properly

1 participant