26-04-2022, 03:54 PM
Hi i've been trying to tear a cloth with a gameobject but i came across to a bug which makes the cloth look like this:
![[Image: view.php?img=LPic6267fb1269bf4869992675]](https://www.linkpicture.com/view.php?img=LPic6267fb1269bf4869992675)
If i change the tear resistance the bug doesn't happen all the time and i can cut the flag succesfully most of the time. However this is not the definite solution.
Can you help me with that?
Here where i call the Tear() method:
void ModifyConstraints(int collisionParticleIndex)
{
var distanceConstraints =
flag.GetConstraintsByType(Oni.ConstraintType.Distance) as ObiConstraints<ObiDistanceConstraintsBatch>;
if (distanceConstraints == null) return;
IterateAllConstraints(distanceConstraints, collisionParticleIndex);
}
void IterateAllConstraints(ObiConstraints<ObiDistanceConstraintsBatch> distanceConstraints, int particleToTear)
{
IStructuralConstraintBatch currentBatch;
foreach (var batch in distanceConstraints.batches)
{
currentBatch = (IStructuralConstraintBatch) batch;
for (int i = 0; i < batch.activeConstraintCount; i++)
{
if (batch.particleIndices[i * 2] == particleToTear)
{
StructuralConstraint sc =
new StructuralConstraint(currentBatch, batch.GetConstraintIndex(i), tearForce);
flag.Tear(sc);
flag.solver.PushSolverParameters();
}
}
}
}
If i change the tear resistance the bug doesn't happen all the time and i can cut the flag succesfully most of the time. However this is not the definite solution.
Can you help me with that?
Here where i call the Tear() method:
void ModifyConstraints(int collisionParticleIndex)
{
var distanceConstraints =
flag.GetConstraintsByType(Oni.ConstraintType.Distance) as ObiConstraints<ObiDistanceConstraintsBatch>;
if (distanceConstraints == null) return;
IterateAllConstraints(distanceConstraints, collisionParticleIndex);
}
void IterateAllConstraints(ObiConstraints<ObiDistanceConstraintsBatch> distanceConstraints, int particleToTear)
{
IStructuralConstraintBatch currentBatch;
foreach (var batch in distanceConstraints.batches)
{
currentBatch = (IStructuralConstraintBatch) batch;
for (int i = 0; i < batch.activeConstraintCount; i++)
{
if (batch.particleIndices[i * 2] == particleToTear)
{
StructuralConstraint sc =
new StructuralConstraint(currentBatch, batch.GetConstraintIndex(i), tearForce);
flag.Tear(sc);
flag.solver.PushSolverParameters();
}
}
}
}