Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change Shape Matching Constraints at Runtime
#2
Hi richienko,

You're retrieving the offset of the first batch only, then reusing it for all batches:

Code:
int offset = softbody.solverBatchOffsets[(int)Oni.ConstraintType.ShapeMatching][0];
for (int i = 0; i < shapeConstraints.batches.Count; i++) {

Each batch has its own offset, you should get it like so:

Code:
for (int i = 0; i < shapeConstraints.batches.Count; i++) {
    int offset = softbody.solverBatchOffsets[(int)Oni.ConstraintType.ShapeMatching][i];

The constraint index is wrong. You're using i (the batch index) instead of j when calculating it. Should be:

Code:
index = offset + j;

Also, there's 5 material parameters per constraint. You're accessing the material parameters of the first constraint only:

Code:
solverBatch.materialParameters[0] = 0.1f; //deformationResistance
solverBatch.materialParameters[4] = 0.9f; //maxDeformation

should be:

Code:
solverBatch.materialParameters[index*5+0] = 0.1f; //deformationResistance
solverBatch.materialParameters[index*5+4] = 0.9f; //maxDeformation

So the final, correct code is:

Code:
var shapeConstraints = softbody.GetConstraintsByType(Oni.ConstraintType.ShapeMatching) as ObiConstraints<ObiShapeMatchingConstraintsBatch>;
var solverConstraints = softbody.solver.GetConstraintsByType(Oni.ConstraintType.ShapeMatching) as ObiConstraints<ObiShapeMatchingConstraintsBatch>;

for (int i = 0; i < shapeConstraints.batches.Count; i++) {

    int offset = softbody.solverBatchOffsets[(int)Oni.ConstraintType.ShapeMatching][i];

    var softbodyBatch = shapeConstraints.batches[i];
    var solverBatch = solverConstraints.batches[i];

    for (int j = 0; j < softbodyBatch.activeConstraintCount; ++j) {
        int index = j + offset;
        solverBatch.materialParameters[index*5+0] = 0.1f; //deformationResistance
        solverBatch.materialParameters[index*5+4] = 0.9f; //maxDeformation
    }
}

Also note this only makes sense if you're going to apply different parameters to each individual constraint. If you want to set the same parameter for all constraints, just use the per-actor parameters as explained here:
http://obi.virtualmethodstudio.com/tutor...aints.html
Reply


Messages In This Thread
RE: Change Shape Matching Constraints at Runtime - by josemendez - 26-05-2021, 07:43 AM