Skip to content

Commit

Permalink
Merge pull request #38253 from nekomatata/bullet-update-2.90
Browse files Browse the repository at this point in the history
Update to bullet master (2.90)
  • Loading branch information
akien-mga authored Apr 27, 2020
2 parents 3fff0dd + 3e7db60 commit f7e2ff5
Show file tree
Hide file tree
Showing 56 changed files with 4,401 additions and 856 deletions.
1 change: 1 addition & 0 deletions modules/bullet/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ if env["builtin_bullet"]:
"BulletSoftBody/btDeformableContactProjection.cpp",
"BulletSoftBody/btDeformableMultiBodyDynamicsWorld.cpp",
"BulletSoftBody/btDeformableContactConstraint.cpp",
"BulletSoftBody/poly34.cpp",
# clew
"clew/clew.c",
# LinearMath
Expand Down
8 changes: 5 additions & 3 deletions platform/linuxbsd/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,17 @@ def configure(env):
env.ParseConfig("pkg-config libpng16 --cflags --libs")

if not env["builtin_bullet"]:
# We need at least version 2.89
# We need at least version 2.90
min_bullet_version = "2.90"

import subprocess

bullet_version = subprocess.check_output(["pkg-config", "bullet", "--modversion"]).strip()
if str(bullet_version) < "2.89":
if str(bullet_version) < min_bullet_version:
# Abort as system bullet was requested but too old
print(
"Bullet: System version {0} does not match minimal requirements ({1}). Aborting.".format(
bullet_version, "2.89"
bullet_version, min_bullet_version
)
)
sys.exit(255)
Expand Down
5 changes: 4 additions & 1 deletion thirdparty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ Files extracted from upstream source:
## bullet

- Upstream: https://github.com/bulletphysics/bullet3
- Version: 2.89
- Version: 2.90 (master cd8cf7521cbb8b7808126a6adebd47bb83ea166a)
- License: zlib

Important: Synced with a pre-release version of bullet 2.90 from the master branch.
Commit hash: cd8cf7521cbb8b7808126a6adebd47bb83ea166a

Files extracted from upstream source:

- src/* apart from CMakeLists.txt and premake4.lua files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ struct btDbvntNode

btDbvntNode(const btDbvtNode* n)
: volume(n->volume)
, angle(0)
, normal(0,0,0)
, angle(0)
, data(n->data)
{
childs[0] = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class btOverlappingPairCache : public btOverlappingPairCallback
virtual void cleanOverlappingPair(btBroadphasePair& pair, btDispatcher* dispatcher) = 0;

virtual int getNumOverlappingPairs() const = 0;

virtual bool needsBroadphaseCollision(btBroadphaseProxy * proxy0, btBroadphaseProxy * proxy1) const = 0;
virtual btOverlapFilterCallback* getOverlapFilterCallback() = 0;
virtual void cleanProxyFromPairs(btBroadphaseProxy* proxy, btDispatcher* dispatcher) = 0;

virtual void setOverlapFilterCallback(btOverlapFilterCallback* callback) = 0;
Expand Down Expand Up @@ -380,6 +381,14 @@ class btNullPairCache : public btOverlappingPairCache
{
}

bool needsBroadphaseCollision(btBroadphaseProxy*, btBroadphaseProxy*) const
{
return true;
}
btOverlapFilterCallback* getOverlapFilterCallback()
{
return 0;
}
virtual void setOverlapFilterCallback(btOverlapFilterCallback* /*callback*/)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ void btQuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCall

#ifdef RAYAABB2
btVector3 rayDir = (rayTarget - raySource);
rayDir.normalize();
rayDir.safeNormalize();// stephengold changed normalize to safeNormalize 2020-02-17
lambda_max = rayDir.dot(rayTarget - raySource);
///what about division by zero? --> just set rayDirection[i] to 1.0
btVector3 rayDirectionInverse;
Expand Down Expand Up @@ -554,7 +554,7 @@ void btQuantizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback*

