[Bf-blender-cvs] [ba39be6] fracture_modifier: speed enhancement for building compounds (omitting broadphase handles) and successful test with clusters, values need a bit tweaking but basic principle works

Martin Felke noreply at git.blender.org
Thu Oct 22 13:20:33 CEST 2015


Commit: ba39be6bc3828151c40e913d7b9a7c3beade485e
Author: Martin Felke
Date:   Thu Oct 22 13:16:42 2015 +0200
Branches: fracture_modifier
https://developer.blender.org/rBba39be6bc3828151c40e913d7b9a7c3beade485e

speed enhancement for building compounds (omitting broadphase handles) and successful test with clusters, values need a bit tweaking but basic principle works

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

M	extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp
M	extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h
M	intern/rigidbody/RBI_api.h
M	intern/rigidbody/rb_bullet_api.cpp
M	source/blender/blenkernel/intern/fracture.c
M	source/blender/blenkernel/intern/rigidbody.c

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

diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp
index 37656ef..61c1f3b 100644
--- a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp
@@ -10,7 +10,8 @@ btFractureDynamicsWorld::btFractureDynamicsWorld (btDispatcher* dispatcher, btBr
 :btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration),
 m_fracturingMode(true),
 m_idCallback(callback),
-m_shapeBodyCallback(shapebodycallback)
+m_shapeBodyCallback(shapebodycallback),
+m_addBroadPhaseHandle(false)
 {
 	m_childIndexHash = new btHashMap<btHashInt, int>();
 }
@@ -53,6 +54,32 @@ void btFractureDynamicsWorld::updateBodies()
 					fbody->setWorldTransform(trans);
 				}
 			}
+			else
+			{
+				btCollisionShape *cshape = (btCollisionShape*)body->getCollisionShape();
+
+				//non compounds have a child index of -1, (and will have a broadphase handle)
+				int objectIndexA, shardIndexA;
+				m_idCallback(cshape->getUserPointer(), &objectIndexA, &shardIndexA);
+				m_childIndexHash->insert(shardIndexA, -1);
+			}
+		}
+	}
+}
+
+void	btFractureDynamicsWorld::updateAabbs()
+{
+	BT_PROFILE("updateAabbs");
+
+	//btTransform predictedTrans;
+	for ( int i=0;i<m_collisionObjects.size();i++)
+	{
+		btCollisionObject* colObj = m_collisionObjects[i];
+
+		//only update aabb of active objects
+		if ((m_forceUpdateAllAabbs || colObj->isActive()) && colObj->getBroadphaseHandle() != NULL)
+		{
+			updateSingleAabb(colObj);
 		}
 	}
 }
@@ -61,7 +88,7 @@ void btFractureDynamicsWorld::updateBodies()
 void btFractureDynamicsWorld::glueCallback()
 {
 
-	int numManifolds = getDispatcher()->getNumManifolds();
+	//int numManifolds = getDispatcher()->getNumManifolds();
 
 	///first build the islands based on axis aligned bounding box overlap
 
@@ -80,7 +107,8 @@ void btFractureDynamicsWorld::glueCallback()
 			if (!collisionObject->isStaticOrKinematicObject())
 			{
 				collisionObject->setIslandTag(index++);
-			} else
+			}
+			else
 			{
 				collisionObject->setIslandTag(-1);
 			}
@@ -125,6 +153,7 @@ void btFractureDynamicsWorld::glueCallback()
 	}
 #endif
 
+#if 0
 	int numConstraints = m_compoundConstraints.size();
 	for (int i=0;i<numConstraints;i++)
 	{
@@ -143,14 +172,29 @@ void btFractureDynamicsWorld::glueCallback()
 			unionFind.unite(tag0, tag1);
 		}
 	}
+#endif
 
-
-
+	for (int ai=0;ai<getCollisionObjectArray().size();ai++)
+	{
+		btCollisionObject* collisionObject= getCollisionObjectArray()[ai];
+		if (!collisionObject->isStaticOrKinematicObject())
+		{
+			if (collisionObject->getInternalType() & CUSTOM_FRACTURE_TYPE)
+			{
+				//ensure 1 compound per object, so shard id 0 becomes parent always.... sure that it is first ?
+				int objectId, shardId, islandTag;
+				islandTag = collisionObject->getIslandTag();
+				btFractureBody *body = (btFractureBody*)collisionObject;
+				m_idCallback(body->getUserPointer(),&objectId, &shardId);
+				if (objectId > -1)
+					unionFind.unite(objectId, islandTag);
+			}
+		}
+	}
 
 	numElem = unionFind.getNumElements();
 
 
