06-08-2021, 12:02 PM
(06-08-2021, 08:14 AM)josemendez Wrote: particleIndex is the index of a particle in the solver. this.solver.particleToActor[particleIndex].indexInActor is the index of the particle in an actor. It's two entirely different things. From the manual, scripting particles section:
Say you have 3 actors: the first one has 5 particles, the second one has 3, and the third one has 4. Actor particle indices for them are 0-4, 0-2 and 0-3. But the solver (that stores all particle data) might have assigned completely different indices for them. Particles for the first actor might have their data stored at indices 21,33,34 and 36, the second one 3,5 and 9, and the third one 1,2,4 and 6, in the solver arrays. To access per-actor data you'd use actor indices (particleIndex in your case). To access the main solver arrays (positions, velocities, orientations, etc) you'd use solver indices.
Also, your TearAtIndex() method doesn't make any sense. You're using the index of a particle in the actor to look up an array of elements. If this works, it's purely out of luck. Will result in an out of bounds exception most of the time.
Code:if (index < rope.elements.Count)
{
this.rope.Tear(rope.elements[index]); //<---can't access elements using a particle index!!
}
Elements are the "edges" in between particles, that hold them together. Each element joins exactly two particles together, so it has two solver indices in it. You should iterate trough all elements until you find the one that references your particle. Like so:
Code:void TearAtIndex(int index) //<---pass a solver index here, that is your particleIndex.
{
foreach(var element in rope.elements)
{
if (element.particle1 == index){
this.rope.Tear(element);
break;
}
}
this.rope.RebuildConstraintsFromElements();
}
Thank you very much ! I was confused at "But the solver (that stores all particle data) might have assigned completely different indices for them." and now things become clearer !