From 37e128504257db0c37e31f26a626b2f92b2d10db Mon Sep 17 00:00:00 2001 From: Daniel Genrich Date: Mon, 23 Jan 2012 01:35:14 +0000 Subject: 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. --- release/scripts/startup/bl_ui/properties_physics_cloth.py | 1 + source/blender/blenkernel/intern/cloth.c | 1 + source/blender/blenkernel/intern/implicit.c | 3 +++ source/blender/blenloader/intern/readfile.c | 14 ++++++++++++++ source/blender/makesdna/DNA_cloth_types.h | 3 ++- source/blender/makesdna/DNA_object_force.h | 2 ++ source/blender/makesrna/intern/rna_cloth.c | 6 ++++++ 7 files changed, 29 insertions(+), 1 deletion(-) diff --git a/release/scripts/startup/bl_ui/properties_physics_cloth.py b/release/scripts/startup/bl_ui/properties_physics_cloth.py index 32b94504525..dc64aacf043 100644 --- a/release/scripts/startup/bl_ui/properties_physics_cloth.py +++ b/release/scripts/startup/bl_ui/properties_physics_cloth.py @@ -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() diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 73428c889dc..33adc2af284 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -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; diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c index 00a2de369a3..757d3ddf9ac 100644 --- a/source/blender/blenkernel/intern/implicit.c +++ b/source/blender/blenkernel/intern/implicit.c @@ -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); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 28f00f355de..0a92d2ca544 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -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! */ diff --git a/source/blender/makesdna/DNA_cloth_types.h b/source/blender/makesdna/DNA_cloth_types.h index 5c333c3fc1f..1079f1db835 100644 --- a/source/blender/makesdna/DNA_cloth_types.h +++ b/source/blender/makesdna/DNA_cloth_types.h @@ -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; diff --git a/source/blender/makesdna/DNA_object_force.h b/source/blender/makesdna/DNA_object_force.h index 1707c0d3929..70aeaaacd44 100644 --- a/source/blender/makesdna/DNA_object_force.h +++ b/source/blender/makesdna/DNA_object_force.h @@ -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 */ diff --git a/source/blender/makesrna/intern/rna_cloth.c b/source/blender/makesrna/intern/rna_cloth.c index db6cb28bd98..839c67f6297 100644 --- a/source/blender/makesrna/intern/rna_cloth.c +++ b/source/blender/makesrna/intern/rna_cloth.c @@ -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"); -- cgit v1.2.3