Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Trying to add DistanceConstraint for my TearableCloth but getting IndexOutOfRange
#28
(19-08-2022, 08:42 AM)josemendez Wrote: You've deactivated the constraints in the actor, but you'll need the solver to reload them for this to have any affect. See "Adding/removing constraints" in the manual:
http://obi.virtualmethodstudio.com/manua...aints.html



Like with anything else, there's two ways to do this: either change the rest distance in the actor and then force the solver to reload all actor constraints by marking them dirty, or access the solver batches directly and change the rest distance there.

There's code in the manual that modifies constraint data at runtime, accessing the solver batches directly:
http://obi.virtualmethodstudio.com/manua...aints.html

The example modifies for skin constraint radius, doing it for distance constraints is basically the same. The only difference is in accessing constraint data arrays (the for loop at the end):


Code:
// get constraints stored in the actor:
var actorConstraints = cloth.GetConstraintsByType(Oni.ConstraintType.Distance)
                        as ObiConstraints<ObiDistanceConstraintsBatch>;

// get runtime constraints in the solver:
var solverConstraints = cloth.solver.GetConstraintsByType(Oni.ConstraintType.Distance)
                        as ObiConstraints<ObiDistanceConstraintsBatch>;

// get first batch for both:
var actorBatch = actorConstraints.batches[0];
var solverBatch = solverConstraints.batches[0];

// get the offset of the batch in the solver:
int offset = cloth.solverBatchOffsets[(int)Oni.ConstraintType.Distance][0];

// iterate over all active skin constraints in the batch,
// setting their properties:
for (int i = 0; i < actorBatch.activeConstraintCount; ++i)
{

    // set constraint rest length:
    solverDistanceBatch.restLengths[offset + i] = 0.05f;
}

See the API docs for info on how constraint data is stored for each specific constraint type:
http://obi.virtualmethodstudio.com/api.html

Thanks for the response. I'm not really looking to remove the constraints, only "deactivate" them, which I assume is possible since there is ObiDistanceConstraintsBatch.DeactivateAllConstraints()

If I don't need to remove them then I shouldn't need to update my saved batch index in actor for these constraints, right?
Reply


Messages In This Thread
RE: Trying to add DistanceConstraint for my TearableCloth but getting IndexOutOfRange - by snowtv - 19-08-2022, 07:09 PM