Expandable sps with invisible dummy particle

Hello,

we have a following use case: we have an exandable SPS whose shapes need to be generated dynamically on the fly. We also have 1 invisible dummy particle that we dont need but I understand this is the current limitation of SPS as per documentation: Important note: the SPS must contain at least one particle to work, so never empty it completely !

Now during the runtime sometimes we need to remove all the particles (except the dummy one), generate a new shape and add some new particles with this shape: the following playground demonstrates this use case and an unexpected behaviour that I believe might be a bug?

Playground

The scene starts with a single invisible particle - which is correct - and then when you click anywhere in the scene, old particles (if any) except the dummy one get removed, new particles get generated BUT for some reason the dummy particle becomes visible, its position resets to 0,0,0 and there is nothing i can do to hide it anymore :open_mouth:

Does anyone know if this is a bug? As an alternative we could just dispose the whole SPS and create it anew each time we need to generate new shapes, but isnt that an unnecessary overhead?

Thanks!

Hello! I will take a look at this :slight_smile:

1 Like

There was indeed a problem with invisible particles after a call to buildMesh, have a PR up to fix: Fix invisible particles being visible again after a call of buildMesh by carolhmj · Pull Request #12878 · BabylonJS/Babylon.js (github.com)

1 Like

wow that was fast (as usual :slight_smile: ), thank you!

1 Like

One more question just out of curiosity: why does SPS always need to have at least 1 particle? The docs mention only this warning: Important note : the SPS must contain at least one particle to work, so never empty it completely ! but no explanation as to why.

However, if its really required, would it be possible to at least allow developers to remove/add particles freely and an error would be only thrown the next time buildMesh or setParticles is called and there is 0 particles? So the responsibility to keep at least 1 particle is delegated to the developer instead of automatically guarding this as now. Now I can never remove all the particles - if I call removeParticles(0, nbParticles - 1) there is still 1 left.

Thank you

Hmmm I think is just so the SPS mesh always has vertex information :thinking: @Deltakosh @sebavan do you think we can relax this?

Let me add @jerome to the thread

1 Like

Yes, that’s the reason why : the SPS is a mesh, so it needs at least 3 vertices.