BatchedMesh: add deleteInstance()#29449
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
gkjohnson
left a comment
There was a problem hiding this comment.
Thank you! #28638 also implemented deleteInstance but I quite like the approach of reusing instance Ids which will generally be more performant than having to re-pack the matrix & color buffers when trying to shrink and remap the list of instances.
The only potential point of confusion is that a user will have "deleted" an id only for it to be re-used again, which isn't necessarily severe. It just means that users will need to be diligent about tracking their ids.
cc @Mugen87 unless you have objections I'm happy with this approach for instance deletion and is a lot less complex than the other implementation. Supporting deletion / repacking of geometry is still an open question but we can address that in the future.
|
|
||
| // stores visible, active, and geometry id per object | ||
| this._drawInfo = []; | ||
| this._fragInfo = []; |
There was a problem hiding this comment.
What does the name "_fragInfo" refer to? It would be better to call this something like "availableInstanceIds"
There was a problem hiding this comment.
Sounds good, I like the name "availableInstanceIds". Will make that change
| let drawId = null; | ||
|
|
||
| // If at capacity, rewrite over an inactive block | ||
| if ( atCapacity ) { |
There was a problem hiding this comment.
I think we should check if there are any available deleted Ids and reuse those ids first rather than waiting until the full capacity has been used.
There was a problem hiding this comment.
I like this idea. It would be best to keep both the drawInfo and the available deleted ids as small as possible. I will make that change
Sounds good! |
3f5f814 to
114489b
Compare
|
@gkjohnson Updated the PR with your suggestions
|
Description
The
BatchedMeshcurrently has no way to remove an instance.Solution
Adding the
deleteInstance()method to theBatchedMeshclass will allow users to remove instances easily from theBatchedMesh.The previous commented out code stated that we would need to implement an
optimizefunction to be able to repack the data. Instead, I added a_fragInfoarray to keep track of 'fragmented' or open blocks. The BatchedMesh will still fill the DataTexture the same way it did before, but once it is at capacity, then it will begin adding instances to open spots in the Texture.Additional context
The BatchedMesh has been a pleasure to work with, I just need the ability to remove existing instances. This is my first time opening a PR to three.js, so please let me know if I am missing anything. I am open to any additional changes or suggestions!