Obi Official Forum
Help Obi 7:Modify Constraints / Reset skinned cloth in runtime - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Cloth (https://obi.virtualmethodstudio.com/forum/forum-2.html)
+--- Thread: Help Obi 7:Modify Constraints / Reset skinned cloth in runtime (/thread-4317.html)



Obi 7:Modify Constraints / Reset skinned cloth in runtime - calvantsang - 05-08-2024

So I have updated to Obi7,I used to modify skinned cloth constraints to 0 and set back to blueprint's data in runtime to reset cloth,
Just like the example:

var cloth = GetComponent<ObiSkinnedCloth>();

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

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

// there's only one skin constraint per particle,
// so particleIndex == constraintIndex,
// and there is only need for one skin constraints batch:
var actorSkinBatch = actorConstraints.batches[0];
var solverSkinBatch = solverConstraints.batches[0];

// get the offset of our first -and only- skin batch in the solver:
int offset = cloth.solverBatchOffsets[(int)Oni.ConstraintType.Skin][0];

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

// skin radius
solverSkinBatch.skinRadiiBackstop[index * 3] = 0.05f;

// backstop sphere radius
solverSkinBatch.skinRadiiBackstop[index * 3 + 1] = 0.1f;

// backstop sphere distance
solverSkinBatch.skinRadiiBackstop[index * 3 + 2] = 0;

}

So the problem is this method can only use in CPU backend,
Can anyone tell me with out this method, Is there an easy way to reset skinned cloth with GPU backend?



RE: Obi 7:Modify Constraints / Reset skinned cloth in runtime - josemendez - 07-08-2024

Hi!

In most architectures memory isn't shared between the CPU and the GPU, you need to upload your data to the GPU. This is done by calling Upload() on the ObiNativeList (skinRadiiBackstop in the above code) after modifying its contents.

The manual explains this in the context of particle data arrays, but didn't in the context of constraint data arrays. We've updated the documentation to reflect this, by adding a short section after the above code snippet.

thanks for bringing this to my attention!

kind regards,