[Bf-blender-cvs] [e3d31b8dfbd] blender2.8: Cloth: Componentize forces

Luca Rood noreply at git.blender.org
Fri Aug 31 16:41:22 CEST 2018


Commit: e3d31b8dfbdc3f4412e12fa1594927098ed0654d
Author: Luca Rood
Date:   Wed Aug 29 00:29:37 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBe3d31b8dfbdc3f4412e12fa1594927098ed0654d

Cloth: Componentize forces

This separates cloth stiffness and damping forces into tension,
compression, and shearing components, allowing more control over the
cloth behaviour.

This also adds a bending model selector (although the new bending model
itself is not implemented in this commit). This is because some of the
features implemented here only make sense within the new bending model,
while the old model is kept for compatibility.

This commit makes non-breaking changes, and thus maintains full
compatibility with existing simulations.

Reviewed By: brecht

Differential Revision: http://developer.blender.org/D3655

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

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/blenkernel/intern/particle_system.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/makesdna/DNA_cloth_types.h
M	source/blender/makesrna/intern/rna_cloth.c
M	source/blender/makesrna/intern/rna_particle.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 d65be4e578a..bcb0382f8c3 100644
--- a/release/scripts/startup/bl_ui/properties_physics_cloth.py
+++ b/release/scripts/startup/bl_ui/properties_physics_cloth.py
@@ -74,20 +74,38 @@ class PHYSICS_PT_cloth(PhysicButtonsPanel, Panel):
         col = flow.column()
         col.prop(cloth, "quality", text="Quality Steps")
         col.prop(cloth, "time_scale", text="Speed Multiplier")
+        col.prop(cloth, "bending_model")
 
         col.separator()
 
         col = flow.column()
         col.prop(cloth, "mass", text="Material Mass")
-        col.prop(cloth, "structural_stiffness", text="Structural")
+        col.prop(cloth, "air_damping", text="Air")
+        col.prop(cloth, "vel_damping", text="Velocity")
+
+        col.separator()
+
+        col = flow.column()
+        if cloth.bending_model == 'ANGULAR':
+            col.prop(cloth, "tension_stiffness", text="Stiffness Tension")
+            col.prop(cloth, "compression_stiffness", text="Compression")
+        else:
+            col.prop(cloth, "tension_stiffness", text="Stiffness Structural")
+
+        col.prop(cloth, "shear_stiffness", text="Shear")
         col.prop(cloth, "bending_stiffness", text="Bending")
 
         col.separator()
 
         col = flow.column()
-        col.prop(cloth, "spring_damping", text="Damping Spring")
-        col.prop(cloth, "air_damping", text="Air")
-        col.prop(cloth, "vel_damping", text="Velocity")
+        if cloth.bending_model == 'ANGULAR':
+            col.prop(cloth, "tension_damping", text="Damping Tension")
+            col.prop(cloth, "compression_damping", text="Compression")
+        else:
+            col.prop(cloth, "tension_damping", text="Damping Structural")
+
+        col.prop(cloth, "shear_damping", text="Shear")
+        col.prop(cloth, "bending_damping", text="Bending")
 
         col = flow.column()
         col.prop(cloth, "use_dynamic_mesh", text="Dynamic Mesh")
@@ -248,7 +266,17 @@ class PHYSICS_PT_cloth_stiffness(PhysicButtonsPanel, Panel):
             cloth, "vertex_group_structural_stiffness", ob, "vertex_groups",
             text="Structural Group"
         )
