06-11-2019, 06:45 PM
(This post was last modified: 06-11-2019, 06:47 PM by josemendez.)
(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.