#ifdef RAYAABB2
btVector3 rayDirection = (rayTarget - raySource);
rayDirection.normalize();
rayDirection.safeNormalize();// stephengold changed normalize to safeNormalize 2020-02-17
lambda_max = rayDirection.dot(rayTarget - raySource);
///what about division by zero? --> just set rayDirection[i] to 1.0
rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class btCollisionDispatcher : public btDispatcher

btAlignedObjectArray<btPersistentManifold*> m_manifoldsPtr;

btManifoldResult m_defaultManifoldResult;

btNearCallback m_nearCallback;

btPoolAllocator* m_collisionAlgorithmPoolAllocator;
Expand Down Expand Up @@ -95,11 +93,15 @@ class btCollisionDispatcher : public btDispatcher

btPersistentManifold* getManifoldByIndexInternal(int index)
{
btAssert(index>=0);
btAssert(index<m_manifoldsPtr.size());
return m_manifoldsPtr[index];
}

const btPersistentManifold* getManifoldByIndexInternal(int index) const
{
btAssert(index>=0);
btAssert(index<m_manifoldsPtr.size());
return m_manifoldsPtr[index];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ subject to the following restrictions:
btCollisionDispatcherMt::btCollisionDispatcherMt(btCollisionConfiguration* config, int grainSize)
: btCollisionDispatcher(config)
{
m_batchManifoldsPtr.resize(btGetTaskScheduler()->getNumThreads());
m_batchUpdating = false;
m_grainSize = grainSize; // iterations per task
}
Expand Down Expand Up @@ -65,6 +66,10 @@ btPersistentManifold* btCollisionDispatcherMt::getNewManifold(const btCollisionO
manifold->m_index1a = m_manifoldsPtr.size();
m_manifoldsPtr.push_back(manifold);
}
else
{
m_batchManifoldsPtr[btGetCurrentThreadIndex()].push_back(manifold);
}

return manifold;
}
Expand Down Expand Up @@ -121,7 +126,7 @@ struct CollisionDispatcherUpdater : public btIParallelForBody

