Skip to content

fix(physics): collider auto-fit no longer inflates rotated shapes on load - #113

Open
Drima-code wants to merge 1 commit into
renzora:mainfrom
Drima-code:fix-collider-autofit-rotation
Open

Drima-code wants to merge 1 commit into
renzora:mainfrom
Drima-code:fix-collider-autofit-rotation

Conversation

@Drima-code

Copy link
Copy Markdown

Summary

Auto-fit resizes any CollisionShapeData that still has its default values, which includes every scene load of a unit-mesh object whose collider was never resized (a cube with a default box collider). The fit built a world-axis AABB of the mesh and mapped its corners back into local space, which is only exact without rotation. So reopening a scene silently grew the collider of every rotated object, and the inflated values were then saved.

Example: a cube rotated 15 degrees about Y and scaled (5, 0.5, 4) reopened with half extents (0.70, 0.5, 0.8125) instead of (0.5, 0.5, 0.5), so its collision no longer matched its mesh. Unrotated objects also drifted from 0.5 to 0.49999997 on each load.

Changes

  • combined_world_aabb becomes combined_local_aabb: each mesh AABB corner is transformed straight into the collider entity's local space (inverse(entity GlobalTransform) * child GlobalTransform * corner), so the bounds are exact under rotation and non-uniform scale.
  • The fitted shape is only written if it differs from the stored one (1e-4), so a shape that already fits is left untouched and loading no longer dirties the scene with float noise.
  • New regression test crates/renzora_physics/tests/auto_fit_rotated.rs.
  • One RELEASE_NOTES.md line.

Related Issues

None filed; found while evaluating the editor for a project.

AI Assistance

Assisted-by: Claude Opus 5.5 (claude-opus-5-5)

Checklist

  • Code compiles cleanly (renzora check): not run in the container; see Testing
  • All existing tests pass (renzora test): only the new test was run; see Testing
  • New tests added (if applicable)
  • No unrelated formatting or refactoring changes
  • Branch is up to date with main
  • I have read every line of this diff and can explain it in review
  • Any AI assistance is disclosed above and in an Assisted-by: commit trailer

Testing

Run natively on Linux (Rust 1.95.0) from an r1-alpha7 checkout carrying the same change (auto_fit.rs is byte-identical between r1-alpha7 and main).

  • cargo test --profile dist -p renzora_physics --test auto_fit_rotated: passes. With the original auto_fit.rs swapped back in, it fails with half extents changed to Vec3(0.70000005, 0.5, 0.8125), the same values seen in the editor.
  • In the editor: built a scene with rotated and unrotated default-collider cubes, saved, closed, reopened and saved again without edits. Before the fix the rotated cube's collider changed on reopen; after it, the two saves are identical apart from session entity ids.
  • cargo clippy --profile dist --no-deps -p renzora_physics -- -D warnings -A clippy::too_many_arguments -A clippy::type_complexity reports nothing in the changed code (the only hit on r1-alpha7 is the unused_mut at lib.rs:255, already fixed on main).

…load

Auto-fit runs for any default-valued CollisionShapeData, which includes every
scene load of a unit-mesh object whose collider was never resized. The fit took
a world-axis AABB of the mesh and mapped its corners back into local space,
which is only exact without rotation: a 15 degree Y platform scaled
(5, 0.5, 4) came back with half extents (0.70, 0.5, 0.81), so after reopening
the scene its collision no longer matched its mesh, and the inflated values were
then saved.

Bounds are now accumulated per corner in the collider's own local space, and a
fit that already matches the stored shape is not written, which also stops 0.5
drifting to 0.49999997 on unrotated objects.

tests/auto_fit_rotated.rs fails on the old code with exactly the inflated
extents above and passes with the fix. Also validated in a running editor:
save, close, reopen and save again now produce a scene that is identical apart
from session entity ids.

Assisted-by: Claude Opus 5.5 (claude-opus-5-5)
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.

1 participant