Page MenuHome

Dynamic base mesh for cloth simulation
ClosedPublic

Authored by Luca Rood (LucaRood) on Apr 8 2016, 6:42 PM.

Details

Summary

This should be applied after D2122.

This adds the ability for cloth simulations to respect changes in the underlying mesh. So you can for instance, animate shape keys, armatures, or add any deformation modifiers (above the cloth modifier), and the simulation will respect those animations and deform accordingly (if the option is active, of course).

This is mainly useful for (but not limited to) cartoon animations, where your character might stretch or change shape, and you want the clothes to follow accordingly. Whereas without this patch, you would either have to hand-animate the clothes instead of simulating them, or accept that with simulation the clothes wouldn't fit your character once it changes shape/stretches.

With this patch, there is a new check-box in the cloth simulation options, underneath the pinning options, entitled "Dynamic Base Mesh", that if checked activates the described functionality.

Here is a little demo of this diff's functionality (couldn't figure out how to embed):
https://vimeo.com/lucarood/cloth-dynamic-basemesh

And here is how the UI looks after applying this:

Diff Detail

Repository
rB Blender

Event Timeline

Luca Rood (LucaRood) retitled this revision from to Dynamic base mesh for cloth simulation.
Luca Rood (LucaRood) updated this object.
Luca Rood (LucaRood) added a project: Physics.

I had forgotten to update the avg_spring_len every time the spring lengths are updated. This update fixes that.

I added a numstructs property to the Cloth struct, to permanently store the count of structural springs. This is used to calculate the average spring length, and eliminates the need to recalculate the spring count on every step.

This also fixes a miscalculation of the average spring lengths, that was present in my previous update. As sewing springs always have rest length of 0, it is not necessary to add those values to the average calculation, but they should still be added to the spring count, which wasn't done in my previous update. Now the spring count is stored in the numstructs property, and as the sewing springs are already accounted for in there, the need to include them in the average calculation is eliminated.

Luca Rood (LucaRood) planned changes to this revision.Apr 30 2016, 6:40 PM

There are some errors in the average spring length calculations, regarding sewing springs. I am, however, not submitting a new diff to fix those issues yet, because some of my code will conflict with this fix by @Alexander Gavrilov (angavrilov): https://developer.blender.org/diffusion/BS/repository/fix-cloth-shrink/

His code should probably be reviewed before this diff, and I will wait for updates regarding the status of its inclusion into master, before making further developments on my side.

Luca Rood (LucaRood) removed rB Blender as the repository for this revision.

This update makes the diff patchable against the newly committed code by @Alexander Gavrilov (angavrilov). Also, I have removed sewing springs from the average spring length calculation again, as adding them in the first place seems to have been a mistake.

I think there's no more point in the numstructs stuff anymore either.

Indeed the usefulness of the numstructs field has been slightly reduced, with the removal of sewing springs from the calculation. However I have kept it in, to avoid having to recalculate that value on every step, seeing as it doesn't change between steps.

I think that reducing the number of operations in a repetitive function is almost always beneficial (as long as the memory consumption doesn't suffer more than a negligible increase). Admittedly, the advantage of actually storing the structural spring count, is perhaps a bit small, in this context, as the cost of recalculating on every step is quite tiny. So if the general consensus is that they shouldn't be stored, I can of course move back to the previous method of recalculating them.

Luca Rood (LucaRood) set the repository for this revision to rB Blender.May 8 2016, 7:14 PM
Luca Rood (LucaRood) updated this object.

I have removed the numstructs field, in favour of the increment operation. And have also made some UI changes, to better fit with some other diffs that should now be applied before this, namely D2121 and D2122.

Campbell Barton (campbellbarton) requested changes to this revision.Jul 29 2016, 4:09 AM
Campbell Barton (campbellbarton) edited edge metadata.
Campbell Barton (campbellbarton) added inline comments.
source/blender/blenkernel/intern/cloth.c
1189–1199

Its possible number of vertices in dynamic mesh changes. there should be a check for this else you risk writing past xrest array and crashing.

(unless I miss some array size check elsewhere)

source/blender/makesrna/intern/rna_cloth.c
568

Typically use use_ prefix for boolean options, else it reads as if you can select a mesh to be the dynamic base, (maybe use_dynamic_basis ?)

This revision now requires changes to proceed.Jul 29 2016, 4:09 AM
Luca Rood (LucaRood) edited edge metadata.

Renamed "dynamic_base_mesh" to "use_dynamic_mesh". Also added comment to clarify about changing vertex count.

This revision is now accepted and ready to land.Jul 29 2016, 10:31 AM