Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Trying to add DistanceConstraint for my TearableCloth but getting IndexOutOfRange
#19
This code will permanently add the constraints to the actor's blueprint instance:

Code:
public void AttachParticlePairInColon(ObiTearableCloth colon, int colonMeshVertexA, int colonMeshVertexB)
    {
        ClothBlueprintParticleIndividualizer attacher = colon.GetComponent<ClothBlueprintParticleIndividualizer>();

        int particleIndexA = colon.clothBlueprint.topology.rawToWelded[colonMeshVertexA];
        int particleIndexB = colon.clothBlueprint.topology.rawToWelded[colonMeshVertexB];

        // 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(particleIndexA, particleIndexB), 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);

        colon.SetConstraintsDirty(Oni.ConstraintType.Distance);
    }

The only differences are that instead of getting a batch reference from the solver, I get it from the actor itself, and that the particle indices passed are actor indices. I see that the numbers in the inspector (topSeal and bottomSeal array) are mesh vertex indices, so I retrieve the particle indices from the topology's rawToWelded array (which maps vertex index to particle index).

At the end, call SetConstraintsDirty so that the solver knows a blueprint has been modified and it must reload distance constraints.
Reply


Messages In This Thread
RE: Trying to add DistanceConstraint for my TearableCloth but getting IndexOutOfRange - by josemendez - 10-08-2022, 09:11 AM