18-03-2021, 10:21 AM
(17-03-2021, 08:54 AM)josemendez Wrote: Hi Valerie,Hi Jose,
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!
Thank you so much for taking the time to respond to my question to elaborately! As much as I wish I were able to do C#, I can't and am only progressing so slowly that this project is not taking on any shape. Even the very detailed explanation of yours leaves me with a lot of question marks.
Do you know someone who might be interested in helping me/collaborating on this project?
I am aware that I am probably not the only person who needs help with this stuff and demand must be high but I thought it might be worth asking.
Have a nice day!
Best, Valerie