Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Creating and Removing Pin Constraints from ObiPinConstraintsBatch
#5
Your code for detecting particles upon collision is wrong, this bit in particular:

Code:
var particle = item.bodyA;

You're using item.bodyA as if it were a particle index, but it's not: it is a body index (simplex or collider), in this particular case a simplex index. Accessing the particle(s) in that simplex can be done in one of two ways, depending on whether you're using surface collisions or not:

If using them, each simplex will have more than one particle in it:

Code:
// retrieve the offset and size of the simplex in the solver.simplices array:
int simplexStart = solver.simplexCounts.GetSimplexStartAndSize(contact.bodyA, out int simplexSize);

// starting at simplexStart, iterate over all particles in the simplex:
for (int i = 0; i < simplexSize; ++i)
{
int particleIndex = solver.simplices[simplexStart + i];

// do something with each particle, for instance get its position:
var position = solver.positions[particleIndex];
}

If not using them, each simplex is guaranteed to be just a single particle:

Code:
// get the particle index directly, as all simplices are guaranteed to have size 1:
int particleIndex = solver.simplices[contact.bodyA];

This is explained in the manual page for collision callbacks:
http://obi.virtualmethodstudio.com/manua...sions.html

Quote://q: this will resolve for all particles - isnt there quite an overhead calling this when we are only interested in a subset?
// can we only get this for a few particles or does this mean creating multiple solvers?

Solver.OnCollision will return all contacts detected during the frame by that particular solver, regardless of which particle/collider pairs are involved. You can't get only a subset, but you can use a variety of solutions to make checking them much faster: use multithreading, exploit temporal coherence, etc.

kind regards,
Reply


Messages In This Thread
RE: Creating and Removing Pin Constraints from ObiPinConstraintsBatch - by josemendez - 22-08-2023, 06:48 AM