[Bf-blender-cvs] [fb542eadd4] cloth-improvements: UI Cleanup: Separate object collisions from self collisions

Luca Rood noreply at git.blender.org
Sat Jan 7 05:10:04 CET 2017


Commit: fb542eadd427e87996077ba2f4dc27dc4dd2c1c5
Author: Luca Rood
Date:   Fri Jan 6 23:36:30 2017 -0200
Branches: cloth-improvements
https://developer.blender.org/rBfb542eadd427e87996077ba2f4dc27dc4dd2c1c5

UI Cleanup: Separate object collisions from self collisions

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

M	release/scripts/startup/bl_ui/properties_physics_cloth.py
M	source/blender/blenkernel/intern/collision.c
M	source/blender/physics/intern/BPH_mass_spring.cpp

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_cloth.py b/release/scripts/startup/bl_ui/properties_physics_cloth.py
index a4a32d7e9c..94c7197b97 100644
--- a/release/scripts/startup/bl_ui/properties_physics_cloth.py
+++ b/release/scripts/startup/bl_ui/properties_physics_cloth.py
@@ -195,12 +195,6 @@ class PHYSICS_PT_cloth_collision(PhysicButtonsPanel, Panel):
     bl_options = {'DEFAULT_CLOSED'}
     COMPAT_ENGINES = {'BLENDER_RENDER'}
 
-    def draw_header(self, context):
-        cloth = context.cloth.collision_settings
-
-        self.layout.active = cloth_panel_enabled(context.cloth)
-        self.layout.prop(cloth, "use_collision", text="")
-
     def draw(self, context):
         layout = self.layout
 
@@ -208,26 +202,46 @@ class PHYSICS_PT_cloth_collision(PhysicButtonsPanel, Panel):
         md = context.cloth
         ob = context.object
 
-        layout.active = cloth.use_collision and cloth_panel_enabled(md)
+        layout.active = cloth_panel_enabled(md)
 
         split = layout.split()
 
         col = split.column()
+        col.prop(cloth, "use_collision", text="Object Collision:")
+
+        sub = col.column()
+        sub.active = cloth.use_collision
+        sub.prop(cloth, "friction")
+        sub.prop(cloth, "repel_force", slider=True, text="Repel")
+
+        col = split.column()
+        col.active = cloth.use_collision
         col.prop(cloth, "collision_quality", text="Quality")
         col.prop(cloth, "distance_min", slider=True, text="Distance")
-        col.prop(cloth, "repel_force", slider=True, text="Repel")
         col.prop(cloth, "distance_repel", slider=True, text="Repel Distance")
-        col.prop(cloth, "friction")
 
-        col = split.column()
-        col.prop(cloth, "use_self_collision", text="Self Collision")
-        sub = col.column()
+        sub = layout.column()
+        sub.active = cloth.use_collision
+        sub.prop(cloth, "group")
+
+        layout.separator()
+
+        col = layout.column()
+
+        split = col.split()
+
+        split.prop(cloth, "use_self_collision", text="Self Collision:")
+        sub = split.column()
         sub.active = cloth.use_self_collision
         sub.prop(cloth, "self_collision_quality", text="Quality")
+
+        sub = col.column()
+        sub.active = cloth.use_self_collision
         sub.prop(cloth, "self_distance_min", slider=True, text="Distance")
-        sub.prop_search(cloth, "vertex_group_self_collisions", ob, "vertex_groups", text="")
 
-        layout.prop(cloth, "group")
+        sub = layout.column()
+        sub.active = cloth.use_self_collision
+        sub.prop_search(cloth, "vertex_group_self_collisions", ob, "vertex_groups", text="Vertex Group")
 
 
 class PHYSICS_PT_cloth_stiffness(PhysicButtonsPanel, Panel):
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index 858cfbdde3..bc722fc5fb 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -698,89 +698,95 @@ int cloth_bvh_objcollision(Object *ob, ClothModifierData *clmd, float step, floa
 	// static collisions
 	////////////////////////////////////////////////////////////
 
-	// update cloth bvh
-	bvhtree_update_from_cloth ( clmd, 1 ); // 0 means STATIC, 1 means MOVING (see later in this function)
-	bvhselftree_update_from_cloth ( clmd, 0 ); // 0 means STATIC, 1 means MOVING (see later in this function)
-	
-	collobjs = get_collisionobjects(clmd->scene, ob, clmd->coll_parms->group, &numcollobj, eModifierType_Collision);
-	
-	if (!collobjs)
-		return 0;
-
-	/* move object to position (step) in time */
-	for (i = 0; i < numcollobj; i++) {
-		Object *collob= collobjs[i];
-		CollisionModifierData *collmd = (CollisionModifierData *)modifiers_findByType(collob, eModifierType_Collision);
-
-		if (!collmd->bvhtree)
-			continue;
-
-		/* move object to position (step) in time */
-		collision_move_object ( collmd, step + dt, step );
-	}
+	if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED) {
+		bvhtree_update_from_cloth ( clmd, 1 ); // 0 means STATIC, 1 means MOVING (see later in this function)
 
-	do {
-		CollPair **collisions, **collisions_index;
+		collobjs = get_collisionobjects(clmd->scene, ob, clmd->coll_parms->group, &numcollobj, eModifierType_Collision);
 		
-		ret2 = 0;
+		if (!collobjs)
+			return 0;
 
-		collisions = MEM_callocN(sizeof(CollPair *) *numcollobj, "CollPair");
-		collisions_index = MEM_callocN(sizeof(CollPair *) *numcollobj, "CollPair");
-		
-		// check all collision objects
+		/* move object to position (step) in time */
 		for (i = 0; i < numcollobj; i++) {
 			Object *collob= collobjs[i];
 			CollisionModifierData *collmd = (CollisionModifierData *)modifiers_findByType(collob, eModifierType_Collision);
-			BVHTreeOverlap *overlap = NULL;
-			unsigned int result = 0;
-			
+
 			if (!collmd->bvhtree)
 				continue;
-			
-			/* search for overlapping collision pairs */
-			overlap = BLI_bvhtree_overlap(cloth_bvh, collmd->bvhtree, &result, NULL, NULL);
-				
-			// go to next object if no overlap is there
-			if ( result && overlap ) {
-				/* check if collisions really happen (costly near check) */
-				cloth_bvh_objcollisions_nearcheck ( clmd, collmd, &collisions[i], 
-					&collisions_index[i], result, overlap, dt/(float)clmd->coll_parms->loop_count);
-			
-				// resolve nearby collisions
-				ret += cloth_bvh_objcollisions_resolve ( clmd, collmd, collisions[i],  collisions_index[i]);
-				ret2 += ret;
-			}
 
-			if ( overlap )
-				MEM_freeN ( overlap );
-		}
-		rounds++;
-		
-		for (i = 0; i < numcollobj; i++) {
-			if ( collisions[i] ) MEM_freeN ( collisions[i] );
+			/* move object to position (step) in time */
+			collision_move_object ( collmd, step + dt, step );
 		}
-			
-		MEM_freeN(collisions);
-		MEM_freeN(collisions_index);
+	}
 
-		////////////////////////////////////////////////////////////
-		// update positions
-		// this is needed for bvh_calc_DOP_hull_moving() [kdop.c]
-		////////////////////////////////////////////////////////////
+	if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF) {
+		bvhselftree_update_from_cloth ( clmd, 0 ); // 0 means STATIC, 1 means MOVING (see later in this function)
+	}
 
