Page MenuHome

Corrective Smooth modifier: New Scale parameter
ClosedPublic

Authored by lucas veber (lucky3) on Jan 18 2020, 10:58 PM.

Details

Summary

When scaling the root bone of a rig to apply a global scale, the corrective smooth modifier results in wrong deformation due to incorrect scaling.
The delta calculations are not taking into account any scale value.
To fix it, a scale property is added to the modifier, allowing to set manually the scale value for the deltas by simply multiplying the vectors by this value.
There is a similar implementation in Maya's Delta Mush deformer. This property can be for example driven by the scale of the root bone of the rig, to dynamically update when the animator scale this bone.

It seems to work as expected after some tests, however one (small) issue I can't fix for now is this new Scale value is set to 0 when opening older file with objects having corrective smooth modifiers. It's properly set to 1 as default value for newly created modifier. I'd be glad to get support from any experienced developer to fix it.

Diff Detail

Event Timeline

The scale parameter initialization was missing.

lucas veber (lucky3) edited the summary of this revision. (Show Details)Jan 18 2020, 11:13 PM
lucas veber (lucky3) edited the summary of this revision. (Show Details)
lucas veber (lucky3) edited the summary of this revision. (Show Details)Jan 18 2020, 11:15 PM
Brecht Van Lommel (brecht) requested changes to this revision.Jan 27 2020, 4:30 PM

To initialize existing modifiers saved in .blend files, add code at the end of versioning_280.c like this:

if (!DNA_struct_elem_find(fd->filesdna, "CorrectiveSmoothModifierData", "float", "scale"))
  for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
    for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
      if (md->type == eModifierType_CorrectiveSmooth) {
        CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md;
        csmd->scale = 1.0f;
      }
    }
  }
}
This revision now requires changes to proceed.Jan 27 2020, 4:30 PM

I wonder if it wouldn't be possible to squeeze this scale factor out of thin air, eg. by taking the size of the object's bounding box before parenting. (Since inherited scale does not cause the issue to begin with) - Or maybe something smarter than that.

If not, then this seems fine to me. I wasn't aware the issue existed, but I tested it now and can see what this is fixing. I did not test the fix though. I would also be curious if anyone can come up with a better tooltip than "Scale the deformation by a given factor". It feels a bit ambiguous to me, but I can't think of anything much better either.

@Brecht Van Lommel (brecht) Thank you Brecht, that helps a lot.

@Demeter Dzadik (Mets) I can see the point, automating the scaling would be nice.
However it's a tricky thing. Taking the mesh bounding box as input would not always work, it's subject to expand or shrink while the character has not actually been scaled. For example, if the character is an octopus that is modeled with straight vertical tentacles in rest pose, then it is posed/animated with tentacles in a 'star' pose, the bounding box would expand but no additional scale is required since it hasn't actually been scaled.

It's worth noting a similar scale component would be necessary for the Preserve Volume option of the armature modifier, it also loses volume when scaling characters. Again there is a similar fix in Maya by exposing the scale value to the user.
I will give it a try.

You make a good point. I had a feeling my bounding box idea was not very smart. In that case, I don't mind the manual input. :)

The best approach would obviously be to improve the delta mush algorithm so that it supports scaling, but this is too high level for my skills :)
Considering it doesn't use bones transforms as input but the deformed mesh data only, it's not easy... maybe a math genius could do that though?

Sybren A. Stüvel (sybren) requested changes to this revision.EditedJan 28 2020, 3:10 PM

Given that it's indeed hard to figure out what is causing the scaling (could also be a shapekey, or mesh data from an Alembic file), exposing it to the user seems like the best approach to me too.

Scale the deformation by a given factor

For me the tooltip doesn't need to repeat that it is scaling (the label says "Scale") or that it's a factor (there is a single number to modify).

How about "Compensate for scale applied by other modifiers"?

source/blender/modifiers/intern/MOD_correctivesmooth.c
714–715

You could replace those two lines by this, and save a function call:

madd_v3_v3fl(vertexCos[i], delta, scale);
  • Changed Scale property tooltip
  • Corrected wrong struct padding
  • Avoid one function call
  • Added blend file loading instructions

LGTM apart from the trailing whitespace.

release/scripts/startup/bl_ui/properties_data_modifier.py
1643

Remove trailing whitespace.

lucas veber (lucky3) changed the edit policy from "All Users" to "lucas veber (lucky3)".Feb 5 2020, 12:09 PM
lucas veber (lucky3) marked an inline comment as done.
  • Removed a line

@lucas veber (lucky3), you accidentally changed the edit policy on this, which means I can't accept. But the patch is fine with me.

@Sybren A. Stüvel (sybren), can you commit this?

lucas veber (lucky3) changed the edit policy from "lucas veber (lucky3)" to "All Users".Feb 11 2020, 4:29 PM

@lucas veber (lucky3), you accidentally changed the edit policy on this, which means I can't accept. But the patch is fine with me.

Sorry, fixed

This revision is now accepted and ready to land.Feb 11 2020, 4:46 PM