Added separate damping for bending springs.
authorLukas Tönne <lukas.toenne@gmail.com>
Fri, 26 Sep 2014 15:25:21 +0000 (17:25 +0200)
committerLukas Tönne <lukas.toenne@gmail.com>
Tue, 20 Jan 2015 08:30:03 +0000 (09:30 +0100)
The bend damping factor was hardcoded to the same value as the stiffness.
Now it has its own factor in the settings and button in hair dynamics.

release/scripts/startup/bl_ui/properties_particle.py
source/blender/blenkernel/intern/cloth.c
source/blender/blenloader/intern/versioning_270.c
source/blender/makesdna/DNA_cloth_types.h
source/blender/makesrna/intern/rna_cloth.c
source/blender/physics/intern/BPH_mass_spring.cpp

index d725738f50605654c0b9aab685079095b7e7462c..d9b66a671494c8cde3f1122465c06773922f2bbe 100644 (file)
@@ -330,6 +330,7 @@ class PARTICLE_PT_hair_dynamics(ParticleButtonsPanel, Panel):
         sub = col.column(align=True)
         sub.prop(cloth, "spring_damping", text="Spring")
         sub.prop(cloth, "air_damping", text="Air")
+        sub.prop(cloth, "bending_damping", text="Bending")
 
         col.label(text="Quality:")
         col.prop(cloth, "quality", text="Steps", slider=True)
index 297a0e462d04d5773c7c97cc1a6a3cf5e1bb47de..a77357faee5621836e7f9ea787e1af256a2a7f2e 100644 (file)
@@ -120,6 +120,7 @@ void cloth_init(ClothModifierData *clmd )
        clmd->sim_parms->structural = 15.0;
        clmd->sim_parms->shear = 15.0;
        clmd->sim_parms->bending = 0.5;
+       clmd->sim_parms->bending_damping = 0.5;
        clmd->sim_parms->Cdis = 5.0; 
        clmd->sim_parms->Cvi = 1.0;
        clmd->sim_parms->mass = 0.3f;
index 3ffde3f2583737e293ca750bba5db7141a2051b4..dcdf51f3dd6337e12018b4a2c0ba9b1d3ce7e416 100644 (file)
@@ -491,4 +491,23 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
                        }
                }
        }
+       
+       if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "bending_damping")) {
+               Object *ob;
+               ModifierData *md;
+               for (ob = main->object.first; ob; ob = ob->id.next) {
+                       for (md = ob->modifiers.first; md; md = md->next) {
+                               if (md->type == eModifierType_Cloth) {
+                                       ClothModifierData *clmd = (ClothModifierData*) md;
+                                       clmd->sim_parms->bending_damping = 0.5f;
+                               }
+                               else if (md->type == eModifierType_ParticleSystem) {
+                                       ParticleSystemModifierData *pmd = (ParticleSystemModifierData*) md;
+                                       if (pmd->psys->clmd) {
+                                               pmd->psys->clmd->sim_parms->bending_damping = 0.5f;
+                                       }
+                               }
+                       }
+               }
+       }
 }
index 39a1abcc76adae95ee56ccc0b79526e4571abe6b..85c91a510c0206b62e08a097757a5260819b0f38 100644 (file)
@@ -76,6 +76,10 @@ typedef struct ClothSimSettings {
        float   shrink_min;  /* min amount to shrink cloth by 0.0f (no shrink) - 1.0f (shrink to nothing) */
        float   shrink_max;  /* max amount to shrink cloth by 0.0f (no shrink) - 1.0f (shrink to nothing) */
        
+       /* XXX various hair stuff
+        * should really be separate, this struct is a horrible mess already
+        */
+       float   bending_damping;        /* damping of bending springs */
        int             voxel_res;          /* resolution of voxel grid for interaction */
        int             voxel_filter_size;  /* filter size for voxel grid */
 
@@ -91,7 +95,6 @@ typedef struct ClothSimSettings {
        short   shapekey_rest;  /* vertex group for scaling structural stiffness */
        short   presets; /* used for presets on GUI */
        short   reset;
-       int             pad;
 
        struct EffectorWeights *effector_weights;
 } ClothSimSettings;
index 57dc3ea293dc625a01053bbe1bae85f2f41398f4..4e1c91269a346aac365f1a53805b11737efd076a 100644 (file)
@@ -544,6 +544,13 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Bending Stiffness Maximum", "Maximum bending stiffness value");
        RNA_def_property_update(prop, 0, "rna_cloth_update");
 
+       prop = RNA_def_property(srna, "bending_damping", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "bending_damping");
+       RNA_def_property_range(prop, 0.0f, 1000.0f);
+       RNA_def_property_ui_text(prop, "Bending Spring Damping",
+                                "Damping of bending motion");
+       RNA_def_property_update(prop, 0, "rna_cloth_update");
+
        prop = RNA_def_property(srna, "use_sewing_springs", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flags", CLOTH_SIMSETTINGS_FLAG_SEW);
        RNA_def_property_ui_text(prop, "Sew Cloth", "Pulls loose edges together");
index 0138178b72204aec46804d7a046ea662a0e73b36..6a768f10d1129271d2b690545a14625537320921 100644 (file)
@@ -410,7 +410,10 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
                s->flags |= CLOTH_SPRING_FLAG_NEEDED;
                
                scaling = parms->bending + s->stiffness * fabsf(parms->max_bend - parms->bending);
-               cb = kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON));
+               kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON));
+               
+               scaling = parms->bending_damping;
+               cb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON));
                
                BPH_mass_spring_force_spring_bending(data, s->ij, s->kl, s->matrix_ij_kl, s->restlen, kb, cb, s->f, s->dfdx, s->dfdv);
 #endif
@@ -422,7 +425,10 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s,
                s->flags |= CLOTH_SPRING_FLAG_NEEDED;
                
                scaling = parms->bending + s->stiffness * fabsf(parms->max_bend - parms->bending);
-               cb = kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON));
+               kb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON));
+               
+               scaling = parms->bending_damping;
+               cb = scaling / (20.0f * (parms->avg_spring_len + FLT_EPSILON));
                
                /* XXX assuming same restlen for ij and jk segments here, this can be done correctly for hair later */
                BPH_mass_spring_force_spring_bending_angular(data, s->ij, s->kl, s->mn, s->matrix_ij_kl, s->matrix_kl_mn, s->matrix_ij_mn, s->target, kb, cb);