Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Manual tearing via cript
#17
(09-10-2017, 02:13 PM)josemendez Wrote: This. I couldn't have explained it better.

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.
Hello.

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.

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.
Nevermind figured out after spending some time in forum.  Gran sonrisa 
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();
                   }
               }
           }
       }
   }
But I have another problem. I want the just holes to appear in the tear but no new triangles. I mean just cuts/tears but not triangular pieces.
Any ideas?
Reply


Messages In This Thread
Manual tearing via cript - by Kalidor - 09-10-2017, 10:29 AM
RE: Manual tearing via cript - by niZmo - 09-10-2017, 11:32 AM
RE: Manual tearing via cript - by josemendez - 09-10-2017, 02:13 PM
RE: Manual tearing via cript - by ctalDai - 31-07-2019, 06:48 AM
RE: Manual tearing via cript - by Kalidor - 10-10-2017, 09:56 AM
RE: Manual tearing via cript - by josemendez - 10-10-2017, 10:28 AM
RE: Manual tearing via cript - by Kalidor - 10-10-2017, 11:51 AM
RE: Manual tearing via cript - by josemendez - 10-10-2017, 03:14 PM
RE: Manual tearing via cript - by Kalidor - 10-10-2017, 03:44 PM
RE: Manual tearing via cript - by x-lab - 19-10-2017, 11:12 AM
RE: Manual tearing via cript - by josemendez - 19-10-2017, 11:43 AM
RE: Manual tearing via cript - by x-lab - 19-10-2017, 12:13 PM
RE: Manual tearing via cript - by josemendez - 19-10-2017, 01:09 PM
RE: Manual tearing via cript - by x-lab - 19-10-2017, 03:34 PM
RE: Manual tearing via cript - by josemendez - 19-10-2017, 04:13 PM
RE: Manual tearing via cript - by x-lab - 20-10-2017, 11:14 AM
RE: Manual tearing via cript - by josemendez - 20-10-2017, 11:58 AM
RE: Manual tearing via cript - by Sether - 15-01-2020, 04:09 PM
RE: Manual tearing via cript - by josemendez - 16-01-2020, 04:32 PM
RE: Manual tearing via cript - by Sether - 17-01-2020, 10:10 AM
RE: Manual tearing via cript - by zakur0 - 16-01-2020, 01:22 PM
RE: Manual tearing via cript - by josemendez - 16-01-2020, 04:37 PM