Cloth: Add "velocity damping" to damping options. This will help with the "cloth wobbling" problem which accurs quite often when having animated characters with cloth.

This commit is contained in:
Daniel Genrich 2012-01-23 01:35:14 +00:00
parent 62963525ce
commit 37e1285042
7 changed files with 29 additions and 1 deletions

@ -87,6 +87,7 @@ class PHYSICS_PT_cloth(PhysicButtonsPanel, Panel):
col.label(text="Damping:")
col.prop(cloth, "spring_damping", text="Spring")
col.prop(cloth, "air_damping", text="Air")
col.prop(cloth, "vel_damping", text="Velocity")
col.prop(cloth, "use_pin_cloth", text="Pinning")
sub = col.column()

@ -130,6 +130,7 @@ void cloth_init ( ClothModifierData *clmd )
clmd->sim_parms->presets = 2; /* cotton as start setting */
clmd->sim_parms->timescale = 1.0f; /* speed factor, describes how fast cloth moves */
clmd->sim_parms->reset = 0;
clmd->sim_parms->vel_damping = 1.0f; /* 1.0 = no damping, 0.0 = fully dampened */
clmd->coll_parms->self_friction = 5.0;
clmd->coll_parms->friction = 5.0;

@ -1852,6 +1852,9 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase
while(step < tf)
{
// damping velocity for artistic reasons
mul_lfvectorS(id->V, id->V, clmd->sim_parms->vel_damping, numverts);
// calculate forces
cloth_calc_force(clmd, frame, id->F, id->X, id->V, id->dFdV, id->dFdX, effectors, step, id->M);

@ -13038,6 +13038,20 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
/* put compatibility code here until next subversion bump */
{
{
Object *ob;
for(ob=main->object.first; ob; ob= ob->id.next) {
ModifierData *md;
for (md=ob->modifiers.first; md; md=md->next) {
if (md->type==eModifierType_Cloth) {
ClothModifierData *clmd = (ClothModifierData*) md;
if(clmd->sim_parms)
clmd->sim_parms->vel_damping = 1.0f;
}
}
}
}
}
/* WATCH IT!!!: pointers from libdata have not been converted yet here! */

@ -70,6 +70,7 @@ typedef struct ClothSimSettings
float goalfrict;
float velocity_smooth; /* smoothing of velocities for hair */
float collider_friction; /* friction with colliders */
float vel_damping; /* damp the velocity to speed up getting to the resting position */
int stepsPerFrame; /* Number of time steps per frame. */
int flags; /* flags, see CSIMSETT_FLAGS enum above. */
@ -82,7 +83,7 @@ typedef struct ClothSimSettings
short shapekey_rest; /* vertex group for scaling structural stiffness */
short presets; /* used for presets on GUI */
short reset;
short pad[3];
short pad;
struct EffectorWeights *effector_weights;
} ClothSimSettings;

@ -186,6 +186,8 @@ typedef struct PointCache {
int endframe; /* simulation end frame */
int editframe; /* frame being edited (runtime only) */
int last_exact; /* last exact frame that's cached */
int last_valid; /* used for editing cache - what is the last baked frame */
int pad;
/* for external cache files */
int totpoint; /* number of cached points */

@ -289,6 +289,12 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Air Damping", "Air has normally some thickness which slows falling things down");
RNA_def_property_update(prop, 0, "rna_cloth_update");
prop= RNA_def_property(srna, "vel_damping", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "vel_damping");
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Velocity Damping", "Damp velocity to help cloth reach the resting position faster. [1.0 = no damping, 0.0 = fully dampened]");
RNA_def_property_update(prop, 0, "rna_cloth_update");
prop= RNA_def_property(srna, "use_pin_cloth", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flags", CLOTH_SIMSETTINGS_FLAG_GOAL);
RNA_def_property_ui_text(prop, "Pin Cloth", "Enable pinning of cloth vertices to other objects/positions");