Hi again!
the behavior would look at bit like in this example.
https://autode.sk/36uBQUw
In this example, it does not 'correct' the simulation.
This is a first try to validate 'how' it could work.
The video shows how to run the cloth sim per frame and how to set it up so it can be modified while simulating.
That is a first step.
The next step, indeed, relates to your questions.
This is where I can help the least, but can help get on 'a path' to some results.
You'll need to figure out what it the best approach for your objects and simulations.
What 'stretches too much' in the simulation, how you can catch it and how to fix it.
What I don't know is what you would consider to be a stretch problem with your meshes and simulation.
The approach I would take from there, is use a concrete example that you have, a simulation that you'd like your scripted tool to catch and correct, and most important, how would you correct it! As you'd need to be able to do it manually so it can be scripted.
Using the concrete example, I would try to seek for where does the stretch occur, what is the best method for you to catch it, it is vertex distance from each other or would it be the faces' surface area growing, or is it another way ?
Depending on the base mesh type, Editable Mesh (meshop) or Editable Poly (Polyop)
Here is a few key commands that can be used, as example I am using Polyop, for Editable Poly mesh.
To get number of vertices of an Editable Poly
polyop.getNumVerts <object>
To get number of faces of an Editable Poly
polyop.getNumFaces <object>
Using either (or both), we can get the amount of vertices or faces. With that information we can check them
Iterating through vertices to check distances could be a long process, as we would need to check every vertex against all of them. That is doable, requires a good logic.
Could also iterate through all faces and check for it area.
For instance, for a given Editable Poly, iterate through all faces and print out its surface area
for i = 1 to (polyop.getNumFaces $) do (
print (polyop.getFaceArea $ i) -- get the Face Surface
)
If needed be, for any given faces, we can also get the vertices
for i = 1 to (polyop.getNumFaces $) do (
print (polyop.getFaceArea $ i) -- get the Face Surface
print (polyop.getFaceVerts $ i) -- get the same Face Vertices
)
To get all of the possible polyop functions, in the listener execute
show polyop -- shows all polyop functions. Use on Editable Poly
show meshop -- shows all meshop functions. Use on Editable Mesh
Other notes that can be of use:
. The script can use Selection Sets for Vertex or Face Selection
. The script can use modifier stack Vertex or Face Selection
. The Cloth modifier can be set to have many Vertex Groups with different settings, all that can be altered while simulating.
The script could also have options to go back in (simulation) time and correct values so stretching 'does not' occur.
For instance, if on a given frame, lets say 52, the function finds a face that stretches above the point you defined, then the script could go back a given amount of frame (either predefined, like 5 frames back) or go back to a frame where the area was still in an acceptable size. Then truncate the simulation, update some cloth values, and start to simulate again.
At that stage, this is the 'secret sauce' you'd have to figure out...
A long one, but hope it can help! 🙂
Let me know if this goes in the direction you'd like!
Regards,