Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Trying to add DistanceConstraint for my TearableCloth but getting IndexOutOfRange
#1
Pregunta 
I'm following the example on the official document, here is the jist of my current method:

Code:
// get a hold of the distance constraint
        var distanceConstraints = colon.GetConstraintsByType(Oni.ConstraintType.Distance) as ObiConstraints<ObiDistanceConstraintsBatch>;

        // create a new distance constraints batch
        var batch = new ObiDistanceConstraintsBatch();

        // Add a constraint for the pair
        batch.AddConstraint(new Vector2Int(particleSolverIndexA, particleSolverIndexB), 0);

        // set the amount of active constraints in the batch to 2 (the ones we just added).
        batch.ActivateConstraint(0);

        // append the batch to the pin constraints:
        distanceConstraints.AddBatch(batch);

        // this will cause the solver to rebuild distance constraints at the beginning of the next frame:
        colon.SetConstraintsDirty(Oni.ConstraintType.Distance);

Basically my method will first find the solver indexes of two particles closest to the given world positions, then using the above code to add DistanceConstraint between them.

I removed the part of the example where it clears the entire constraint batches first, because I don't wanna remove all the existing DistanceConstraint.

Is there something wrong in the above code? Or I'm not getting the correct solver index for my particles?
Reply


Messages In This Thread
Trying to add DistanceConstraint for my TearableCloth but getting IndexOutOfRange - by snowtv - 26-07-2022, 08:07 PM