(09-10-2017, 02:13 PM)josemendez Wrote: This. I couldn't have explained it better.Hello.
We should probably be checking that the range is correct inside Tear(), since tearing a constraint splits one of the particles at its ends: which one? the one with more mass, or a random one if both have the same. Torn particles (the original one and the new one added at the cut) then have their mass halved.
In the edges of the rope of course, this can cause a cut to attempt to create an additional particle at the very beginning/end of the rope, which is illegal. We check for this whenever we use Tear() inside Obi, but it being a public function we should really perform the check inside of it.
Thanks for pointing it out niZmo.
I am trying to do something similar. I could get the cloth to be torn on collision via script but not at the point of collision. How do I get the the constraint index from particle index or contact point of the collision?
Code:
private void HandleClothCollision(object sender, ObiSolver.ObiCollisionEventArgs e)
{
if (pressed)
{
foreach (Oni.Contact contact in e.contacts)
{
if (contact.distance < 0.01)
{
Collider collider = ObiColliderBase.idToCollider[contact.other] as Collider;
ObiSolver.ParticleInActor pa = solver.particleToActor[contact.particle];
if (collider.tag == "tool" && pa.actor.tag == "fat")
{
Debug.Log("called");
ObiTearableCloth cloth = pa.actor as ObiTearableCloth;
cloth.DistanceConstraints.RemoveFromSolver(null);
cloth.BendingConstraints.RemoveFromSolver(null);
cloth.Tear(contact.particle);
cloth.DistanceConstraints.AddToSolver(cloth);
cloth.BendingConstraints.AddToSolver(cloth);
cloth.BendingConstraints.SetActiveConstraints();
cloth.UpdateDeformableTriangles();
cloth.Solver.UpdateActiveParticles();
}
}
}
}
}
The code I have included tears the cloth but not at the point of collision. Please Help.
(31-07-2019, 06:48 AM)ctalDai Wrote: Hello.Nevermind figured out after spending some time in forum.
I am trying to do something similar. I could get the cloth to be torn on collision via script but not at the point of collision. How do I get the the constraint index from particle index or contact point of the collision?
Code:private void HandleClothCollision(object sender, ObiSolver.ObiCollisionEventArgs e)
{
if (pressed)
{
foreach (Oni.Contact contact in e.contacts)
{
if (contact.distance < 0.01)
{
Collider collider = ObiColliderBase.idToCollider[contact.other] as Collider;
ObiSolver.ParticleInActor pa = solver.particleToActor[contact.particle];
if (collider.tag == "tool" && pa.actor.tag == "fat")
{
Debug.Log("called");
ObiTearableCloth cloth = pa.actor as ObiTearableCloth;
cloth.DistanceConstraints.RemoveFromSolver(null);
cloth.BendingConstraints.RemoveFromSolver(null);
cloth.Tear(contact.particle);
cloth.DistanceConstraints.AddToSolver(cloth);
cloth.BendingConstraints.AddToSolver(cloth);
cloth.BendingConstraints.SetActiveConstraints();
cloth.UpdateDeformableTriangles();
cloth.Solver.UpdateActiveParticles();
}
}
}
}
}
The code I have included tears the cloth but not at the point of collision. Please Help.
Heres the working code.
Code:
private void HandleClothCollision(object sender, ObiSolver.ObiCollisionEventArgs e)
{
if (pressed)
{
foreach (Oni.Contact contact in e.contacts)
{
if (contact.distance < 0.01)
{
Collider collider = ObiColliderBase.idToCollider[contact.other] as Collider;
ObiSolver.ParticleInActor pa = solver.particleToActor[contact.particle];
if (collider.tag == "tool" && pa.actor.tag == "fat")
{
Debug.Log("called");
ObiTearableCloth cloth = pa.actor as ObiTearableCloth;
List<int> affectedConstraints = new List<int>();
foreach (ObiConstraintBatch batch in cloth.DistanceConstraints.GetBatches())
{
affectedConstraints = batch.GetConstraintsInvolvingParticle(contact.particle);
}
cloth.DistanceConstraints.RemoveFromSolver(null);
cloth.BendingConstraints.RemoveFromSolver(null);
for (int i = 0; i < affectedConstraints.Count; i++)
{
cloth.Tear(affectedConstraints[i]);
}
cloth.DistanceConstraints.AddToSolver(cloth);
cloth.BendingConstraints.AddToSolver(cloth);
cloth.BendingConstraints.SetActiveConstraints();
cloth.UpdateDeformableTriangles();
cloth.Solver.UpdateActiveParticles();
}
}
}
}
}
Any ideas?