Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tear Rod
#1
Hi,

I send this post because there is no out-of-box support for tear rod and I need this in my game dev. By looking at Obi source code I finally implemented a close one. Though it's more like a "fold rod" and mesh is not split, it's ok for my game's requirement. I hope this can help you if you have similar requirement. It's based on Obi Rope 7.0.5

Also I'd like to ask why this feature is not supported in case I missed something important and my code may fail to work in future Obi version. 

My code is actually very simple, just deactivate a constraint:

 public void TearRod()
    {
        ObiRod rod = fishingRod;
        var twistBatch = rod.GetConstraintsByType(Oni.ConstraintType.BendTwistas ObiBendTwistConstraintsData;
        foreach (ObiBendTwistConstraintsBatch batch in twistBatch.batches)
        {
            if (batch != null)
            {
                batch.DeactivateConstraint(0);
            }
        }
        rod.SetConstraintsDirty(Oni.ConstraintType.BendTwist);
     
    }


Effect gif: p1.gif
Reply
#2
Hi Chenji!

Thanks for sharing your code! may be useful for other users around.

(17-06-2025, 05:47 PM)chenji Wrote: Also I'd like to ask why this feature is not supported in case I missed something important and my code may fail to work in future Obi version.

You're deactivating one bend/twist constraint - which is fine, and will result in the rod freely bending at that point- but it's not tearing. To completely tear the rod involves these steps:

- Activate a new particle.
- Rewire the existing bend/twist and stretch/shear constraint at the tear site to the new particle.
- Update chain constraints (this is the step that's challenging for rods)
- Update rod elements, so that rendering also reflects the fact that the rod is broken.

Of these 4 steps, 1,2 and 4 are doable, but 3 is more challenging to do in a reasonably performant way.

The reason is a chain constraint affects *all* particles in the rod simultaneously. Tearing the rod means creating a *new* constraint (eg. reuse old constraint for left side of the cut, create new one for right side), which requires allocating memory at runtime which is something we'd like to avoid. The naive solution would be to allocate N constraints of size N for a rod with N particles in it, which is the maximum memory you'd consume in the worst case of a rod that's broken at every particle.

I think we can eventually come up with a solution and add tearing support for chain constraints, probably by modifying the constraint itself to support "break points" along it which only has a modest memory footprint, and doesn't require allocating at runtime. Will try to get it working during the 7.X development cycle.

kind regards,
Reply
#3
(Yesterday, 08:10 AM)josemendez Wrote: I think we can eventually come up with a solution and add tearing support for chain constraints, probably by modifying the constraint itself to support "break points" along it which only has a modest memory footprint, and doesn't require allocating at runtime. Will try to get it working during the 7.X development cycle.
Great! Looking forward to this feature!
Reply