PCS - is it possible to (quickly) update particles with given index?

Hello,
I’ve a CPS with 50000 particles.
I’d like to move them “one after the other”, not all toghether.
So, I’ve created an array (let’s name it “particlesThatMove”) in which, at a defined interval, I push a new random particle ID.
Checking this array of ID, my CPS particles should move or not
The problem is that the “SetParticle” function does not get an array of ID, just a range (from-to).
I know that I could check, in the “UpdateParticle” function, if the given particle “idx” is included in the “particlesThatMove” array, but this way I would have a massive iteration, that increase every time, so the CPU get overload…
Is there a better solution?

P.S. You could ask: why don’t you use a standard particle system? well, the answer is that with standard particle system I can’t get such a regular particle distribution on the mesh, and so it’s quite unpossible to me to give a regular shape to the mesh

This is my demo
https://playground.babylonjs.com/#UI95UC#786

Many thanks!

You can specify what is the range of particles you want to update with setParticles :smiley: :

Point Cloud System particle sequential update | Babylon.js Playground (babylonjs.com)

Just saw your demo, there is also another approach that can be taken! Since checking for array membership can be an expensive operation, you can instead store the information if the particle can be moved in each individual particle. Then, at each update, some of the particles that haven’t been moved yet have a chance to start moving:

Points Cloud System | Babylon.js Playground (babylonjs.com)

Yes, but it’s a range, not a “per Index”[quote=“carolhmj, post:2, topic:25542, full:true”]
You can specify what is the range of particles you want to update with setParticles :smiley: :

Point Cloud System particle sequential update | Babylon.js Playground (babylonjs.com)
[/quote]

A range of index, index+1 works the same as updating a single particle :slight_smile:

Thanks a lot carolhmj for your help,
but I should need to better understand…

  1. surely I can use a range of index in “setParticles” function, but if my index is not a range but is randomly generated, for example from 0 to 10000, how can I manage it?
  2. About your suggestion, to store a new information in a single particle, do you mean that I can create a new property (for example: isMovable) for every particle?
    And, if this is the way, should I do that in the “beforeUpdateParticles” function ?
  1. If you have, lets say, 10000 particles, and for each update you want to move some random particle in that range, you can generate a number on that range (e.g Math.floor(Math.random()*10000)), then use it on the setParticles function. setParticles will update all particles on the range between the start and end arguments, so, if you want to update just the particle you chose randomly, you can do setParticles(randomIndex, randomIndex+1). If you want to update 10 particles, starting from that particle, you can do setParticles(randomIndex, randomIndex+10).
  2. Yes, you can create any property for your particles! You can do it on beforeUpdateParticles, but you can just do it in the updateParticle too. It depends on what you need the property for. If it was something like speed, and I wanted to have updated the speed of each particle before updating, then beforeUpdateParticles would be better.
4 Likes

Well, with a simple property it work a lot better,
but I have a weird issue: after some time I get the error “Cannot set properties of undefined”, just like some particles would not be there anymore…


I’ve tried to put all the idx of the particles that move in an array, to skip them, but with no luck
I’m missing something?
https://playground.babylonjs.com/#UI95UC#788

If you floor the index instead of rounding it, it will stay in bounds. Alternatively, you could keep using round but make the end value one less (particleNmb - 1). :slightly_smiling_face: :beers:
https://playground.babylonjs.com/#UI95UC#789

3 Likes

damn… so stupid…
Thanks!