[Bf-blender-cvs] [597936b] fracture_modifier: new feature: attempt to accelerate simulation of many adjacent shards by compounds; todo... improve connectivity check

Martin Felke noreply at git.blender.org
Tue Oct 20 21:32:11 CEST 2015


Commit: 597936b3fb006876e780e6da9c9c3da9bb345bb3
Author: Martin Felke
Date:   Tue Oct 20 21:31:29 2015 +0200
Branches: fracture_modifier
https://developer.blender.org/rB597936b3fb006876e780e6da9c9c3da9bb345bb3

new feature: attempt to accelerate simulation of many adjacent shards by compounds; todo... improve connectivity check

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

M	extern/bullet2/CMakeLists.txt
A	extern/bullet2/src/BulletDynamics/ConstraintSolver/btCompoundConstraint.cpp
A	extern/bullet2/src/BulletDynamics/ConstraintSolver/btCompoundConstraint.h
A	extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.cpp
A	extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.h
A	extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp
A	extern/bullet2/src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h
M	extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h
M	extern/bullet2/src/btBulletDynamicsCommon.h
M	intern/rigidbody/RBI_api.h
M	intern/rigidbody/rb_bullet_api.cpp
M	release/scripts/startup/bl_ui/properties_physics_fracture.py
M	source/blender/blenkernel/intern/rigidbody.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesdna/DNA_rigidbody_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/extern/bullet2/CMakeLists.txt b/extern/bullet2/CMakeLists.txt
index 2b2c18c..35ef63d 100644
--- a/extern/bullet2/CMakeLists.txt
+++ b/extern/bullet2/CMakeLists.txt
@@ -143,8 +143,11 @@ set(SRC
 	src/BulletDynamics/ConstraintSolver/btUniversalConstraint.cpp
 	src/BulletDynamics/ConstraintSolver/btGearConstraint.cpp
 	src/BulletDynamics/ConstraintSolver/btFixedConstraint.cpp
+	src/BulletDynamics/ConstraintSolver/btCompoundConstraint.cpp
 	src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
+	src/BulletDynamics/Dynamics/btFractureDynamicsWorld.cpp
 	src/BulletDynamics/Dynamics/btRigidBody.cpp
+	src/BulletDynamics/Dynamics/btFractureBody.cpp
 	src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp
 	src/BulletDynamics/Dynamics/Bullet-C-API.cpp
 	src/BulletDynamics/Vehicle/btRaycastVehicle.cpp
@@ -323,11 +326,14 @@ set(SRC
 	src/BulletDynamics/ConstraintSolver/btUniversalConstraint.h
 	src/BulletDynamics/ConstraintSolver/btGearConstraint.h
 	src/BulletDynamics/ConstraintSolver/btFixedConstraint.h
+	src/BulletDynamics/ConstraintSolver/btCompoundConstraint.h
 	src/BulletDynamics/Dynamics/btActionInterface.h
 	src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h
 	src/BulletDynamics/Dynamics/btDynamicsWorld.h
 	src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h
 	src/BulletDynamics/Dynamics/btRigidBody.h
+	src/BulletDynamics/Dynamics/btFractureBody.h
+	src/BulletDynamics/Dynamics/btFractureDynamicsWorld.h
 	src/BulletDynamics/Vehicle/btRaycastVehicle.h
 	src/BulletDynamics/Vehicle/btVehicleRaycaster.h
 	src/BulletDynamics/Vehicle/btWheelInfo.h
diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btCompoundConstraint.cpp b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btCompoundConstraint.cpp
new file mode 100644
index 0000000..6965035
--- /dev/null
+++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btCompoundConstraint.cpp
@@ -0,0 +1,8 @@
+
+#include "btCompoundConstraint.h"
+
+btCompoundConstraint::btCompoundConstraint(btRigidBody& rbA, btRigidBody& rbB)
+    :btTypedConstraint::btTypedConstraint(COMPOUND_CONSTRAINT_TYPE, rbA, rbB)
+{
+}
+
diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btCompoundConstraint.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btCompoundConstraint.h
new file mode 100644
index 0000000..d95ddbe
--- /dev/null
+++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btCompoundConstraint.h
@@ -0,0 +1,20 @@
+#ifndef BTCOMPOUNDCONSTRAINT_H
+#define BTCOMPOUNDCONSTRAINT_H
+
+#include "btTypedConstraint.h"
+
+#define COMPOUND_CONSTRAINT_TYPE (MAX_CONSTRAINT_TYPE+1)
+
+ATTRIBUTE_ALIGNED16(class) btCompoundConstraint : public btTypedConstraint
+{
+	public:
+		btCompoundConstraint(btRigidBody& rbA,btRigidBody& rbB);
+		virtual void getInfo1(btConstraintInfo1* info) {}
+		virtual void getInfo2(btConstraintInfo2* info) {}
+		virtual btScalar getParam(int num, int axis) const { return 0;}
+		virtual void setParam(int num, btScalar value, int axis) {}
+
+		int m_objectId;
+};
+
+#endif // BTCOMPOUNDCONSTRAINT_H
diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.cpp b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.cpp
new file mode 100644
index 0000000..e92dcb7
--- /dev/null
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.cpp
@@ -0,0 +1,178 @@
+
+#include "btFractureBody.h"
+#include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
+#include "BulletCollision/CollisionShapes/btCompoundShape.h"
+#include "BulletDynamics/Dynamics/btDynamicsWorld.h"
+
+#include "BulletDynamics/Dynamics/btFractureDynamicsWorld.h"
+
+
+
+void	btFractureBody::recomputeConnectivity(btCollisionWorld* world)
+{
+	m_connections.clear();
+	//@todo use the AABB tree to avoid N^2 checks
+
+	if (getCollisionShape()->isCompound())
+	{
+		btCompoundShape* compound = (btCompoundShape*)getCollisionShape();
+		for (int i=0;i<compound->getNumChildShapes();i++)
+		{
+			for (int j=i+1;j<compound->getNumChildShapes();j++)
+			{
+
+				struct   MyContactResultCallback : public btCollisionWorld::ContactResultCallback
+				{
+					bool m_connected;
+					btScalar m_margin;
+					MyContactResultCallback() :m_connected(false),m_margin(0.05)
+					{
+					}
+					virtual   btScalar   addSingleResult(btManifoldPoint& cp,   const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1)
+					{
+						if (cp.getDistance()<=m_margin)
+							m_connected = true;
+						return 1.f;
+					}
+			   };
+
+				MyContactResultCallback result;
+
+				btCollisionObject obA;
+				obA.setWorldTransform(compound->getChildTransform(i));
+				obA.setCollisionShape(compound->getChildShape(i));
+				btCollisionObject obB;
+				obB.setWorldTransform(compound->getChildTransform(j));
+				obB.setCollisionShape(compound->getChildShape(j));
+				world->contactPairTest(&obA,&obB,result);
+				if (result.m_connected)
+				{
+					btConnection tmp;
+					tmp.m_childIndex0 = i;
+					tmp.m_childIndex1 = j;
+					tmp.m_childShape0 = compound->getChildShape(i);
+					tmp.m_childShape1 = compound->getChildShape(j);
+					tmp.m_strength = 1.f;//??
+					m_connections.push_back(tmp);
+				}
+			}
+		}
+	}
+	
+
+}
+
+void btFractureBody::recomputeConnectivityByConstraints(btCollisionWorld *world1)
+{
+	btFractureDynamicsWorld *world = (btFractureDynamicsWorld*)world1;
+
+	if (world->m_idCallback != NULL)
+	{
+		int i;
+		m_connections.clear();
+
+		for (i=0; i<world->m_compoundConstraints.size();i++)
+		{
+			btCompoundConstraint *con = world->m_compoundConstraints[i];
+
+			if (con->isEnabled())
+			{
+				int obIdA, shardIdA, obIdB, shardIdB;
+				btFractureBody *obA = (btFractureBody*)&con->getRigidBodyA();
+				btFractureBody *obB = (btFractureBody*)&con->getRigidBodyB();
+
+				world->m_idCallback(obA->getUserPointer(), &obIdA, &shardIdA);
+				world->m_idCallback(obB->getUserPointer(), &obIdB, &shardIdB);
+
+				if ((obIdA == obIdB) && (shardIdA != shardIdB))
+				{
+					btConnection tmp;
+					tmp.m_childIndex0 = shardIdA;
+					tmp.m_childIndex1 = shardIdB;
+					tmp.m_childShape0 = obA->getCollisionShape();
+					tmp.m_childShape1 = obB->getCollisionShape();
+					tmp.m_strength = con->getBreakingImpulseThreshold();
+					m_connections.push_back(tmp);
+				}
+			}
+		}
+	}
+}
+
+btCompoundShape* btFractureBody::shiftTransformDistributeMass(btCompoundShape* boxCompound,btScalar mass,btTransform& shift)
+{
+
+	btVector3 principalInertia;
+
+	btScalar* masses = new btScalar[boxCompound->getNumChildShapes()];
+	for (int j=0;j<boxCompound->getNumChildShapes();j++)
+	{
+		//evenly distribute mass
+		masses[j]=mass/boxCompound->getNumChildShapes();
+	}
+
+	return shiftTransform(boxCompound,masses,shift,principalInertia);
+
+}
+
+
+btCompoundShape* btFractureBody::shiftTransform(btCompoundShape* boxCompound,btScalar* masses,btTransform& shift, btVector3& principalInertia)
+{
+	btTransform principal;
+
+	boxCompound->calculatePrincipalAxisTransform(masses,principal,principalInertia);
+
+
+	///create a new compound with world transform/center of mass properly aligned with the principal axis
+
+	///non-recursive compound shapes perform better
+	
+#ifdef USE_RECURSIVE_COMPOUND
+
+	btCompoundShape* newCompound = new btCompoundShape();
+	newCompound->addChildShape(principal.inverse(),boxCompound);
+	newBoxCompound = newCompound;
+	//m_collisionShapes.push_back(newCompound);
+
+	//btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
+	//btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,newCompound,principalInertia);
+
+#else
+#ifdef CHANGE_COMPOUND_INPLACE
+	newBoxCompound = boxCompound;
+	for (int i=0;i<boxCompound->getNumChildShapes();i++)
+	{
+		btTransform newChildTransform = principal.inverse()*boxCompound->getChildTransform(i);
+		///updateChildTransform is really slow, because it re-calculates the AABB each time. todo: add option to disable this update
+		boxCompound->updateChildTransform(i,newChildTransform);
+	}
+	bool isDynamic = (mass != 0.f);
+	btVector3 localInertia(0,0,0);
+	if (isDynamic)
+		boxCompound->calculateLocalInertia(mass,localInertia);
+	
+#else
+	///creation is faster using a new compound to store the shifted children
+	btCompoundShape* newBoxCompound = new btCompoundShape();
+	for (int i=0;i<boxCompound->getNumChildShapes();i++)
+	{
+		btTransform newChildTransform = principal.inverse()*boxCompound->getChildTransform(i);
+		///updateChildTransform is really slow, because it re-calculates the AABB each time. todo: add option to disable this update
+		newBoxCompound->addChildShape(newChildTransform,boxCompound->getChildShape(i));
+	}
+
+
+
+#endif
+
+#endif//USE_RECURSIVE_COMPOUND
+
+	shift = principal;
+	return newBoxCompound;
+}
+
+
+
+
+
+
diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.h b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.h
new file mode 100644
index 0000000..031a48e
--- /dev/null
+++ b/extern/bullet2/src/BulletDynamics/Dynamics/btFractureBody.h
@@ -0,0 +1,85 @@
+
+#ifndef BT_FRACTURE_BODY
+#define BT_FRACTURE_BODY
+
+class btCollisionShape;
+class btDynamicsWorld;
+class btCollisionWorld;
+class btCompoundShape;
+class btManifoldPoint;
+
+#include "LinearMath/btAlignedObjectArray.h"
+#include "BulletDynamics/Dynamics/btRigidBody.h"
+
+#define CUSTOM_FRACTURE_TYPE (btRigidBody::CO_USER_TYPE+1)
+
+
+struct btConnection
+{
+	
+	btCollisionShape*	m_childShape0;
+	btCollisionShape*	m_childShape1;
+	int	m_childIndex0;
+	int	m_childIndex1;
+	btScalar	m_strength;
+};
+
+class btFractureBody : public btRigidBody
+{
+	//connections
+public:
+
+	btDynamicsWorld*	m_world;
+	btAlignedObjectArray<btScalar>	m_masses;
+	btAlignedObjectArray<btConnection>	m_connections;
+	int m_childIndex;
+
+
+
+	btFractureBody(	const btRigidBodyConstructionInfo& constructionInfo)
+		:btRigidBody(constructionInfo),
+		m_world(0),
+		m_childIndex(-1)
+	{
+		m_masses.push_back(constructionInfo.m_mass);
+		m_internalType=CUSTOM_FRACTURE_TYPE+CO_RIGID_BODY;
+	}
+
+
+
+	///btRigidBody constructor for backwards compatibility. 
+	///To specify friction (etc) during rigid body construction, please use the other constructor (using btRigidBodyConstructionInfo)
+	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list