27-04-2022, 09:10 AM
(27-04-2022, 07:42 AM)josemendez Wrote: Hi!Thanks a lot for your help :)
Your code has many bugs:
- You're iterating trough actor constraints (whose indices reference actor particles), but you're passing a "collisionParticleIndex" which quite probably is solver index, if you're retrieving it directly from the solver.OnCollision event.
- You're passing batch.GetConstraintIndex(i) to the StructuralConstraint constructor, but "i" is already a constraint index (remember that you're iterating trough all constraints from 0 to activeConstraintCount). GetConstraintIndex() takes a constraint id and returns the index of the constraint in the internal arrays. You already have the constraint index "i", so no need to call GetConstraintIndex().
- You're calling flag.solver.PushSolverParameters(); but haven't modified any solver parameter. This call does nothing - except negatively affect performance.
- You're missing a call to cloth.UpdateDeformableTriangles(); after all Tear() operations. The mesh topology isn't be updated at all right now, so any tears will turn the cloth into a triangle mess since particles/constraints are updated but the mesh is not.
I'd recommend taking a look at ObiTearableCloth.cs ApplyTearing() method as reference. You can basically copy/paste all of it and repurpose some bits.
Let me know if I can be of further help,
I was actually converting solver index to particle index in a loop so i don't think the problem arised from that:
int solverIndex = flag.solver.simplices[contact.bodyA];
ObiSolver.ParticleInActor pa = flag.solver.particleToActor[solverIndex];
int collisionParticleIndex = pa.indexInActor;
But changing the "GetConstraintIndex(i)" to simpy "i" and calling "cloth.UpdateDeformableTriangles()" seems to fix my issue.