Cloth: Add "velocity damping" to damping options. This will help with the "cloth...
authorDaniel Genrich <daniel.genrich@gmx.net>
Mon, 23 Jan 2012 01:35:14 +0000 (01:35 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Mon, 23 Jan 2012 01:35:14 +0000 (01:35 +0000)
release/scripts/startup/bl_ui/properties_physics_cloth.py
source/blender/blenkernel/intern/cloth.c
source/blender/blenkernel/intern/implicit.c
source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_cloth_types.h
source/blender/makesdna/DNA_object_force.h
source/blender/makesrna/intern/rna_cloth.c

index 32b9450452573e4d21fa36fc52d3eb1c09f1824c..dc64aacf043da6edf920a70141284e5963612ce7 100644 (file)
@@ -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()
index 73428c889dc32cb9e8bfb5d0735e65c0ae6bdab2..33adc2af284649545d1c4b0cb055030a833e5c72 100644 (file)
@@ -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;
index 00a2de369a3f2dd5d70468ea353dd835460806cb..757d3ddf9acee663f0be8cdebd0731549f1e80d6 100644 (file)
@@ -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);
                
index 28f00f355de6258491e18f2a9577ccd5c8113908..0a92d2ca5449fc0198f4c6590924e91537450040 100644 (file)
@@ -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! */
index 5c333c3fc1fc4019acd522869edcae5601125c17..1079f1db83543dc9b3d15a2a0c663de3bf6abade 100644 (file)
@@ -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;
index 1707c0d39296948e31ef03b65ae8192522a65265..70aeaaacd44671923be457d751f9ffc7b8717177 100644 (file)
@@ -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 */
index db6cb28bd980d364a8ec7c509fb1146fada45446..839c67f6297e787dca4f9f24559351b806bed6e9 100644 (file)
@@ -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");