Modifiers: Corrective Smooth modifier, new Scale parameter
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. Reviewed By: brecht, sybren Differential Revision: https://developer.blender.org/D6622
This commit is contained in:
parent
982b498c22
commit
915998111b
@ -1677,7 +1677,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
|
||||
|
||||
layout.prop(md, "factor", text="Factor")
|
||||
layout.prop(md, "iterations")
|
||||
|
||||
layout.prop(md, "scale")
|
||||
row = layout.row()
|
||||
row.prop(md, "smooth_type")
|
||||
|
||||
|
@ -4819,5 +4819,17 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
|
||||
br->automasking_boundary_edges_propagation_steps = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Corrective smooth modifier scale*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1684,10 +1684,10 @@ typedef struct CorrectiveSmoothDeltaCache {
|
||||
|
||||
/* Value of settings when creating the cache.
|
||||
* These are used to check if the cache should be recomputed. */
|
||||
float lambda;
|
||||
float lambda, scale;
|
||||
short repeat, flag;
|
||||
char smooth_type, rest_source;
|
||||
char _pad[2];
|
||||
char _pad[6];
|
||||
} CorrectiveSmoothDeltaCache;
|
||||
|
||||
typedef struct CorrectiveSmoothModifierData {
|
||||
@ -1700,10 +1700,10 @@ typedef struct CorrectiveSmoothModifierData {
|
||||
/* note: -1 is used to bind */
|
||||
unsigned int bind_coords_num;
|
||||
|
||||
float lambda;
|
||||
float lambda, scale;
|
||||
short repeat, flag;
|
||||
char smooth_type, rest_source;
|
||||
char _pad[2];
|
||||
char _pad[6];
|
||||
|
||||
/** MAX_VGROUP_NAME. */
|
||||
char defgrp_name[64];
|
||||
|
@ -3109,6 +3109,13 @@ static void rna_def_modifier_correctivesmooth(BlenderRNA *brna)
|
||||
RNA_def_property_ui_text(prop, "Repeat", "");
|
||||
RNA_def_property_update(prop, 0, "rna_CorrectiveSmoothModifier_update");
|
||||
|
||||
prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_FACTOR);
|
||||
RNA_def_property_float_sdna(prop, NULL, "scale");
|
||||
RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
|
||||
RNA_def_property_ui_range(prop, 0.0, 10.0, 5, 3);
|
||||
RNA_def_property_ui_text(prop, "Scale", "Compensate for scale applied by other modifiers");
|
||||
RNA_def_property_update(prop, 0, "rna_CorrectiveSmoothModifier_update");
|
||||
|
||||
prop = RNA_def_property(srna, "rest_source", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "rest_source");
|
||||
RNA_def_property_enum_items(prop, modifier_rest_source_items);
|
||||
|
@ -64,6 +64,7 @@ static void initData(ModifierData *md)
|
||||
csmd->bind_coords_num = 0;
|
||||
|
||||
csmd->lambda = 0.5f;
|
||||
csmd->scale = 1.0f;
|
||||
csmd->repeat = 5;
|
||||
csmd->flag = 0;
|
||||
csmd->smooth_type = MOD_CORRECTIVESMOOTH_SMOOTH_SIMPLE;
|
||||
@ -696,7 +697,7 @@ static void correctivesmooth_modifier_do(ModifierData *md,
|
||||
uint i;
|
||||
|
||||
float(*tangent_spaces)[3][3];
|
||||
|
||||
const float scale = csmd->scale;
|
||||
/* calloc, since values are accumulated */
|
||||
tangent_spaces = MEM_calloc_arrayN(numVerts, sizeof(float[3][3]), __func__);
|
||||
|
||||
@ -710,7 +711,7 @@ static void correctivesmooth_modifier_do(ModifierData *md,
|
||||
#endif
|
||||
|
||||
mul_v3_m3v3(delta, tangent_spaces[i], csmd->delta_cache.deltas[i]);
|
||||
add_v3_v3(vertexCos[i], delta);
|
||||
madd_v3_v3fl(vertexCos[i], delta, scale);
|
||||
}
|
||||
|
||||
MEM_freeN(tangent_spaces);
|
||||
|
Loading…
x
Reference in New Issue
Block a user