Obi Official Forum
Help Undo Tear - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Help Undo Tear (/thread-2439.html)



Undo Tear - flaurens - 21-08-2020

Hi everyone!
I recently discovered the Tear function which is perfect for our game in order to cut the rope between two game objects.
Our other feature is to be able to undo that tear by progressively moving one of the cut ropes to its other fragment until they are linked again.
Is that something achievable with the current version of ObiRope?

Thanks in advance!


RE: Undo Tear - josemendez - 21-08-2020

(21-08-2020, 03:34 PM)flaurens Wrote: Hi everyone!
I recently discovered the Tear function which is perfect for our game in order to cut the rope between two game objects.
Our other feature is to be able to undo that tear by progressively moving one of the cut ropes to its other fragment until they are linked again.
Is that something achievable with the current version of ObiRope?

Thanks in advance!

Unfortunately not. Rope tearing is a topology change, that cannot be undone except by re-loading the rope blueprint. You can't "re-weld" together torn pieces of rope.


RE: Undo Tear - flaurens - 21-08-2020

(21-08-2020, 04:23 PM)josemendez Wrote: Unfortunately not. Rope tearing is a topology change, that cannot be undone except by re-loading the rope blueprint. You can't "re-weld" together torn pieces of rope.
Ok I understand, Is there any method to do the re-loading of the blueprint? Or I have to do it manually?
When you say blueprint I understand that you talk about the blueprint field on the ObiRope component right?

PS: I know that you said that is not possible to undo the tearing process, but I was wondering if it's possible to move one of the particles (once the rope has been cut) in order to go to the other constrain particle (where the tear has occurred)


RE: Undo Tear - sbrabi - 29-09-2022

(21-08-2020, 04:23 PM)josemendez Wrote: Unfortunately not. Rope tearing is a topology change, that cannot be undone except by re-loading the rope blueprint. You can't "re-weld" together torn pieces of rope.

Hi, why can't we just do this ?
Code:
public static void MergeParticles( this Obi.ObiRope obiRope, int indexOfElementBefore, int indexOfElementOfInterest )
{
    var solver = obiRope.solver;
            
    var previousElement   = obiRope.elements[ indexOfElementBefore ];
    var elementOfInterest = obiRope.elements[ indexOfElementOfInterest ];

    // Revert previous halving of the particle mass.
    solver.invMasses[ previousElement.particle2 ] /= 2;

    obiRope.DeactivateParticle( solver.particleToActor[ elementOfInterest.particle1 ].indexInActor );

    elementOfInterest.particle1 = previousElement.particle2;
}


Followed by a
Code:
obiRope.RebuildConstraintsFromElements();

It works for my use case by the way, it perfectly welds torn pieces of Rope back, with a satisfying snap-back I might add.