void btCollisionDispatcherMt::dispatchAllCollisionPairs(btOverlappingPairCache* pairCache, const btDispatcherInfo& info, btDispatcher* dispatcher)
{
int pairCount = pairCache->getNumOverlappingPairs();
const int pairCount = pairCache->getNumOverlappingPairs();
if (pairCount == 0)
{
return;
Expand All @@ -136,16 +141,17 @@ void btCollisionDispatcherMt::dispatchAllCollisionPairs(btOverlappingPairCache*
btParallelFor(0, pairCount, m_grainSize, updater);
m_batchUpdating = false;

// reconstruct the manifolds array to ensure determinism
m_manifoldsPtr.resizeNoInitialize(0);

btBroadphasePair* pairs = pairCache->getOverlappingPairArrayPtr();
for (int i = 0; i < pairCount; ++i)
// merge new manifolds, if any
for (int i = 0; i < m_batchManifoldsPtr.size(); ++i)
{
if (btCollisionAlgorithm* algo = pairs[i].m_algorithm)
btAlignedObjectArray<btPersistentManifold*>& batchManifoldsPtr = m_batchManifoldsPtr[i];

for (int j = 0; j < batchManifoldsPtr.size(); ++j)
{
algo->getAllContactManifolds(m_manifoldsPtr);
m_manifoldsPtr.push_back(batchManifoldsPtr[j]);
}

batchManifoldsPtr.resizeNoInitialize(0);
}

// update the indices (used when releasing manifolds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class btCollisionDispatcherMt : public btCollisionDispatcher
virtual void dispatchAllCollisionPairs(btOverlappingPairCache* pairCache, const btDispatcherInfo& info, btDispatcher* dispatcher) BT_OVERRIDE;

protected:
btAlignedObjectArray<btAlignedObjectArray<btPersistentManifold*> > m_batchManifoldsPtr;
bool m_batchUpdating;
int m_grainSize;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ struct btCompoundLeafCallback : btDbvt::ICollide

if (TestAabbAgainstAabb2(aabbMin0, aabbMax0, aabbMin1, aabbMax1))
{
btCollisionObjectWrapper compoundWrap(this->m_compoundColObjWrap, childShape, m_compoundColObjWrap->getCollisionObject(), newChildWorldTrans, childTrans, -1, index);
btTransform preTransform = childTrans;
if (this->m_compoundColObjWrap->m_preTransform)
{
preTransform = preTransform *(*(this->m_compoundColObjWrap->m_preTransform));
}
btCollisionObjectWrapper compoundWrap(this->m_compoundColObjWrap, childShape, m_compoundColObjWrap->getCollisionObject(), newChildWorldTrans, preTransform, -1, index);

btCollisionAlgorithm* algo = 0;
bool allocatedAlgorithm = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct btContactSolverInfoData
btScalar m_sor; //successive over-relaxation term
btScalar m_erp; //error reduction for non-contact constraints
btScalar m_erp2; //error reduction for contact constraints
btScalar m_deformable_erp; //error reduction for deformable constraints
btScalar m_deformable_erp; //error reduction for deformable constraints
btScalar m_globalCfm; //constraint force mixing for contacts and non-contacts
btScalar m_frictionERP; //error reduction for friction constraints
btScalar m_frictionCFM; //constraint force mixing for friction constraints
Expand All @@ -67,6 +67,7 @@ struct btContactSolverInfoData
bool m_jointFeedbackInWorldSpace;
bool m_jointFeedbackInJointFrame;
int m_reportSolverAnalytics;
int m_numNonContactInnerIterations;
};

struct btContactSolverInfo : public btContactSolverInfoData
Expand All @@ -82,7 +83,7 @@ struct btContactSolverInfo : public btContactSolverInfoData
m_numIterations = 10;
m_erp = btScalar(0.2);
m_erp2 = btScalar(0.2);
m_deformable_erp = btScalar(0.);
m_deformable_erp = btScalar(0.1);
m_globalCfm = btScalar(0.);
m_frictionERP = btScalar(0.2); //positional friction 'anchors' are disabled by default
m_frictionCFM = btScalar(0.);
Expand All @@ -104,6 +105,7 @@ struct btContactSolverInfo : public btContactSolverInfoData
m_jointFeedbackInWorldSpace = false;
m_jointFeedbackInJointFrame = false;
m_reportSolverAnalytics = 0;
m_numNonContactInnerIterations = 1; // the number of inner iterations for solving motor constraint in a single iteration of the constraint solve
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,10 @@ int btGeneric6DofSpring2Constraint::get_limit_motor_info2(
// will we not request a velocity with the wrong direction ?
// and the answer is not, because in practice during the solving the current velocity is subtracted from the m_constraintError
// so the sign of the force that is really matters
info->m_constraintError[srow] = (rotational ? -1 : 1) * (f < 0 ? -SIMD_INFINITY : SIMD_INFINITY);
if (m_flags & BT_6DOF_FLAGS_USE_INFINITE_ERROR)
info->m_constraintError[srow] = (rotational ? -1 : 1) * (f < 0 ? -SIMD_INFINITY : SIMD_INFINITY);
else
info->m_constraintError[srow] = vel + f / m * (rotational ? -1 : 1);

btScalar minf = f < fd ? f : fd;
btScalar maxf = f < fd ? fd : f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ enum bt6DofFlags2
BT_6DOF_FLAGS_ERP_STOP2 = 2,
BT_6DOF_FLAGS_CFM_MOTO2 = 4,
BT_6DOF_FLAGS_ERP_MOTO2 = 8,
BT_6DOF_FLAGS_USE_INFINITE_ERROR = (1<<16)
};
#define BT_6DOF_FLAGS_AXIS_SHIFT2 4 // bits per axis

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ subject to the following restrictions:
*/

//#define COMPUTE_IMPULSE_DENOM 1
//#define BT_ADDITIONAL_DEBUG
#ifdef BT_DEBUG
# define BT_ADDITIONAL_DEBUG
#endif

//It is not necessary (redundant) to refresh contact manifolds, this refresh has been moved to the collision algorithms.

Expand Down Expand Up @@ -690,8 +692,10 @@ int btSequentialImpulseConstraintSolver::getOrInitSolverBody(btCollisionObject&
{
#if BT_THREADSAFE
int solverBodyId = -1;
bool isRigidBodyType = btRigidBody::upcast(&body) != NULL;
if (isRigidBodyType && !body.isStaticOrKinematicObject())
const bool isRigidBodyType = btRigidBody::upcast(&body) != NULL;
const bool isStaticOrKinematic = body.isStaticOrKinematicObject();
const bool isKinematic = body.isKinematicObject();
if (isRigidBodyType && !isStaticOrKinematic)
{
// dynamic body
// Dynamic bodies can only be in one island, so it's safe to write to the companionId
Expand All @@ -704,7 +708,7 @@ int btSequentialImpulseConstraintSolver::getOrInitSolverBody(btCollisionObject&
body.setCompanionId(solverBodyId);
}
}
else if (isRigidBodyType && body.isKinematicObject())
else if (isRigidBodyType && isKinematic)
{
//
// NOTE: must test for kinematic before static because some kinematic objects also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,14 @@ class btClosestNotMeConvexResultCallback : public btCollisionWorld::ClosestConve
///don't do CCD when the collision filters are not matching
if (!ClosestConvexResultCallback::needsCollision(proxy0))
return false;
if (m_pairCache->getOverlapFilterCallback()) {
btBroadphaseProxy* proxy1 = m_me->getBroadphaseHandle();
bool collides = m_pairCache->needsBroadphaseCollision(proxy0, proxy1);
if (!collides)
{
return false;
}
}

btCollisionObject* otherObj = (btCollisionObject*)proxy0->m_clientObject;

Expand Down
19 changes: 13 additions & 6 deletions thirdparty/bullet/BulletDynamics/Dynamics/btRigidBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,13 @@ void btRigidBody::setGravity(const btVector3& acceleration)

void btRigidBody::setDamping(btScalar lin_damping, btScalar ang_damping)
{
m_linearDamping = btClamped(lin_damping, (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
m_angularDamping = btClamped(ang_damping, (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
#ifdef BT_USE_OLD_DAMPING_METHOD
m_linearDamping = btMax(lin_damping, btScalar(0.0));
m_angularDamping = btMax(ang_damping, btScalar(0.0));
#else
m_linearDamping = btClamped(lin_damping, btScalar(0.0), btScalar(1.0));
m_angularDamping = btClamped(ang_damping, btScalar(0.0), btScalar(1.0));
#endif
}

///applyDamping damps the velocity, using the given m_linearDamping and m_angularDamping
Expand All @@ -146,10 +151,9 @@ void btRigidBody::applyDamping(btScalar timeStep)
//On new damping: see discussion/issue report here: http://code.google.com/p/bullet/issues/detail?id=74
//todo: do some performance comparisons (but other parts of the engine are probably bottleneck anyway

//#define USE_OLD_DAMPING_METHOD 1
#ifdef USE_OLD_DAMPING_METHOD
m_linearVelocity *= GEN_clamped((btScalar(1.) - timeStep * m_linearDamping), (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
m_angularVelocity *= GEN_clamped((btScalar(1.) - timeStep * m_angularDamping), (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
#ifdef BT_USE_OLD_DAMPING_METHOD
m_linearVelocity *= btMax((btScalar(1.0) - timeStep * m_linearDamping), btScalar(0.0));
m_angularVelocity *= btMax((btScalar(1.0) - timeStep * m_angularDamping), btScalar(0.0));
#else
m_linearVelocity *= btPow(btScalar(1) - m_linearDamping, timeStep);
m_angularVelocity *= btPow(btScalar(1) - m_angularDamping, timeStep);
Expand Down Expand Up @@ -380,6 +384,9 @@ void btRigidBody::integrateVelocities(btScalar step)
{
m_angularVelocity *= (MAX_ANGVEL / step) / angvel;
}
#if defined(BT_CLAMP_VELOCITY_TO) && BT_CLAMP_VELOCITY_TO > 0
clampVelocity(m_angularVelocity);
#endif
}

btQuaternion btRigidBody::getOrientation() const
Expand Down
Loading

0 comments on commit f7e2ff5

Please sign in to comment.