Selecting Individual Particles During Runtime - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Cloth (https://obi.virtualmethodstudio.com/forum/forum-2.html) +--- Thread: Selecting Individual Particles During Runtime (/thread-1461.html) |
Selecting Individual Particles During Runtime - 3rdcat - 06-11-2019 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 RE: Selecting Individual Particles During Runtime - josemendez - 06-11-2019 (06-11-2019, 11:50 AM)3rdcat Wrote: Hello 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]; RE: Selecting Individual Particles During Runtime - 3rdcat - 06-11-2019 (06-11-2019, 01:12 PM)josemendez Wrote: Hi, 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? RE: Selecting Individual Particles During Runtime - josemendez - 06-11-2019 (06-11-2019, 01:18 PM)3rdcat Wrote: Hello, 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. RE: Selecting Individual Particles During Runtime - 3rdcat - 09-11-2019 (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]]. Thank you for the detailed explanation, it was very helpful. Can't wait for the exciting things inĀ 5.0! |