fix: calculate instanced mesh bounds after update #2268
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.
Background
We are using the <Merged /> component for a visual that has a number of different possible shapes. A single
<Merged />
is rendered to provide instanced meshes for each of these shapes.We were encountering a bug where, after changing from one shape to another, a visual would begin disappearing at certain camera zoom levels. I suspected this was caused by frustum culling. See the video below for an example. I have not yet been able to reproduce this behavior in a code sandbox.
chrome_coHzuv9Hd4.mp4
What
The "How to update things" article from the three.js documentation, when talking about
InstancedMesh
, states:My interpretation of the above paragraph is that we need to re-calculate the bounding sphere of an instanced mesh whenever the instance matrix is changed. This pull request modifies
<Instances />
to check whether an instanced mesh has a bounding sphere or bounding box when updating its instance matrix, and if it does, recalculates them.This change fixes the issue that we were experiencing, and makes sense to me based on my reading of the documentation, so I have not continued to investigate further. If you suspect I am misunderstanding the root cause of the bug or this proposed fix, or if it would be helpful for me to continue attempting to reproduce the issue in a code sandbox, please let me know. Thanks.