18-06-2025, 08:10 AM
(This post was last modified: 18-06-2025, 08:18 AM by josemendez.)
Hi Chenji!
Thanks for sharing your code! may be useful for other users around.
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,
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,