[Bf-blender-cvs] [bc3b482b9d] cloth-improvements: Implement separate normal override and single sided collisions

Luca Rood noreply at git.blender.org
Wed Feb 1 17:03:00 CET 2017


Commit: bc3b482b9d08e925d17366c76333541c00fdd572
Author: Luca Rood
Date:   Wed Feb 1 14:00:13 2017 -0200
Branches: cloth-improvements
https://developer.blender.org/rBbc3b482b9d08e925d17366c76333541c00fdd572

Implement separate normal override and single sided collisions

This adds single sided collisions without necessarily using normal
override, and adds a separate normal override option. (code can do with
some cosmetic cleanup)

Also removed a printf I had forgotten.

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

M	release/scripts/startup/bl_ui/properties_physics_field.py
M	source/blender/blenkernel/intern/collision.c
M	source/blender/blenkernel/intern/effect.c
M	source/blender/makesdna/DNA_object_force.h
M	source/blender/makesrna/intern/rna_object_force.c
M	source/blender/physics/intern/BPH_mass_spring.cpp

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_field.py b/release/scripts/startup/bl_ui/properties_physics_field.py
index 53188b8857..3ee8f25dd5 100644
--- a/release/scripts/startup/bl_ui/properties_physics_field.py
+++ b/release/scripts/startup/bl_ui/properties_physics_field.py
@@ -222,6 +222,7 @@ class PHYSICS_PT_collision(PhysicButtonsPanel, Panel):
             sub.prop(settings, "thickness_outer", text="Outer", slider=True)
             sub.prop(settings, "thickness_inner", text="Inner", slider=True)
 
+            col.prop(settings, "use_culling")
             col.prop(settings, "use_normal")
 
             col.prop(settings, "cloth_friction")
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index 71dee85d9c..d3b7aa4323 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -430,10 +430,28 @@ static int cloth_collision_response_static (ClothModifierData *clmd, CollisionMo
 		if (collob->pd->flag & PFIELD_CLOTH_USE_NORMAL) {
 			normal_tri_v3(collider_norm, collmd->current_x[collpair->bp1].co, collmd->current_x[collpair->bp2].co, collmd->current_x[collpair->bp3].co);
 			backside = dot_v3v3(collider_norm, collpair->normal) < 0.0f;
+
+			if (!(collob->pd->flag & PFIELD_CLOTH_USE_CULLING) && backside) {
+				negate_v3(collider_norm);
+				backside = false;
+			}
 		}
 		else {
 			copy_v3_v3(collider_norm, collpair->normal);
-			backside = false;
+
+			if (collob->pd->flag & PFIELD_CLOTH_USE_CULLING) {
+				float tmp_norm[3];
+
+				normal_tri_v3(tmp_norm, collmd->current_x[collpair->bp1].co, collmd->current_x[collpair->bp2].co, collmd->current_x[collpair->bp3].co);
+				backside = dot_v3v3(collider_norm, tmp_norm) < 0.0f;
+
+				if (backside) {
+					negate_v3(collider_norm);
+				}
+			}
+			else {
+				backside = false;
+			}
 		}
 
 		/* Calculate relative "velocity". */
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index 41d59805c2..d867ebbd61 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -127,7 +127,7 @@ PartDeflect *object_add_collision_fields(int type)
 			pd->f_flow = 1.0f;
 			break;
 	}
-	pd->flag = PFIELD_DO_LOCATION|PFIELD_DO_ROTATION|PFIELD_CLOTH_USE_NORMAL;
+	pd->flag = PFIELD_DO_LOCATION|PFIELD_DO_ROTATION|PFIELD_CLOTH_USE_CULLING;
 
 	return pd;
 }
diff --git a/source/blender/makesdna/DNA_object_force.h b/source/blender/makesdna/DNA_object_force.h
index 68018dbd16..a299e90fb7 100644
--- a/source/blender/makesdna/DNA_object_force.h
+++ b/source/blender/makesdna/DNA_object_force.h
@@ -375,7 +375,8 @@ typedef struct SoftBody {
 #define PFIELD_DO_ROTATION		(1<<15)
 #define PFIELD_GUIDE_PATH_WEIGHT (1<<16)	/* apply curve weights */
 #define PFIELD_SMOKE_DENSITY    (1<<17)		/* multiply smoke force by density */
-#define PFIELD_CLOTH_USE_NORMAL (1<<18)		/* enable cloth collision side detection based on normal */
+#define PFIELD_CLOTH_USE_CULLING (1<<18)		/* enable cloth collision side detection based on normal */
+#define PFIELD_CLOTH_USE_NORMAL (1<<19)		/* replace collision direction with collider normal */
 
 /* pd->falloff */
 #define PFIELD_FALL_SPHERE		0
diff --git a/source/blender/makesrna/intern/rna_object_force.c b/source/blender/makesrna/intern/rna_object_force.c
index 38d6846148..80e414f307 100644
--- a/source/blender/makesrna/intern/rna_object_force.c
+++ b/source/blender/makesrna/intern/rna_object_force.c
@@ -993,9 +993,14 @@ static void rna_def_collision(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Friction", "Friction for cloth collisions");
 	RNA_def_property_update(prop, 0, "rna_CollisionSettings_update");
 
+	prop = RNA_def_property(srna, "use_culling", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", PFIELD_CLOTH_USE_CULLING);
+	RNA_def_property_ui_text(prop, "Single Sided", "Cloth collision acts with respect to the collider normals (improves penetration recovery)");
+	RNA_def_property_update(prop, 0, "rna_CollisionSettings_update");
+
 	prop = RNA_def_property(srna, "use_normal", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", PFIELD_CLOTH_USE_NORMAL);
-	RNA_def_property_ui_text(prop, "Single Sided", "Cloth collision acts with respect to the collider normals (improves penetration recovery)");
+	RNA_def_property_ui_text(prop, "Override Normals", "Cloth collision impulses act in the direction of the collider normals (might improve some cases)");
 	RNA_def_property_update(prop, 0, "rna_CollisionSettings_update");
 }
 
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 581d3c30a6..6e64048708 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -1168,8 +1168,6 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
 						BPH_mass_spring_set_motion_state(id, i, verts[i].txold, verts[i].tvold);
 					}
 
-					printf("Resetting\n");
-
 					continue;
 				}
 			}




More information about the Bf-blender-cvs mailing list