26-05-2021, 07:43 AM
(This post was last modified: 26-05-2021, 07:50 AM by josemendez.)
Hi richienko,
You're retrieving the offset of the first batch only, then reusing it for all batches:
Each batch has its own offset, you should get it like so:
The constraint index is wrong. You're using i (the batch index) instead of j when calculating it. Should be:
Also, there's 5 material parameters per constraint. You're accessing the material parameters of the first constraint only:
should be:
So the final, correct code is:
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
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