-        col.prop(cloth, "structural_stiffness_max", text="Max")
+        col.prop(cloth, "tension_stiffness_max", text="Max Tension")
+        col.prop(cloth, "compression_stiffness_max", text="Compression")
+
+        col.separator()
+
+        col = flow.column()
+        col.prop_search(
+            cloth, "vertex_group_shear_stiffness", ob, "vertex_groups",
+            text="Shear Group"
+        )
+        col.prop(cloth, "shear_stiffness_max", text="Max")
 
         col.separator()
 
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index 82a8d7f4e43..a099ae46d78 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -167,11 +167,17 @@ typedef enum {
 	CLOTH_SIMSETTINGS_FLAG_TEARING = ( 1 << 4 ),// true if tearing is enabled
 	CLOTH_SIMSETTINGS_FLAG_SCALING = ( 1 << 8 ), /* is advanced scaling active? */
 	CLOTH_SIMSETTINGS_FLAG_CCACHE_EDIT = (1 << 12),	/* edit cache in editmode */
-	CLOTH_SIMSETTINGS_FLAG_NO_SPRING_COMPRESS = (1 << 13), /* don't allow spring compression */
+	CLOTH_SIMSETTINGS_FLAG_RESIST_SPRING_COMPRESS = (1 << 13), /* don't allow spring compression */
 	CLOTH_SIMSETTINGS_FLAG_SEW = (1 << 14), /* pull ends of loose edges together */
 	CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH = (1 << 15), /* make simulation respect deformations in the base object */
 } CLOTH_SIMSETTINGS_FLAGS;
 
+/* ClothSimSettings.bending_model. */
+typedef enum {
+	CLOTH_BENDING_LINEAR	= 0,
+	CLOTH_BENDING_ANGULAR	= 1,
+} CLOTH_BENDING_MODEL;
+
 /* COLLISION FLAGS */
 typedef enum {
 	CLOTH_COLLSETTINGS_FLAG_ENABLED = ( 1 << 1 ), /* enables cloth - object collisions */
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index caf5b94b30e..54236785509 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -85,13 +85,18 @@ void cloth_init(ClothModifierData *clmd )
 	clmd->sim_parms->gravity[0] = 0.0;
 	clmd->sim_parms->gravity[1] = 0.0;
 	clmd->sim_parms->gravity[2] = -9.81;
-	clmd->sim_parms->structural = 15.0;
-	clmd->sim_parms->max_struct = 15.0;
-	clmd->sim_parms->shear = 15.0;
+	clmd->sim_parms->tension = 15.0;
+	clmd->sim_parms->max_tension = 15.0;
+	clmd->sim_parms->compression = 15.0;
+	clmd->sim_parms->max_compression = 15.0;
+	clmd->sim_parms->shear = 5.0;
+	clmd->sim_parms->max_shear = 5.0;
 	clmd->sim_parms->bending = 0.5;
 	clmd->sim_parms->max_bend = 0.5;
+	clmd->sim_parms->tension_damp = 5.0;
+	clmd->sim_parms->compression_damp = 5.0;
+	clmd->sim_parms->shear_damp = 5.0;
 	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;
 	clmd->sim_parms->stepsPerFrame = 5;
@@ -134,6 +139,8 @@ void cloth_init(ClothModifierData *clmd )
 
 	clmd->sim_parms->voxel_cell_size = 0.1f;
 
+	clmd->sim_parms->bending_model = CLOTH_BENDING_ANGULAR;
+
 	if (!clmd->sim_parms->effector_weights)
 		clmd->sim_parms->effector_weights = BKE_add_effector_weights(NULL);
 
@@ -728,6 +735,9 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, Mesh *mesh )
 					if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SCALING ) {
 						if ( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_struct-1)) {
 							verts->struct_stiff = dvert->dw [j].weight;
+						}
+
+						if ( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_shear-1)) {
 							verts->shear_stiff = dvert->dw [j].weight;
 						}
 
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index de4d25a95d9..a5ce7893d3e 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -3171,7 +3171,7 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
 		psys->clmd = (ClothModifierData*)modifier_new(eModifierType_Cloth);
 		psys->clmd->sim_parms->goalspring = 0.0f;
 		psys->clmd->sim_parms->vel_damping = 1.0f;
-		psys->clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_GOAL|CLOTH_SIMSETTINGS_FLAG_NO_SPRING_COMPRESS;
+		psys->clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_GOAL|CLOTH_SIMSETTINGS_FLAG_RESIST_SPRING_COMPRESS;
 		psys->clmd->coll_parms->flags &= ~CLOTH_COLLSETTINGS_FLAG_SELF;
 	}
 
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 987e4bb3cfa..a35c0531059 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -40,6 +40,7 @@
 
 #include "DNA_object_types.h"
 #include "DNA_camera_types.h"
