-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
InstancedBufferGeometry._maxInstanceCount preventing instances from being rendered #26363
Comments
Your use case is not supported since the count property represents the maximum number of instances. Meaning after the first render, you can only have instances in the range The reason behind this restriction is the fact that buffers can't be resized after the first render. We do not want to implement some sort of auto-detection and resizing in the renderer since this comes with a performance hit. Especially the resize itself is costly and should be avoided whenever possible. If you have to increase the count of your instances over time, you have to dispose the old geometry and create a new one. The more recommended approach though is to create the geometry with a sufficient size so a resize is not necessary over time. |
ok so what I'm hearing is that instead, set I think this read-only distinction could be made a bit more clear in the docs, as there are a number of other "counts" that are meant to be set (e.g. drawRange, updateRange, instanceCount, etc). thanks for the quick reply. |
Yes, Indeed, it does make sense to clarify the docs and mark this property as read-only. |
Description
I ran into this issue when I tried to increase the
count
on a largeInstancedInterleavedBuffer
. During the initial rendergeometry._maxInstanceCount
was set toInstancedInterleavedBuffer.count
, and increasingInstancedInterleavedBuffer.count
andgeometry.instanceCount
later had no effect, causing additional instances to not render.Some options:
_maxInstanceCount
from the library, as it seems to be a bit of a patch anyway? An alternative could be to calculate an appropriateinstanceCount
only in the case thatgeometry.instanceCount
is not defined by looping through allInstancedBufferAttributes
orInstancedInterleavedBuffers
on theInstancedBufferGeometry
:three.js/src/renderers/WebGLRenderer.js
Lines 900 to 907 in 2f4e4e3
_maxInstanceCount
, could we change the following to support the full size of anInstancedInterleavedBuffer
rather than its currently set count:three.js/src/renderers/webgl/WebGLBindingStates.js
Lines 398 to 402 in 4e07037
to
Option 2 still has the downside of persisting an incorrect
_maxInstanceCount
if theInstancedInterleavedBuffer
and its associated attributes were to be swapped out with a larger buffer at a later time. I use this pattern in cases where I don't know exactly how big to init the buffers for user-generated geometry, and (while I do give them plenty of headroom) I don't want to init the buffers too big upfront until they are needed. This issue of replacing the buffers came up previously in Issue #21488Maybe an alternative on option 2 would be to update
geometry._maxInstanceCount
each time a newInstancedBufferAttribute
or attribute referencing anInstanceInterleavedBuffer
is attached to the geometry?Anyway, in the current code
_maxInstanceCount
seems to only be calculated based on attachedInstancedInterleavedBuffers
, when it should also depend on attachedInstancedBufferAttributes
.Thanks!
Reproduction steps
InstancedBufferGeometry
with instanceCount = 0 and attributes referencing anInstancedInterleavedBuffer
containing a large array, but count = 0.InstancedInterleavedBuffer
and increase the instanceCount of theInstancedBufferGeometry
to match.Code
The following line fixes the issue:
Live example
This example should add new geometry on each pointerdown on the canvas.
Uncommenting line 24 makes the example work.
Screenshots
No response
Version
r0.154
Device
Desktop
Browser
Chrome
OS
MacOS
The text was updated successfully, but these errors were encountered: