Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: calculate instanced mesh bounds after update #2268

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

davidboy
Copy link
Contributor

@davidboy davidboy commented Dec 12, 2024

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:

Certain library features like view frustum culling or ray casting rely on up-to-date bounding volumes (bounding sphere and bounding box). Because of the way how InstancedMesh works, the class has its own boundingBox and boundingSphere properties that supersede the bounding volumes on geometry level... Similar to geometries you have to recompute the bounding box and sphere whenever you change the underlying data.

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.

  • Ready to be merged

Copy link

vercel bot commented Dec 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
drei ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 12, 2024 1:54am

Copy link

vercel bot commented Dec 12, 2024

@davidboy is attempting to deploy a commit to the Poimandres Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

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