-		/* verts come from clmd */
-		for (i = 0; i < mvert_num; i++) {
-			if ( clmd->sim_parms->vgroup_mass>0 ) {
-				if ( verts [i].flags & CLOTH_VERT_FLAG_PINNED ) {
+	do {
+		ret2 = 0;
+
+		if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED) {
+			CollPair **collisions, **collisions_index;
+
+			collisions = MEM_callocN(sizeof(CollPair *) *numcollobj, "CollPair");
+			collisions_index = MEM_callocN(sizeof(CollPair *) *numcollobj, "CollPair");
+
+			// check all collision objects
+			for (i = 0; i < numcollobj; i++) {
+				Object *collob= collobjs[i];
+				CollisionModifierData *collmd = (CollisionModifierData *)modifiers_findByType(collob, eModifierType_Collision);
+				BVHTreeOverlap *overlap = NULL;
+				unsigned int result = 0;
+
+				if (!collmd->bvhtree)
 					continue;
+
+				/* search for overlapping collision pairs */
+				overlap = BLI_bvhtree_overlap(cloth_bvh, collmd->bvhtree, &result, NULL, NULL);
+
+				// go to next object if no overlap is there
+				if ( result && overlap ) {
+					/* check if collisions really happen (costly near check) */
+					cloth_bvh_objcollisions_nearcheck ( clmd, collmd, &collisions[i],
+						&collisions_index[i], result, overlap, dt/(float)clmd->coll_parms->loop_count);
+
+					// resolve nearby collisions
+					ret += cloth_bvh_objcollisions_resolve ( clmd, collmd, collisions[i],  collisions_index[i]);
+					ret2 += ret;
 				}
+
+				if ( overlap )
+					MEM_freeN ( overlap );
 			}
 
-			VECADD ( verts[i].tx, verts[i].txold, verts[i].tv );
+			for (i = 0; i < numcollobj; i++) {
+				if ( collisions[i] ) MEM_freeN ( collisions[i] );
+			}
+
+			MEM_freeN(collisions);
+			MEM_freeN(collisions_index);
+
+			////////////////////////////////////////////////////////////
+			// update positions
+			// this is needed for bvh_calc_DOP_hull_moving() [kdop.c]
+			////////////////////////////////////////////////////////////
+
+			/* verts come from clmd */
+			for (i = 0; i < mvert_num; i++) {
+				if ( clmd->sim_parms->vgroup_mass>0 ) {
+					if ( verts [i].flags & CLOTH_VERT_FLAG_PINNED ) {
+						continue;
+					}
+				}
+
+				VECADD ( verts[i].tx, verts[i].txold, verts[i].tv );
+			}
+			////////////////////////////////////////////////////////////
 		}
-		////////////////////////////////////////////////////////////
-		
-		
+
+		rounds++;
+
 		////////////////////////////////////////////////////////////
 		// Test on *simple* selfcollisions
 		////////////////////////////////////////////////////////////
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 334d1681a2..5e23a83c9d 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -941,7 +941,7 @@ static void cloth_collision_solve_extra(Object *ob, ClothModifierData *clmd, Lis
 	bool do_extra_solve;
 	int i;
 	
-	if (!(clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED))
+	if (!(clmd->coll_parms->flags & (CLOTH_COLLSETTINGS_FLAG_ENABLED | CLOTH_COLLSETTINGS_FLAG_SELF)))
 		return;
 	if (!clmd->clothObject->bvhtree)
 		return;




More information about the Bf-blender-cvs mailing list