+#include "DNA_cloth_types.h"
 #include "DNA_collection_types.h"
 #include "DNA_constraint_types.h"
 #include "DNA_gpu_types.h"
@@ -80,6 +81,7 @@
 #include "BKE_gpencil.h"
 #include "BKE_paint.h"
 #include "BKE_object.h"
+#include "BKE_cloth.h"
 
 #include "BLT_translation.h"
 
@@ -1920,5 +1922,27 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
 				}
 			}
 		}
+
+		if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "short", "bending_model")) {
+			for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
+				for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
+					if (md->type == eModifierType_Cloth) {
+						ClothModifierData *clmd = (ClothModifierData *)md;
+
+						clmd->sim_parms->bending_model = CLOTH_BENDING_LINEAR;
+						clmd->sim_parms->tension = clmd->sim_parms->structural;
+						clmd->sim_parms->compression = clmd->sim_parms->structural;
+						clmd->sim_parms->shear = clmd->sim_parms->structural;
+						clmd->sim_parms->max_tension = clmd->sim_parms->max_struct;
+						clmd->sim_parms->max_compression = clmd->sim_parms->max_struct;
+						clmd->sim_parms->max_shear = clmd->sim_parms->max_struct;
+						clmd->sim_parms->vgroup_shear = clmd->sim_parms->vgroup_struct;
+						clmd->sim_parms->tension_damp = clmd->sim_parms->Cdis;
+						clmd->sim_parms->compression_damp = clmd->sim_parms->Cdis;
+						clmd->sim_parms->shear_damp = clmd->sim_parms->Cdis;
+					}
+				}
+			}
+		}
 	}
 }
diff --git a/source/blender/makesdna/DNA_cloth_types.h b/source/blender/makesdna/DNA_cloth_types.h
index 940872fd08d..1b7f3ab9c4a 100644
--- a/source/blender/makesdna/DNA_cloth_types.h
+++ b/source/blender/makesdna/DNA_cloth_types.h
@@ -49,17 +49,17 @@
 typedef struct ClothSimSettings {
 	struct	LinkNode *cache; /* UNUSED atm */
 	float 	mingoal; 	/* see SB */
-	float	Cdis;		/* Mechanical damping of springs.		*/
+	float	Cdis DNA_DEPRECATED;	/* Mechanical damping of springs. */
 	float	Cvi;		/* Viscous/fluid damping.			*/
 	float	gravity[3];	/* Gravity/external force vector.		*/
 	float	dt;		/* This is the duration of our time step, computed.	*/
 	float	mass;		/* The mass of the entire cloth.		*/
-	float	structural;	/* Structural spring stiffness.			*/
+	float	structural DNA_DEPRECATED;	/* Structural spring stiffness. */
 	float	shear;		/* Shear spring stiffness.			*/
 	float	bending;	/* Flexion spring stiffness.			*/
 	float	max_bend; 	/* max bending scaling value, min is "bending" */
-	float	max_struct; 	/* max structural scaling value, min is "structural" */
-	float	max_shear; 	/* max shear scaling value, UNUSED */
+	float	max_struct DNA_DEPRECATED;	/* max structural scaling value, min is "structural" */
+	float	max_shear; 	/* max shear scaling value */
 	float	max_sewing; 	/* max sewing force */
 	float 	avg_spring_len; /* used for normalized springs */
 	float 	timescale; /* parameter how fast cloth runs */
@@ -101,6 +101,16 @@ typedef struct ClothSimSettings {
 
 	char pad0[4];
 	struct EffectorWeights *effector_weights;
+
+	short	bending_model;
+	short	vgroup_shear;		/* Vertex group for scaling structural stiffness. */
+	float	tension;
+	float	compression;
+	float	max_tension;
+	float	max_compression;
+	float	tension_damp;		/* Mechanical damping of tension springs. */
+	float	compression_damp;	/* Mechanical damping of compression sp

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list