Obi Official Forum
Get current batch index and a constraint index in oby tear cloth - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Cloth (https://obi.virtualmethodstudio.com/forum/forum-2.html)
+--- Thread: Get current batch index and a constraint index in oby tear cloth (/thread-2927.html)



Get current batch index and a constraint index in oby tear cloth - DenisBlack - 12-05-2021

Hi, mb anybody can help me.
I try to make tearing cloth by some collision (like scissors).

I get Particle id from collision detect : 900 id; But dont understand how to correctly get current batch and constaint index.
In ObiTearableCloth.cs i saw ApplyTearing method with calculate by force and get some code from there.

Code:
  List<StructuralConstraint> tornEdges = new List<StructuralConstraint>();
            var distanceConstraints = Cloth.GetConstraintsByType(Oni.ConstraintType.Distance) as ObiConstraints<ObiDistanceConstraintsBatch>;
            var solverConstraints = Solver.GetConstraintsByType(Oni.ConstraintType.Distance) as ObiConstraints<ObiDistanceConstraintsBatch>;
       
            if (distanceConstraints != null && solverConstraints != null)
            {
                Debug.LogError("distanceConstraints.batches.Count "+ distanceConstraints.batches.Count());
               
                for (int j = 0; j < distanceConstraints.batches.Count; ++j)
                {
                    var batch = distanceConstraints.batches[j] as ObiDistanceConstraintsBatch;
                    var solverBatch = solverConstraints.batches[j] as ObiDistanceConstraintsBatch;
                   
                    Debug.LogError("batch.activeConstraintCount "+ batch.activeConstraintCount.ToString());
                   
                    for (int i = 0; i < batch.activeConstraintCount; i++)
                    {
                     
                    }
                   
                   
                }
            }

How to i can iterating check current active constreint wich collect my particle id?


UPD:
Ok, next time first need to write on note my task - that help to collect thoughts ))

Code:
for (int i = 0; i < batch.activeConstraintCount; i++)
                {
                    if(batch.GetParticleIndices(i).first.Equals(particleIndex) || batch.GetParticleIndices(i).second.Equals(particleIndex))
                        tornEdges.Add(new StructuralConstraint(batch, i, 0));
                }



RE: Get current batch index and a constraint index in oby tear cloth - josemendez - 13-05-2021

Glad you beat me to the answer Guiño. Good job in figuring it out!

Let me know if I can help anytime.