Commit: eca3877ac473cb087c24741f945a03c807ed3096 Author: Luca Rood Date: Thu Dec 15 17:00:06 2016 -0200 Branches: cloth-improvements https://developer.blender.org/rBeca3877ac473cb087c24741f945a03c807ed3096
Implement structural plasticity (has issues) The issue here is that the rest length factor isn't cached, because the cache only allows you to store a single type of data per cache (I'll try to fix this later), so if you interrupt the simulation midway through, going to the start frame, the plastic deformations will be reset. =================================================================== M release/scripts/startup/bl_ui/properties_physics_cloth.py M source/blender/blenkernel/BKE_cloth.h M source/blender/blenkernel/intern/cloth.c M source/blender/makesdna/DNA_cloth_types.h M source/blender/makesrna/intern/rna_cloth.c M source/blender/physics/intern/BPH_mass_spring.cpp M source/blender/physics/intern/implicit.h M source/blender/physics/intern/implicit_blender.c =================================================================== diff --git a/release/scripts/startup/bl_ui/properties_physics_cloth.py b/release/scripts/startup/bl_ui/properties_physics_cloth.py index f57b0e0..d49d88c 100644 --- a/release/scripts/startup/bl_ui/properties_physics_cloth.py +++ b/release/scripts/startup/bl_ui/properties_physics_cloth.py @@ -101,6 +101,9 @@ class PHYSICS_PT_cloth(PhysicButtonsPanel, Panel): col.prop(cloth, "air_damping", text="Air") col.prop(cloth, "vel_damping", text="Velocity") + layout.prop(cloth, "structural_plasticity") + layout.prop(cloth, "structural_yield_factor") + split = layout.split() col = split.column() diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h index 5514958..a7a13cd 100644 --- a/source/blender/blenkernel/BKE_cloth.h +++ b/source/blender/blenkernel/BKE_cloth.h @@ -139,6 +139,7 @@ typedef struct ClothSpring { int lb; /* length of *pb */ float restlen; /* The original length of the spring */ float restang; /* The original angle of the bending springs */ + float lenfact; /* Factor of restlen used for plasticity */ int type; /* types defined in BKE_cloth.h ("springType") */ int flags; /* defined in BKE_cloth.h, e.g. deactivated due to tearing */ float stiffness; /* stiffness factor from the vertex groups */ diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index c017fdc..d0b9d6b 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -114,6 +114,10 @@ void cloth_init(ClothModifierData *clmd ) clmd->sim_parms->time_scale = 1.0f; /* multiplies cloth speed */ clmd->sim_parms->reset = 0; clmd->sim_parms->vel_damping = 1.0f; /* 1.0 = no damping, 0.0 = fully dampened */ + clmd->sim_parms->struct_plasticity = 0.0f; + clmd->sim_parms->struct_yield_fact = 1.0f; + clmd->sim_parms->bend_plasticity = 0.0f; + clmd->sim_parms->bend_yield_fact = 0.0f; clmd->coll_parms->self_friction = 5.0; clmd->coll_parms->friction = 5.0; @@ -1393,6 +1397,7 @@ BLI_INLINE bool add_shear_bend_spring(ClothModifierData *clmd, LinkNodePair *edg shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl); spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest) * shrink_factor; + spring->lenfact = 1.0f; spring->type = CLOTH_SPRING_TYPE_SHEAR; spring->stiffness = (cloth->verts[spring->kl].shear_stiff + cloth->verts[spring->ij].shear_stiff) / 2.0f; @@ -1438,6 +1443,7 @@ BLI_INLINE bool add_shear_bend_spring(ClothModifierData *clmd, LinkNodePair *edg shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl); spring->restlen = len_v3v3(cloth->verts[spring->ij].xrest, cloth->verts[spring->kl].xrest) * shrink_factor; + spring->lenfact = 1.0f; spring->restang = spring_angle(cloth->verts, spring->ij, spring->kl, spring->pa, spring->pb, spring->la, spring->lb); @@ -1466,7 +1472,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) LinkNodePair *edgelist; EdgeSet *edgeset = NULL; LinkNode *search = NULL, *search2 = NULL; - + // error handling if ( numedges==0 ) return 0; @@ -1499,6 +1505,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) else { shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl); spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest) * shrink_factor; + spring->lenfact = 1.0f; spring->stiffness = (cloth->verts[spring->kl].struct_stiff + cloth->verts[spring->ij].struct_stiff) / 2.0f; spring->type = CLOTH_SPRING_TYPE_STRUCTURAL; @@ -1624,6 +1631,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) shrink_factor = cloth_shrink_factor(clmd, cloth->verts, spring->ij, spring->kl); spring->restlen = len_v3v3(cloth->verts[spring->ij].xrest, cloth->verts[spring->kl].xrest) * shrink_factor; + spring->lenfact = 1.0f; spring->restang = spring_angle(cloth->verts, spring->ij, spring->kl, spring->pa, spring->pb, spring->la, spring->lb); @@ -1673,6 +1681,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) spring->kl = tspring->ij; spring->mn = tspring->kl; spring->restlen = len_v3v3(cloth->verts[spring->kl].xrest, cloth->verts[spring->ij].xrest); + spring->lenfact = 1.0f; spring->type = CLOTH_SPRING_TYPE_BENDING_HAIR; spring->stiffness = (cloth->verts[spring->kl].bend_stiff + cloth->verts[spring->ij].bend_stiff) / 2.0f; bend_springs++; diff --git a/source/blender/makesdna/DNA_cloth_types.h b/source/blender/makesdna/DNA_cloth_types.h index 6583a00..2480caa 100644 --- a/source/blender/makesdna/DNA_cloth_types.h +++ b/source/blender/makesdna/DNA_cloth_types.h @@ -82,6 +82,10 @@ typedef struct ClothSimSettings { float vel_damping; /* damp the velocity to speed up getting to the resting position */ 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) */ + float struct_plasticity; /* Factor of how much the rest length will change after reaching yield point (0-1) */ + float struct_yield_fact; /* Factor of how much length has to change before plastic behavior kicks in (1-inf) */ + float bend_plasticity; /* Factor of how much the rest angle will change after reaching yield point (0-1) */ + float bend_yield_fact; /* How much angle has to change as a factor of a full circle before plastic behavior kicks in (0-1) */ /* XXX various hair stuff * should really be separate, this struct is a horrible mess already diff --git a/source/blender/makesrna/intern/rna_cloth.c b/source/blender/makesrna/intern/rna_cloth.c index 6b4c93b..c107b8e 100644 --- a/source/blender/makesrna/intern/rna_cloth.c +++ b/source/blender/makesrna/intern/rna_cloth.c @@ -635,6 +635,31 @@ static void rna_def_cloth_sim_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Shear Stiffness Maximum", "Maximum shear scaling value"); RNA_def_property_update(prop, 0, "rna_cloth_update"); + prop = RNA_def_property(srna, "structural_plasticity", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "struct_plasticity"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Structural Plasticity", "How much cloth should retain in plane deformations after reaching yield point"); + RNA_def_property_update(prop, 0, "rna_cloth_update"); + + prop = RNA_def_property(srna, "structural_yield_factor", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "struct_yield_fact"); + RNA_def_property_range(prop, 1.0f, 100.0f); + RNA_def_property_ui_range(prop, 1.0f, 2.0f, 10, 3); + RNA_def_property_ui_text(prop, "Structural Yield Factor", "How much cloth has to deform in plane before plasticity takes effect"); + RNA_def_property_update(prop, 0, "rna_cloth_update"); + + prop = RNA_def_property(srna, "bending_plasticity", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "bend_plasticity"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Bending Plasticity", "How much cloth should retain bending deformations after reaching yield point"); + RNA_def_property_update(prop, 0, "rna_cloth_update"); + + prop = RNA_def_property(srna, "bending_yield_factor", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "bend_yield_fact"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_text(prop, "Bending Yield Factor", "How much cloth has to bend before plasticity takes effect"); + RNA_def_property_update(prop, 0, "rna_cloth_update"); + prop = RNA_def_property(srna, "sewing_force_max", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "max_sewing"); RNA_def_property_range(prop, 0.0f, 10000.0f); diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp index f1a472b..eff4a1c 100644 --- a/source/blender/physics/intern/BPH_mass_spring.cpp +++ b/source/blender/physics/intern/BPH_mass_spring.cpp @@ -363,17 +363,17 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s, // TODO: verify, half verified (couldn't see error) // sewing springs usually have a large distance at first so clamp the force so we don't get tunnelling through colission objects - BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, k_tension, 0.0f, - d_tension, 0.0f, no_compress, parms->max_sewing); + BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, &s->lenfact, k_tension, 0.0f, + d_tension, 0.0f, no_compress, parms->max_sewing, 0.0f, 1.0f); } else { scaling_compression = parms->compression + s->stiffness * fabsf(parms->max_compression - parms->compression); - if (s->restlen > ALMOST_ZERO) { - k_tension = scaling_tension / s->restlen; - k_compression = scaling_compression / s->restlen; - d_tension = parms->tension_damp / s->restlen; - d_compression = parms->compression_damp / s->restlen; + if (s->restlen * s->lenfact > ALMOST_ZERO) { + k_tension = scaling_tension / (s->restlen * s->lenfact); + k_compression = scaling_compression / (s->restlen * s->lenfact); + d_tension = parms->tension_damp / (s->restlen * s->lenfact); + d_compression = parms->compression_damp / (s->restlen * s->lenfact); } else { // Multiply by some arbitrary large value, just so zero-length springs have enough force. @@ -383,8 +383,8 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s, d_compression = 0; } - BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, k_tension, k_compression, - d_tension, d_compression, no_compress, 0.0f); + BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, s->restlen, &s->lenfact, k_tension, k_compression, + d_tension, d_compression, no_co @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs