Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selecting Individual Particles During Runtime
#1
Hello

I was wondering if it is possible to change the properties of individual particles via script during runtime.
I understand from the examples that it is possible to change them collectively, but is choosing specific ones from the index possible? (i.e changing the particle weight of a line of particles on the cloth without affecting others)
Thank you very much
Reply
#2
(06-11-2019, 11:50 AM)3rdcat Wrote: Hello

I was wondering if it is possible to change the properties of individual particles via script during runtime.
I understand from the examples that it is possible to change them collectively, but is choosing specific ones from the index possible? (i.e changing the particle weight of a line of particles on the cloth without affecting others)
Thank you very much

Hi,

I'm not sure I understand your question. You can change particle properties collectively or individually, as long as you have their indices. For instance, to change the velocity of particle "i" in the actor:

Code:
int indexInSolver = actor.particleIndices[i];
solver.velocities[indexInSolver] = Vector3.zero;
Reply
#3
(06-11-2019, 01:12 PM)josemendez Wrote: Hi,

I'm not sure I understand your question. You can change particle properties collectively or individually, as long as you have their indices. For instance, to change the velocity of particle "i" in the actor:

Code:
int indexInSolver = actor.particleIndices[i];
solver.velocities[indexInSolver] = Vector3.zero;

Hello,

Thanks for the reply.
I was wondering how to obtain the specific indice which a particle is allocated to.
For example, if I use the cloth sheet from the example which has... 289 particles, how would I know which particle corresponded to which indice?
Reply
#4
(06-11-2019, 01:18 PM)3rdcat Wrote: Hello,

Thanks for the reply.
I was wondering how to obtain the specific indice which a particle is allocated to.
For example, if I use the cloth sheet from the example which has... 289 particles, how would I know which particle corresponded to which indice?

Well, each actor has a "particleIndices" array that tells you exactly what index in the solver is that particle allocated to. For instance, the first particle in the cloth is at cloth.particleIndices[0]. So if you use that to index the solver arrays, you get the position/velocity/ whatever of that particle: solver.positions[cloth.particleIndices[0]].

Sometimes you're interested in particles that meet some property. Generally you need to iterate over all of them, performing a test (proximity to another object, alignment to an axis, velocity over a threshold, etc). Otherwise, an actor is just a bunch of particles, just like a mesh is a bunch of vertices. How you'd know which vertex indices are part of the arm of a character? well, you just cannot know.

In Obi 5.0, we've added the concept of particle "groups". This allows you to group particles together in editor, and later retrieve these groups by code. This way you can attach semantic data to certain particles that have a special meaning or purpose for you. For instance, you could select all particles in a character's arm, put them under a group called "arm", then retrieve their indices at runtime.
Reply
#5
(06-11-2019, 06:45 PM)josemendez Wrote: Well, each actor has a "particleIndices" array that tells you exactly what index in the solver is that particle allocated to. For instance, the first particle in the cloth is at cloth.particleIndices[0]. So if you use that to index the solver arrays, you get the position/velocity/ whatever of that particle: solver.positions[cloth.particleIndices[0]].

Sometimes you're interested in particles that meet some property. Generally you need to iterate over all of them, performing a test (proximity to another object, alignment to an axis, velocity over a threshold, etc). Otherwise, an actor is just a bunch of particles, just like a mesh is a bunch of vertices. How you'd know which vertex indices are part of the arm of a character? well, you just cannot know.

In Obi 5.0, we've added the concept of particle "groups". This allows you to group particles together in editor, and later retrieve these groups by code. This way you can attach semantic data to certain particles that have a special meaning or purpose for you. For instance, you could select all particles in a character's arm, put them under a group called "arm", then retrieve their indices at runtime.

Thank you for the detailed explanation, it was very helpful.
Can't wait for the exciting things inĀ 5.0!
Reply