Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Tear, Pin, Cut, Fold and Mark
#8
(17-03-2021, 08:54 AM)josemendez Wrote: Hi Valerie,

So you want the cloth to be cut/torn upon contact with a collider (scissor-shaped, in this case), correct?

It's important to realize that cloth can only be cut along existing mesh edges. This means that you can't cut arbitrary shapes out of it, as that would require generating new geometry (changing the topology or, re-topologizing the mesh). This is considerably expensive so cloth in games generally avoids it. Only really specific use cases for industrial/medical applications actually require it.

With this in mind, cutting the cloth upon contact with a collider requires two steps:

1)- Get the contacts between the cloth and the scissor collider(s).
2)- For each contact, determine the closest mesh edge and tear it.

First step is trivial using collision callbacks: http://obi.virtualmethodstudio.com/tutor...sions.html

Second step is a bit more involved, and requires understanding how cloth simulation works. Cloth is simulated by creating a particle for each mesh vertex, then placing "distance constraint" in each edge of the mesh. Each distance constraint glues together 2 particles, you can think of them as simple springs between particles.

Constraints are grouped into "batches" for efficient parallelization. So for example, if the mesh has 600 edges you will have 600 distance constraints, grouped into a few batches (120 in one batch, 232 in another, etc). This is explained in detail here: http://obi.virtualmethodstudio.com/tutor...aints.html

With this out of the way, we now get to the actual tearing: Cloth has a Tear() method that takes a StructuralConstraint struct as parameter. StructuralConstraints are DTOs (data transfer objects) that contain a batch index and a constraint index for a given distance constraint in the cloth. You pass one of these to the Tear() method, and both the cloth mesh and its particle/constraint representation are updated to reflect the newly torn edge.

From step 1) you know the index of a particle that is touching the scissors. You now have to find which constraint(s) reference that particle (by iterating trough all constraints), create a StructuralConstraint our of the batch/constraint index, and call Tear(). You can see an example of this in the cloth's ApplyTearing() method: it iterates trough all distance constraints in the cloth, finds the ones that are under too much force, and tears them. You just need to find the ones that contain the particle index found in 1) instead.

Needless to say, some C# coding experience is necessary to implement this. Let me know how it goes! Sonrisa


Hi josemendez,

I'm working on a project with similar needs, I guess it's not necessary to open a new thread. So I'm replying you here. Hope that's not too much trouble for you.
So I understand that I need to get the particles first, then get the edges (or StructuralConstraint in term of the class name) to tear. I'm reading the source codes in ObiTearableCloth.cs and RaycastLasers.cs as an example.
And I understand you can get the "particle" by loop through all the ObiSolver.simplices. It seems it only return with an int, I'm assuming it's some sort of index? And it seems it's a mix of "points", "edges", and "triangles"?
But I didn't find any way to related that index with batchIndex and constraintIndex to find the according StructuralConstraint. Could you please show me who to approach? Thx a lot   Sonrisa 
Reply


Messages In This Thread
Tear, Pin, Cut, Fold and Mark - by Valerize - 06-01-2021, 11:35 AM
RE: Tear, Pin, Cut, Fold and Mark - by josemendez - 06-01-2021, 01:04 PM
RE: Tear, Pin, Cut, Fold and Mark - by Valerize - 07-01-2021, 09:03 PM
RE: Tear, Pin, Cut, Fold and Mark - by Valerize - 16-03-2021, 06:17 PM
RE: Tear, Pin, Cut, Fold and Mark - by josemendez - 17-03-2021, 08:54 AM
RE: Tear, Pin, Cut, Fold and Mark - by Valerize - 18-03-2021, 10:21 AM
RE: Tear, Pin, Cut, Fold and Mark - by josemendez - 18-03-2021, 10:55 AM
RE: Tear, Pin, Cut, Fold and Mark - by cycle6 - 13-01-2022, 01:58 AM
RE: Tear, Pin, Cut, Fold and Mark - by josemendez - 13-01-2022, 09:37 AM
RE: Tear, Pin, Cut, Fold and Mark - by cycle6 - 13-01-2022, 10:31 AM
RE: Tear, Pin, Cut, Fold and Mark - by josemendez - 13-01-2022, 10:50 AM
RE: Tear, Pin, Cut, Fold and Mark - by cycle6 - 13-01-2022, 11:04 AM
RE: Tear, Pin, Cut, Fold and Mark - by josemendez - 13-01-2022, 11:36 AM