Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Problems deleting obi colliders with pin constraints
#3
Hi, thanks for the quick reply. I guess I'm still confused as to how I should best resolve the issue. Referring to what you said:

josemendez Wrote:This is the correct solution and it is what Obi does internally. Same applies to all constraints, not just pin constraints: whenever the index of a particle or collider in the internal solver arrays change, all constraints affecting them must be re-created or updated. Remember we are dealing with indices, not pointers/references, so they are not automagically updated.

This is why the ObiColliderHandle class exists: it stores an object reference to the actual Collider, and its index in the solver arrays. This index is updated automatically by the collision system.

Here is an example of how I'm creating a pin constraint:


Code:
pinConstraints = rope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiPinConstraintsData;
pinBatch = new();
targetObiCollider = gameObject.AddComponent<ObiCollider>();
pinBatch.AddConstraint(
    rope.elements[0].particle1,
    targetObiCollider,
    Vector3.zero,
    Quaternion.identity, 0, 10000, 1);
pinBatch.activeConstraintCount = 1;
pinConstraints.AddBatch(pinBatch);
rope.SetConstraintsDirty(Oni.ConstraintType.Pin);

As you can see, I am not directly referencing the collider handle - just passing `targetObiCollider` to the API.

josemendez Wrote:When you create a pin constraint using batch.AddConstraint(), the handle to this collider is stored in the batch. Any subsequent calls to

rope.SetConstraintsDirty(Oni.ConstraintType.Pin); will force the constraints to use whatever collider index is currently stored in the handle - as long as the constraint has been added to the actor, and not the solver. 

As far as I can tell, I'm not adding the constraint to the solver, since I performed the `GetConstraintsByType` call on the rope (actor) and not its solver. Or is my above code wrong?

Regardless, I noticed that `ObiPinConstraintsBatch.AddConstraint` is doing two things: 1) it tracks the collider handle in pinBodies 2) it caches the current handle index in `colliderIndices`. I had originally assumed that `rope.SetConstraintsDirty(Oni.ConstraintType.Pin);` would cause the collision system to update the index value in `colliderIndices`, because it is already keeping track of the handle, but this doesn't actually seem to be happening.

If the only possible solution is to duplicate the logic in `ObiParticleAttachment.UpdateAttachment`, that's fine. It seems pretty heavy-handed to require every single pin I create to then have to continuously poll for changes instead of having the collision system resolve this internally, which is what I was hoping for. I'll probably need to write an entire helper class for this though.
Reply


Messages In This Thread
RE: Problems deleting obi colliders with pin constraints - by btduser - 12-05-2024, 09:06 PM