09-05-2022, 02:15 PM
Hi,
I recently took over a project (from people no longer at my company) and am trying to upgrade Obi (Cloth and Rope) from version 4.0 to 6.4. I get a handful of errors because of API changes and managed to adjust most of the code, but one method in particular is hard to update. One part of the problem is that our code is not well documented (or well written, sadly), but also I'm having trouble finding info on how to replace methods that no longer exist, especially ObiConstraint(s)Batch#GetConstraintsInvolvingParticle(int particleIndex). In the old version, our method borrowed heavily from ObiTearableCloth#ApplyTearing(), but it changed drastically after the upgrade. Our method was added to ObiTearableCloth and is called from within a solver collision callback with the index of a ParticleInActor for each contact in the ObiCollisionEventArgs.
Here's the method, I added comments behind the lines I believe to be unnecessary:
DistanceConstraints.AddToSolver(this); // unnecessary? ApplyTearing() no longer calls it
Here's where I'm at right now, stuck on how to replace GetConstraintsInvolvingParticle() and construct the correct StructuralConstraints for the Tear() call:
Any hints on how to rewrite this or confirmation on the three calls after the loop I marked no longer being necessary?
Thanks!
I recently took over a project (from people no longer at my company) and am trying to upgrade Obi (Cloth and Rope) from version 4.0 to 6.4. I get a handful of errors because of API changes and managed to adjust most of the code, but one method in particular is hard to update. One part of the problem is that our code is not well documented (or well written, sadly), but also I'm having trouble finding info on how to replace methods that no longer exist, especially ObiConstraint(s)Batch#GetConstraintsInvolvingParticle(int particleIndex). In the old version, our method borrowed heavily from ObiTearableCloth#ApplyTearing(), but it changed drastically after the upgrade. Our method was added to ObiTearableCloth and is called from within a solver collision callback with the index of a ParticleInActor for each contact in the ObiCollisionEventArgs.
Here's the method, I added comments behind the lines I believe to be unnecessary:
DistanceConstraints.AddToSolver(this); // unnecessary? ApplyTearing() no longer calls it
Code:
public void CustomCut(int index)
{
ObiDistanceConstraintBatch distanceBatch = DistanceConstraints.GetFirstBatch();
float[] forces = new float[distanceBatch.ConstraintCount]; // unnecessary and...
Oni.GetBatchConstraintForces(distanceBatch.OniBatch, forces, distanceBatch.ConstraintCount, 0); // unnecessary, because "forces" isn't used
List<TornEdge> tornEdges = new List<TornEdge>();
foreach (ObiConstraintBatch batch in DistanceConstraints.GetBatches())
{
List<int> affectedConstraints = batch.GetConstraintsInvolvingParticle(index);
for(int i = 0; i<affectedConstraints.Count; i++)
{
Tear(affectedConstraints[i]);
}
//Tear(affectedConstraints[0]);
DistanceConstraints.AddToSolver(this); // unnecessary? ApplyTearing() no longer does this in new version
// update active bending constraints:
BendingConstraints.SetActiveConstraints(); // unnecessary? ApplyTearing() no longer does this in new version
// update solver deformable triangle indices:
UpdateDeformableTriangles();
// upload active particle list to solver:
solver.UpdateActiveParticles(); // unnecessary? ApplyTearing() no longer does this in new version
}
}
Here's where I'm at right now, stuck on how to replace GetConstraintsInvolvingParticle() and construct the correct StructuralConstraints for the Tear() call:
Code:
public void CustomCut(int index)
{
var distanceConstraints = GetConstraintsByType(Oni.ConstraintType.Distance) as ObiDistanceConstraintsData;
foreach (ObiConstraintsBatch batch in distanceConstraints.batches)
{
List<int> affectedConstraints = batch.GetConstraintsInvolvingParticle(index);
for(int i = 0; i < affectedConstraints.Count; i++)
{
Tear(affectedConstraints[i]);
}
// update solver deformable triangle indices:
UpdateDeformableTriangles();
}
}
Thanks!