[Bf-blender-cvs] [bb32d92] cloth-improvements: Implement angular plasticity (has issues)

Luca Rood noreply at git.blender.org
Sat Dec 17 03:09:36 CET 2016


Commit: bb32d9240fe17a7c239417701e69f00fa165906b
Author: Luca Rood
Date:   Thu Dec 15 21:03:12 2016 -0200
Branches: cloth-improvements
https://developer.blender.org/rBbb32d9240fe17a7c239417701e69f00fa165906b

Implement angular plasticity (has issues)

Same issues as the previous structural plasticity commit.

===================================================================

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/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 d49d88c..fc14855 100644
--- a/release/scripts/startup/bl_ui/properties_physics_cloth.py
+++ b/release/scripts/startup/bl_ui/properties_physics_cloth.py
@@ -103,6 +103,8 @@ class PHYSICS_PT_cloth(PhysicButtonsPanel, Panel):
 
         layout.prop(cloth, "structural_plasticity")
         layout.prop(cloth, "structural_yield_factor")
+        layout.prop(cloth, "bending_plasticity")
+        layout.prop(cloth, "bending_yield_factor")
 
         split = layout.split()
 
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index a7a13cd..53c2f27 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -140,6 +140,7 @@ typedef struct ClothSpring {
 	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 */
+	float angoffset;	/* Offset of restang 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 d0b9d6b..1d4aef2 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -1634,6 +1634,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm )
 						spring->lenfact = 1.0f;
 
 						spring->restang = spring_angle(cloth->verts, spring->ij, spring->kl, spring->pa, spring->pb, spring->la, spring->lb);
+						spring->angoffset = 0.0f;
 
 						spring->stiffness = (cloth->verts[spring->ij].bend_stiff + cloth->verts[spring->kl].bend_stiff) / 2.0f;
 
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index eff4a1c..a8b1a61 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -434,10 +434,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);
-		k = scaling * s->restlen * 0.1f; /* multiplying by 0.1, just to scale the forces to more reasonable values */
+		k = scaling * s->restlen * s->lenfact * 0.1f; /* multiplying by 0.1, just to scale the forces to more reasonable values */
 		
-		BPH_mass_spring_force_spring_angular(data, s->ij, s->kl, s->pa, s->pb, s->la, s->lb,
-                                             s->restang, k, parms->bending_damping);
+		BPH_mass_spring_force_spring_angular(data, s->ij, s->kl, s->pa, s->pb, s->la, s->lb, s->restang, &s->angoffset,
+		                                     k, parms->bending_damping, parms->bend_plasticity, parms->bend_yield_fact * M_PI * 2);
 #endif
 	}
 	else if (s->type & CLOTH_SPRING_TYPE_BENDING_HAIR) {
diff --git a/source/blender/physics/intern/implicit.h b/source/blender/physics/intern/implicit.h
index 0146961..02d07c0 100644
--- a/source/blender/physics/intern/implicit.h
+++ b/source/blender/physics/intern/implicit.h
@@ -119,7 +119,8 @@ bool BPH_mass_spring_force_spring_linear(struct Implicit_Data *data, int i, int
 					 bool no_compress, float clamp_force, float plasticity, float yield_fact);
 /* Angular spring force between two polygons */
 bool BPH_mass_spring_force_spring_angular(struct Implicit_Data *data, int i, int j, int *i_a, int *i_b, int len_a, int len_b,
-                                          float restang, float stiffness, float damping);
+                                          float restangorig, float *angoffset, float stiffness, float damping,
+					  float plasticity, float yield_ang);
 /* Bending force, forming a triangle at the base of two structural springs */
 bool BPH_mass_spring_force_spring_bending(struct Implicit_Data *data, int i, int j, float restlen,
                                           float kb, float cb);
diff --git a/source/blender/physics/intern/implicit_blender.c b/source/blender/physics/intern/implicit_blender.c
index cc388eb..d91136b 100644
--- a/source/blender/physics/intern/implicit_blender.c
+++ b/source/blender/physics/intern/implicit_blender.c
@@ -1752,19 +1752,37 @@ BLI_INLINE bool spring_angle(Implicit_Data *data, int i, int j, int *i_a, int *i
 
 /* Angular springs roughly based on the bending model proposed by Baraff and Witkin in "Large Steps in Cloth Simulation" */
 bool BPH_mass_spring_force_spring_angular(Implicit_Data *data, int i, int j, int *i_a, int *i_b, int len_a, int len_b,
-                                          float restang, float stiffness, float damping)
+                                          float restangorig, float *angoffset, float stiffness, float damping,
+                                          float plasticity, float yield_ang)
 {
 	float angle, dir_a[3], dir_b[3], vel_a[3], vel_b[3];
 	float f_a[3], f_b[3], f_e[3];
 	float force;
+	float restang;
 	int x;
 
+	restang = restangorig + *angoffset;
+
 	spring_angle(data, i, j, i_a, i_b, len_a, len_b,
 	             dir_a, dir_b, &angle, vel_a, vel_b);
 
 	/* spring force */
 	force = stiffness * (angle - restang);
 
+	/* compute plasticity offset */
+	if (angle > restang) {
+		if (angle - restang > yield_ang) {
+			restang += (angle - restang - yield_ang) * plasticity;
+			*angoffset = restang - restangorig;
+		}
+	}
+	else if (angle < restang) {
+		if (restang - angle > yield_ang) {
+			restang -= (restang - angle - yield_ang) * plasticity;
+			*angoffset = restang - restangorig;
+		}
+	}
+
 	/* damping force */
 	force += -damping * (dot_v3v3(vel_a, dir_a) + dot_v3v3(vel_b, dir_b));




More information about the Bf-blender-cvs mailing list