28-07-2022, 07:19 PM
(28-07-2022, 07:36 AM)josemendez Wrote: There can be several reasons for this. Could you share the entire code you're using?
For instance, a possible cause would be adding the distance constraint to the blueprint, once the blueprint has been instantiated. This will have no effect on existing instances of it.
Code:
public void AttachParticlePairInColon(ObiTearableCloth colon, int colonMeshVertexA, int colonMeshVertexB)
{
ClothBlueprintParticleIndividualizer attacher = colon.GetComponent<ClothBlueprintParticleIndividualizer>();
Mesh colonMesh = colon.GetComponent<MeshFilter>().sharedMesh;
int particleSolverIndexA = attacher.GetClosestParticleSolverIndex(colon.transform.TransformPoint(colonMesh.vertices[colonMeshVertexA]));
int particleSolverIndexB = attacher.GetClosestParticleSolverIndex(colon.transform.TransformPoint(colonMesh.vertices[colonMeshVertexB]));
// get a hold of the distance constraint
var distanceConstraints = obiSolver.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);
}
This is it. I think I'm adding them to the solver? Does it have anything to do with the fact that I'm using TearableCloth? I'm also thinking about creating invisible objects and use PinConstraints if DistanceConstraint is not an option...