Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Trying to add DistanceConstraint for my TearableCloth but getting IndexOutOfRange
#27
(18-08-2022, 09:47 PM)snowtv Wrote: Hi, I've tried to deactivate the distance constraint but it doesn't seem to work. Here is the code

Code:
ObiActor colon = obiSolver.actors[cutConstraint[0]];
            // get a hold of the distance constraint
            var distanceConstraints = colon.GetConstraintsByType(Oni.ConstraintType.Distance) as ObiConstraints<ObiDistanceConstraintsBatch>;
            distanceConstraints.batches[cutConstraint[1]].DeactivateAllConstraints();

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


(18-08-2022, 09:47 PM)snowtv Wrote: I'd also like to know how to correctly edit the distance of the distance constraint

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
Reply


Messages In This Thread
RE: Trying to add DistanceConstraint for my TearableCloth but getting IndexOutOfRange - by josemendez - 19-08-2022, 08:42 AM