-
 	index=0;
 	for (int ai=0;ai<getCollisionObjectArray().size();ai++)
 	{
@@ -227,7 +271,7 @@ void btFractureDynamicsWorld::glueCallback()
 			btScalar totalMass = 0.f;
 
 
-			btCompoundShape* compound = new btCompoundShape();
+			btCompoundShape* compound = new btCompoundShape(false);
 			if (fracObj->getCollisionShape()->isCompound())
 			{
 				btTransform tr;
@@ -335,7 +379,9 @@ void btFractureDynamicsWorld::glueCallback()
 				newBody->applyImpulse(imp, rel_pos);
 			}
 
+			m_addBroadPhaseHandle = true;
 			addRigidBody(newBody);
+			m_addBroadPhaseHandle = false;
 
 			//newbody is a compound parent, hmmmm, so set its childindex to 0 or -1
 			m_childIndexHash->insert(shardIndex, -1);
@@ -412,7 +458,9 @@ btFractureBody* btFractureDynamicsWorld::addNewBody(const btTransform& oldTransf
 
 	newBody->setCollisionFlags(newBody->getCollisionFlags()|btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
 	newBody->setWorldTransform(oldTransform*shift);
+	m_addBroadPhaseHandle = true;
 	addRigidBody(newBody);
+	m_addBroadPhaseHandle = false;
 	return newBody;
 }
 
@@ -450,12 +498,51 @@ void btFractureDynamicsWorld::removeConstraint(btTypedConstraint *constraint)
 
 void btFractureDynamicsWorld::addRigidBody(btRigidBody* body)
 {
+	bool addBroadPhaseHandle = true;
+
 	if (body->getInternalType() & CUSTOM_FRACTURE_TYPE)
 	{
+		int objectId, shardId;
 		btFractureBody* fbody = (btFractureBody*)body;
 		m_fractureBodies.push_back(fbody);
+		m_idCallback(fbody->getUserPointer(), &objectId, &shardId);
+		if (objectId > 0 && shardId > 1)
+			addBroadPhaseHandle = false;
+	}
+
+	//m_addBroadPhaseHandle is an override switch (for new, fractured objects)
+	if (addBroadPhaseHandle || m_addBroadPhaseHandle)
+	{
+		btDiscreteDynamicsWorld::addRigidBody(body);
+	}
+	else
+	{
+		//inlined from DiscreteDynamicsWorld::addRigidbody(if broadphase handle is omitted)
+		if (!body->isStaticOrKinematicObject() && !(body->getFlags() &BT_DISABLE_WORLD_GRAVITY))
+		{
+			body->setGravity(m_gravity);
+		}
+
+		if (body->getCollisionShape())
+		{
+			if (!body->isStaticObject())
+			{
+				m_nonStaticRigidBodies.push_back(body);
+			} else
+			{
+				body->setActivationState(ISLAND_SLEEPING);
+			}
+
+			btCollisionObject* collisionObject = (btCollisionObject*)body;
+
+			//its inside a compound and collision is disabled, so need no broadphase handle for children
+			//removing the broadphase stuff is N^2 and slow, only adding if necessary !
+			collisionObject->setBroadphaseHandle(NULL);
+
+			btAssert( m_collisionObjects.findLinearSearch(collisionObject)  == m_collisionObjects.size());
+			m_collisionObjects.push_back(collisionObject);
+		}
 	}
-	btDiscreteDynamicsWorld::addRigidBody(body);
 }
 
 void	btFractureDynamicsWorld::removeRigidBody(btRigidBody* body)
@@ -563,7 +650,7 @@ void	btFractureDynamicsWorld::breakDisconnectedParts( btFractureBody* fracObj)
 		int numShapes=0;
 
 
-		btCompoundShape* newCompound = new btCompoundShape();
+		btCompoundShape* newCompound = new btCompoundShape(false);
 		btAlignedObjectArray<btScalar> masses;
 
 		int idx;
diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h
index 88f01d5..4343166 100644
--- a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h
@@ -25,6 +25,8 @@ class btFractureDynamicsWorld : public btDiscreteDynamicsWorld
 
 	void	breakDisconnectedParts( btFractureBody* fracObj);
 
+	bool	m_addBroadPhaseHandle;
+
 public:
 
 	btFractureDynamicsWorld ( btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration, IdCallback callback, ShapeBodyCallback shapebodycallback);
@@ -67,6 +69,8 @@ public:
 	void updateBodies();
 
 	void propagateDamage(btFractureBody *body, btScalar *impulse, int connection_index, bool *needsBreakingCheck);
+
+	virtual void updateAabbs();
 };
 
 #endif //_BT_FRACTURE_DYNAMICS_WORLD_H
diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h
index 64e32e8..bc73c6f 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -136,7 +136,7 @@ void RB_world_convex_sweep_test(
 /* ............ */
 
 /* Create new RigidBody instance */
-rbRigidBody *RB_body_new(rbCollisionShape *shape, const float loc[3], const float rot[4]);
+rbRigidBody *RB_body_new(rbCollisionShape *shape, const float loc[3], const float rot[4], bool use_compounds);
 
 /* Delete the given RigidBody instance */
 void RB_body_delete(rbRigidBody *body);
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index 60f8060..6d523c5 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -78,7 +78,7 @@ subject to the following restrictions:
 #include "BulletDynamics/Dynamics/btFractureDynamicsWorld.h"
 
 struct rbRigidBody {
-	btFractureBody *body;
+	btRigidBody *body;
 	int col_groups;
 	int linear_index;
 	void *meshIsland;
@@ -91,7 +91,12 @@ typedef void (*IdOutCallback)(void *world, void *meshisland, int *objectId, int
 static btFractureBody* getBodyFromShape(void *shapePtr)
 {
 	rbRigidBody *body = (rbRigidBody*)shapePtr;
-	return body->body;
+	if (body->body->getInternalType() & CUSTOM_FRACTURE_TYPE)
+	{
+		btFractureBody* fbody = (btFractureBody*)body->body;
+		return fbody;
+	}
+	return NULL;
 }
 
 static inline void copy_v3_btvec3(float vec[3], const btVector3 &btvec)
@@ -527,21 +532,25 @@ void RB_dworld_export(rbDynamicsWorld *world, const char *filename)
 
 void RB_dworld_add_body(rbDynamicsWorld *world, rbRigidBody *object, int col_groups, void* meshIsland, void* blenderOb, int linear_index)
 {
-	btFractureBody *body = object->body;
-	body->setWorld(world->dynamicsWorld);
+	btRigidBody *body = object->body;
+
+	if (body->getInternalType() == CUSTOM_FRACTURE_TYPE)
+	{
+		btFractureBody* fbody = (btFractureBody*)body;
+		fbody->setWorld(world->dynamicsWorld);
+	}
 
 	object->col_groups = col_groups;
 	object->meshIsland = meshIsland;
 	object->world = world;
 	object->blenderOb = blenderOb;
 	object->linear_index = linear_index;
-	
 	world->dynamicsWorld->addRigidBody(body);
 }
 
 void RB_dworld_remove_body(rbDynamicsWorld *world, rbRigidBody *object)
 {
-	btFractureBody *body = object->body;
+	btRigidBody *body = object->body;
 	
 	world->dynamicsWorld->removeRigidBody(body);
 }
@@ -553,7 +562,7 @@ void RB_world_convex_sweep_test(
         const float loc_start[3], const float loc_end[3],
         float v_location[3],  float v_hitpoint[3],  float v_normal[3], int *r_hit)
 {
-	btFractureBody *body = object->body;
+	btRigidBody *body = object->body;
 	btCollisionShape *collisionShape = body->getCollisionShape();
 	/* only convex shapes are supported, but user can specify a non convex shape */
 	if (collisionShape->isConvex()) {
@@ -601,7 +610,7 @@ void RB_world_convex_sweep_test(
 
 /* ............ */
 
-rbRigidBody *RB_body_new(rbCollisionShape *sha

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list