Skip to content

fix(flame_3d): Invalidate the AABB of a parent when a child is added or removed - #4180

Merged
ufrshubham merged 1 commit into
mainfrom
devkage/fix-3d-aabb-on-child-added
Oct 31, 2026
Merged

ufrshubham merged 1 commit into
mainfrom
devkage/fix-3d-aabb-on-child-added

Conversation

@ufrshubham

@ufrshubham ufrshubham commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Description

A Component3D's AABB is the hull of its own geometry and the AABBs of its children, but adding or removing a child didn't invalidate the parent's cached AABB. Object3D.renderTree culls a component together with its whole subtree using its AABB, so a child added inside the view was never rendered when the parent's cached AABB was outside of it, for example a spawner or pool that adds children to itself at runtime.

This PR marks the parent's AABB as dirty when a component is mounted, so new children are included in it. It does the same when a component is removed, which isn't visible but keeps the parent's AABB from staying bigger than its children. Marking stops at the first ancestor that is already dirty and the AABB is only recomputed lazily, so this costs the same as a child moving, which already marks its ancestors dirty.

The tests cover a child added to a parent, a child added deeper in the hierarchy and a child being removed, and all of them fail without the fix. I also verified the fix with the repro from #4164 on Windows.

This PR is stacked on top of #4167, as both add the same test file. It will be retargeted to main once #4167 is merged.

before_4164.mp4
after_4164.mp4

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • [-] I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • [-] I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

Closes #4164

@ufrshubham ufrshubham self-assigned this Oct 31, 2026
@ufrshubham
ufrshubham added this pull request to stack #4181 October 31, 2026 13:39
Base automatically changed from devkage/fix-3d-aabb-on-ancestor-move to main October 31, 2026 16:09
…or removed

A parent's AABB is the hull of its own geometry and the AABBs of its
children, but adding or removing a child didn't invalidate it. Since an
Object3D culls itself and its whole subtree using its AABB, a child added
inside the view could be skipped when the parent's cached AABB was outside
of it.

The parent's AABB is now marked dirty when a component is mounted or
removed.
@ufrshubham
ufrshubham force-pushed the devkage/fix-3d-aabb-on-child-added branch from bb957e4 to c342e18 Compare October 31, 2026 16:09
@ufrshubham
ufrshubham merged commit 2bb3118 into main Oct 31, 2026
8 checks passed
@ufrshubham
ufrshubham deleted the devkage/fix-3d-aabb-on-child-added branch October 31, 2026 16:34
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.

[flame_3d] Children added to an Object3D after it was rendered can be culled while on screen

2 participants