Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Knot in suturing simulator
#3
(18-03-2022, 05:57 PM)josemendez Wrote: Hi!

Can’t be sure what the problem is without really delving into specifics of your user input implementation (are these manipulators force-driven rigidbodies or simply kinematic transforms?) but one thing stands a lot in your settings: you’re using 20 collision iterations (that is, collider-particle collisions have very high priority) but only 1 particle collision iteration (very low priority for particle-particle collisions).

At the very least you should use the same amount of particle collision iterations that you do for all other constraints, since these are what determine how robust rope-rope collision detection is.
Particle friction constraints are also quite important when making knots, as these determine the quality of forces tangential to contact points.


On a side note, 20 iterations and 10 substeps is absolute overkill, it yields 200 iterations per step (not even per frame). Try 2 iterations for all constraints and 10 substeps.

Let me know whether this improves the results.

Thanks for your reply!

I've first tried to set all the solver constraints to 2 (keeping 10 substeps) but did not notice significant improvements. So, I've gradually increased the most relevant ones to 5 (distance, particle collision, particle friction, collision, friction), but again, the simulation looks smoother, but the problem with the collisions and the knot remains.

Sorry, I've forgot to give some details about the interaction with the rope itself. Every manipulator has a rigidbody, set to kinematic while grabbed by the user.
For the rope grabbing script I've followed an old thread. This is my code: all the manipulators have a small obi collider in the pliers' region, used only for this interaction.

using UnityEngine;
using Obi;



public class RopePicker : BaseCommand
{
    [SerializeField] float _sensitivity = 0.1f;
    [SerializeField] ObiRope _rope;

    private bool canGrab = true;
    ObiSolver solver;
    ObiCollider obiCollider;
    ObiSolver.ObiCollisionEventArgs collisionEvent;
    ObiPinConstraintsBatch newBatch;
    ObiConstraints<ObiPinConstraintsBatch> pinConstraints;
   
    void Awake()
    {
        solver = FindObjectOfType<ObiSolver>();
        obiCollider = GetComponent<ObiCollider>();
    }
   
    // Start is called before the first frame update
    void Start()
    {
        // get a hold of the constraint type we want, in this case, pin constraints:
        pinConstraints = _rope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
    }

    private void OnEnable()
    {
        if (solver != null)
            solver.OnCollision += Solver_OnCollision;
    }

    private void OnDisable()
    {
        if (solver != null)
            solver.OnCollision -= Solver_OnCollision;
    }

    private void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        collisionEvent = e;
    }
   
    public override void Activate(float value)
    {
        if (value > _sensitivity)
        {
            Grab();
        }
        else
        {
            Release();
        }
    }
   
    public void Grab()
    {
        var world = ObiColliderWorld.GetInstance();
        //Debug.Log(pinConstraints);

        if (solver != null && collisionEvent != null)
        {
            //Debug.Log("Collision");
            foreach (Oni.Contact contact in collisionEvent.contacts)
            {
                if (contact.distance < 0.00001f)
                {
                    var contactCollider = world.colliderHandles[contact.bodyB].owner;
                    ObiSolver.ParticleInActor pa = solver.particleToActor[contact.bodyA];

                    //Debug.Log(pa + " hit " + contactCollider);
                    if (canGrab)
                    {
                        if (contactCollider == obiCollider)
                        {
                            //Debug.Log("Hand Collision");
                            var batch = new ObiPinConstraintsBatch();
                            int solverIndex = _rope.solverIndices[contact.bodyA];
                            Vector3 positionWS = solver.transform.TransformPoint(solver.positions[solverIndex]); // particle position from solver to world space
                            Vector3 positionCS = obiCollider.transform.InverseTransformPoint(positionWS); // particle position from world to collider space
                            batch.AddConstraint(_rope.solverIndices[contact.bodyA], obiCollider, positionCS, Quaternion.identity, 0, 0, float.PositiveInfinity);
                            batch.activeConstraintCount = 1;
                            newBatch = batch;
                            pinConstraints.AddBatch(newBatch);

                            canGrab = false;

                            // this will cause the solver to rebuild pin constraints at the beginning of the next frame:
                            _rope.SetConstraintsDirty(Oni.ConstraintType.Pin);
                        }
                    }
                }
            }
        }
    }
   
   
    public void Release()
    {
        if (!canGrab)
        {
            //Debug.Log("Release");
            pinConstraints.RemoveBatch(newBatch);
            _rope.SetConstraintsDirty(Oni.ConstraintType.Pin);
            canGrab = true;
        }
    }
}


Thanks again for your help!
Reply


Messages In This Thread
Knot in suturing simulator - by Portz - 18-03-2022, 04:26 PM
RE: Knot in suturing simulator - by josemendez - 18-03-2022, 05:57 PM
RE: Knot in suturing simulator - by Portz - 21-03-2022, 11:02 AM
RE: Knot in suturing simulator - by josemendez - 22-03-2022, 11:41 AM
RE: Knot in suturing simulator - by Portz - 23-03-2022, 06:05 PM
RE: Knot in suturing simulator - by josemendez - 24-03-2022, 08:47 AM
RE: Knot in suturing simulator - by Portz - 24-03-2022, 11:20 AM
RE: Knot in suturing simulator - by manurocker95 - 25-03-2022, 11:04 AM
RE: Knot in suturing simulator - by josemendez - 25-03-2022, 01:31 PM
RE: Knot in suturing simulator - by manurocker95 - 28-03-2022, 11:04 AM
RE: Knot in suturing simulator - by josemendez - 28-03-2022, 11:44 AM