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

InstancedBufferGeometry.maxInstancedCount => .instanceCount #19135

Merged
merged 1 commit into from May 11, 2020

Conversation

WestLangley
Copy link
Collaborator

Fixes #18990.

I'll update the migration docs if this is merged.

@WestLangley WestLangley added this to the r116 milestone Apr 15, 2020
@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 15, 2020

Don't you think it's better to name the property just count so it's aligned to InstancedMesh?

@WestLangley
Copy link
Collaborator Author

@Mugen87 OK, if you want.

But now that I think about it, I am wondering if this PR is even a good idea...

Having a count property would lead users to think they have to set it -- and they don't. It works similar to drawRange.count, which also defaults to Infinity. The renderer will not try to render more instances than the buffer will allow. The users do not have to set count at all.

Maybe leave the API the same?

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 15, 2020

I think the thing is that you want to align the API towards drawRange whereas I want to align it to InstancedMesh :)

When creating an instance of InstancedMesh, count is a mandatory parameter. If not assigned, the respective property will be undefined and the creation of instanceMatrix will fail. I think it would be great if the instancing API (InstancedMesh and InstancedBufferGeometry ) have similar semantics. However, I also understand the benefits to make it consistent to how drawRange works. Especially since maxInstancedCount is no mandatory parameter. Um, I'm not sure about all this...

@mrdoob What is your preference here? 😊

@WestLangley
Copy link
Collaborator Author

With InstancedMesh, count is required because the constructor allocates the instanceMatrix buffer.

With InstancedBufferGeometry, the user allocates the buffers, because there can be any number of them. maxInstancedCount, which is optional, serves the same purpose as drawRange in that case.

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 15, 2020

Yes, that's important to highlight.

@WestLangley
Copy link
Collaborator Author

I think this PR is good-to-go.

@mrdoob mrdoob modified the milestones: r116, r117 Apr 30, 2020
@WestLangley
Copy link
Collaborator Author

@mrdoob tl;dr

Currently, .maxInstancedCount is used to specify the number of instances to render, and there is no check preventing the renderer from trying to render more instances than the buffer will allow.

This PR renames the property to .instanceCount, and also adds a check preventing the mentioned rendering error -- just as we do with .drawRange.

@mrdoob mrdoob merged commit f177bce into mrdoob:dev May 11, 2020
@mrdoob
Copy link
Owner

mrdoob commented May 11, 2020

Thanks!

@WestLangley WestLangley deleted the dev_instanced_buffer_geo branch May 12, 2020 00:57
bitowl added a commit to bitowl/three-instanced-mesh that referenced this pull request May 29, 2020
Since mrdoob/three.js#19135 the default value for instanceCount is Infinity.
The copy function of InstancedBufferGeometry overwrites this value with undefined from the source. If instanceCount is undefined, the Math.min() in the renderer leads to NaN and zero instances are rendered.
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.

InstancedBufferGeometry: maxInstancedCount property
3 participants