27-04-2022, 07:42 AM
(This post was last modified: 27-04-2022, 07:47 AM by josemendez.)
Hi!
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,
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,