Page MenuHome

Fix T88188: Allow keyframing vertex mass in cloth sim
ClosedPublic

Authored by Robert Sheldon (rsheldiii) on Jun 18 2021, 12:58 AM.

Details

Summary

Update cloth weights every simulation step.

Cloth sim weights are not updated during cloth simulation,
originally causing the simulation to ignore vertex weight keyframes.
Philipp Oeser removed the animatable property but also noted two
areas where the weight could be updated to keep track of vertex
weight changes. I would love to be able to keyframe vertex weight,
so I added a function to SIM_mass_spring to allow updating the
implicit cloth weights and used it in cloth step function. I opted to
unconditionally update all weights because I couldn't find a good
source of truth for whether the weight changed. This solution has so
far worked perfectly for me and seems very stable.

I am quite out of my depth here, this is my first revision, so I apologize
for any issues. Please let me know how I can improve this revision so
it may be accepted!

Diff Detail

Repository
rB Blender

Event Timeline

Robert Sheldon (rsheldiii) requested review of this revision.Jun 18 2021, 12:58 AM
Robert Sheldon (rsheldiii) created this revision.

Like I said in the commit message from rB4707c8617951: Fix T88188: Keyframing Vertex Mass in Cloth Simulation doesn't have any:

Seems possible to update ClothVertex->mass every step in
do_step_cloth, however it seems more involved to update the masses in
Implicit_Data there as well. The masses from Implicit_Data are
accessed in many places, so it would be mandatory to have these masses
kept up-to-date (and even then it is unclear if the solver was designed
to work with these animated or if there are assumptions about this being
stable across the sim).

my simple testing actually survived animating these masses, but I have not checked the solver in depth [and dont have the time for it unfortunately].
Codewise seems fine, and if in doubt, I would like to see this functionality being in master (but not without a set of eyes from the Nodes & Physics module)

Hopefully I can get around to test this out soon.

Sadly there is just so much other stuff going on right now... :c

No worries, I understand this isn't a super high priority. Thank you both for helping with this! let me know if there's anything else I can do to make this go smoothly.

I've tested this out and it seems to work nicely! :)

The only thing I can think of is that perhaps we should add a check to see if verts->mass == clmd->sim_parms->mass at the start of the update for loop and only update the vertex masses if they have actually changed.
I don't know how much performance this will save, but it should allow us to skip matrix multiplications if we don't need to do them.

added an if clause in the loop to conditionally update vertex masses only if they change.

@Sebastian Parborg (zeddb) does this look good?

You only actually need to do the comparison once, right?
As the vertex mass is global.
So you can do the check before the loop and save the result in a bool variable.
IE you only need to check and assign the new value once.

Then you only need to make sure that all masses in the simulation matrix is updated.

Saved the comparison in a bool. also remove comment as it is redundant now with the boolean's name.

how does this look @Sebastian Parborg (zeddb) ?

Other than my nitpick that I can fix when I commit this, LGTM.

source/blender/blenkernel/intern/cloth.c
271

I think you should have this all on one line.

So you have the verts->mass != clmd->sim_parms->mass assignment here.

This revision is now accepted and ready to land.Jul 15 2021, 12:31 PM