From b958e8a2368e52feead25a8a59572dd14f14c3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Mon, 22 May 2023 15:10:36 +0200 Subject: [PATCH] bullet: Sync with upstream 3.25 Remove upstreamed patch. --- thirdparty/README.md | 4 +- .../btConvexConcaveCollisionAlgorithm.cpp | 5 +- .../BulletCollision/Gimpact/btBoxCollision.h | 12 ++ .../NarrowPhaseCollision/btManifoldPoint.h | 8 +- .../MLCPSolvers/btLemkeAlgorithm.cpp | 146 ++++++++++-------- .../MLCPSolvers/btLemkeAlgorithm.h | 3 +- .../bullet/BulletSoftBody/btSoftBody.cpp | 15 +- thirdparty/bullet/LinearMath/btConvexHull.cpp | 4 +- thirdparty/bullet/LinearMath/btScalar.h | 2 +- thirdparty/bullet/LinearMath/btSerializer.h | 4 +- thirdparty/bullet/VERSION.txt | 2 +- .../patches/fix-unused-but-set-warning.patch | 17 -- 12 files changed, 125 insertions(+), 97 deletions(-) delete mode 100644 thirdparty/bullet/patches/fix-unused-but-set-warning.patch diff --git a/thirdparty/README.md b/thirdparty/README.md index 5c1e2810d45..a0a9c267772 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -20,7 +20,7 @@ Files extracted from upstream source: ## bullet - Upstream: https://github.com/bulletphysics/bullet3 -- Version: 3.24 (7dee3436e747958e7088dfdcea0e4ae031ce619e, 2022) +- Version: 3.25 (2c204c49e56ed15ec5fcfa71d199ab6d6570b3f5, 2022) - License: zlib Files extracted from upstream source: @@ -29,8 +29,6 @@ Files extracted from upstream source: and CMakeLists.txt and premake4.lua files - `LICENSE.txt`, and `VERSION` as `VERSION.txt` -Includes some patches in the `patches` folder which have been sent upstream. - ## certs diff --git a/thirdparty/bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp b/thirdparty/bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp index 8d59ba95ae5..95bce9e7c0f 100644 --- a/thirdparty/bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp +++ b/thirdparty/bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp @@ -103,7 +103,8 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle, int partId, if (m_convexBodyWrap->getCollisionShape()->isConvex()) { -#ifndef BT_DISABLE_CONVEX_CONCAVE_EARLY_OUT +#ifdef BT_ENABLE_CONVEX_CONCAVE_EARLY_OUT + //todo: check this issue https://github.com/bulletphysics/bullet3/issues/4263 //an early out optimisation if the object is separated from the triangle //projected on the triangle normal) { @@ -139,7 +140,7 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle, int partId, if (dist > contact_threshold) return; } -#endif //BT_DISABLE_CONVEX_CONCAVE_EARLY_OUT +#endif //BT_ENABLE_CONVEX_CONCAVE_EARLY_OUT btTriangleShape tm(triangle[0], triangle[1], triangle[2]); tm.setMargin(m_collisionMarginTriangle); diff --git a/thirdparty/bullet/BulletCollision/Gimpact/btBoxCollision.h b/thirdparty/bullet/BulletCollision/Gimpact/btBoxCollision.h index 182835c3b44..941dcc63ae8 100644 --- a/thirdparty/bullet/BulletCollision/Gimpact/btBoxCollision.h +++ b/thirdparty/bullet/BulletCollision/Gimpact/btBoxCollision.h @@ -229,10 +229,12 @@ public: m_min[0] = BT_MIN3(V1[0], V2[0], V3[0]); m_min[1] = BT_MIN3(V1[1], V2[1], V3[1]); m_min[2] = BT_MIN3(V1[2], V2[2], V3[2]); + m_min[3] = 0.f; m_max[0] = BT_MAX3(V1[0], V2[0], V3[0]); m_max[1] = BT_MAX3(V1[1], V2[1], V3[1]); m_max[2] = BT_MAX3(V1[2], V2[2], V3[2]); + m_max[3] = 0.f; } btAABB(const btVector3 &V1, @@ -243,10 +245,12 @@ public: m_min[0] = BT_MIN3(V1[0], V2[0], V3[0]); m_min[1] = BT_MIN3(V1[1], V2[1], V3[1]); m_min[2] = BT_MIN3(V1[2], V2[2], V3[2]); + m_min[3] = 0.f; m_max[0] = BT_MAX3(V1[0], V2[0], V3[0]); m_max[1] = BT_MAX3(V1[1], V2[1], V3[1]); m_max[2] = BT_MAX3(V1[2], V2[2], V3[2]); + m_max[3] = 0.f; m_min[0] -= margin; m_min[1] -= margin; @@ -275,9 +279,11 @@ public: m_min[0] = SIMD_INFINITY; m_min[1] = SIMD_INFINITY; m_min[2] = SIMD_INFINITY; + m_min[3] = 0.f; m_max[0] = -SIMD_INFINITY; m_max[1] = -SIMD_INFINITY; m_max[2] = -SIMD_INFINITY; + m_max[3] = 0.f; } SIMD_FORCE_INLINE void increment_margin(btScalar margin) @@ -295,10 +301,12 @@ public: m_min[0] = other.m_min[0] - margin; m_min[1] = other.m_min[1] - margin; m_min[2] = other.m_min[2] - margin; + m_min[3] = 0.f; m_max[0] = other.m_max[0] + margin; m_max[1] = other.m_max[1] + margin; m_max[2] = other.m_max[2] + margin; + m_max[3] = 0.f; } template @@ -310,10 +318,12 @@ public: m_min[0] = BT_MIN3(V1[0], V2[0], V3[0]); m_min[1] = BT_MIN3(V1[1], V2[1], V3[1]); m_min[2] = BT_MIN3(V1[2], V2[2], V3[2]); + m_min[3] = 0.f; m_max[0] = BT_MAX3(V1[0], V2[0], V3[0]); m_max[1] = BT_MAX3(V1[1], V2[1], V3[1]); m_max[2] = BT_MAX3(V1[2], V2[2], V3[2]); + m_max[3] = 0.f; } template @@ -325,10 +335,12 @@ public: m_min[0] = BT_MIN3(V1[0], V2[0], V3[0]); m_min[1] = BT_MIN3(V1[1], V2[1], V3[1]); m_min[2] = BT_MIN3(V1[2], V2[2], V3[2]); + m_min[3] = 0.f; m_max[0] = BT_MAX3(V1[0], V2[0], V3[0]); m_max[1] = BT_MAX3(V1[1], V2[1], V3[1]); m_max[2] = BT_MAX3(V1[2], V2[2], V3[2]); + m_max[3] = 0.f; m_min[0] -= margin; m_min[1] -= margin; diff --git a/thirdparty/bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h b/thirdparty/bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h index 8cc373db2ec..31323282cd0 100644 --- a/thirdparty/bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h +++ b/thirdparty/bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h @@ -71,8 +71,8 @@ public: const btVector3& normal, btScalar distance) : m_localPointA(pointA), m_localPointB(pointB), - m_positionWorldOnB(0,0,0), - m_positionWorldOnA(0,0,0), + m_positionWorldOnB(0,0,0), + m_positionWorldOnA(0,0,0), m_normalWorldOnB(normal), m_distance1(distance), m_combinedFriction(btScalar(0.)), @@ -95,8 +95,8 @@ public: m_contactERP(0.f), m_frictionCFM(0.f), m_lifeTime(0), - m_lateralFrictionDir1(0,0,0), - m_lateralFrictionDir2(0,0,0) + m_lateralFrictionDir1(0,0,0), + m_lateralFrictionDir2(0,0,0) { } diff --git a/thirdparty/bullet/BulletDynamics/MLCPSolvers/btLemkeAlgorithm.cpp b/thirdparty/bullet/BulletDynamics/MLCPSolvers/btLemkeAlgorithm.cpp index 954ffaed759..1007d04e341 100644 --- a/thirdparty/bullet/BulletDynamics/MLCPSolvers/btLemkeAlgorithm.cpp +++ b/thirdparty/bullet/BulletDynamics/MLCPSolvers/btLemkeAlgorithm.cpp @@ -169,9 +169,12 @@ btVectorXu btLemkeAlgorithm::solve(unsigned int maxloops /* = 0*/) /*the column becomes part of the basis*/ basis[pivotRowIndex] = pivotColIndexOld; - - pivotRowIndex = findLexicographicMinimum(A, pivotColIndex); - + bool isRayTermination = false; + pivotRowIndex = findLexicographicMinimum(A, pivotColIndex, z0Row, isRayTermination); + if (isRayTermination) + { + break; // ray termination + } if (z0Row == pivotRowIndex) { //if z0 leaves the basis the solution is found --> one last elimination step is necessary GaussJordanEliminationStep(A, pivotRowIndex, pivotColIndex, basis); @@ -217,79 +220,100 @@ btVectorXu btLemkeAlgorithm::solve(unsigned int maxloops /* = 0*/) return solutionVector; } -int btLemkeAlgorithm::findLexicographicMinimum(const btMatrixXu& A, const int& pivotColIndex) +int btLemkeAlgorithm::findLexicographicMinimum(const btMatrixXu& A, const int& pivotColIndex, const int& z0Row, bool& isRayTermination) { - int RowIndex = 0; + isRayTermination = false; + btAlignedObjectArray activeRows; + + bool firstRow = true; + btScalar currentMin = 0.0; + int dim = A.rows(); - btAlignedObjectArray Rows; + for (int row = 0; row < dim; row++) { - btVectorXu vec(dim + 1); - vec.setZero(); //, INIT, 0.) - Rows.push_back(vec); - btScalar a = A(row, pivotColIndex); - if (a > 0) - { - Rows[row][0] = A(row, 2 * dim + 1) / a; - Rows[row][1] = A(row, 2 * dim) / a; - for (int j = 2; j < dim + 1; j++) - Rows[row][j] = A(row, j - 1) / a; + const btScalar denom = A(row, pivotColIndex); -#ifdef BT_DEBUG_OSTREAM - // if (DEBUGLEVEL) { - // cout << "Rows(" << row << ") = " << Rows[row] << endl; - // } -#endif + if (denom > btMachEps()) + { + const btScalar q = A(row, dim + dim + 1) / denom; + if (firstRow) + { + currentMin = q; + activeRows.push_back(row); + firstRow = false; + } + else if (fabs(currentMin - q) < btMachEps()) + { + activeRows.push_back(row); + } + else if (currentMin > q) + { + currentMin = q; + activeRows.clear(); + activeRows.push_back(row); + } } } - for (int i = 0; i < Rows.size(); i++) + if (activeRows.size() == 0) { - if (Rows[i].nrm2() > 0.) + isRayTermination = true; + return 0; + } + else if (activeRows.size() == 1) + { + return activeRows[0]; + } + + // if there are multiple rows, check if they contain the row for z_0. + for (int i = 0; i < activeRows.size(); i++) + { + if (activeRows[i] == z0Row) { - int j = 0; - for (; j < Rows.size(); j++) - { - if (i != j) - { - if (Rows[j].nrm2() > 0.) - { - btVectorXu test(dim + 1); - for (int ii = 0; ii < dim + 1; ii++) - { - test[ii] = Rows[j][ii] - Rows[i][ii]; - } - - //=Rows[j] - Rows[i] - if (!LexicographicPositive(test)) - break; - } - } - } - - if (j == Rows.size()) - { - RowIndex += i; - break; - } + return z0Row; } } - return RowIndex; -} + // look through the columns of the inverse of the basic matrix from left to right until the tie is broken. + for (int col = 0; col < dim ; col++) + { + btAlignedObjectArray activeRowsCopy(activeRows); + activeRows.clear(); + firstRow = true; + for (int i = 0; i ratio) + { + currentMin = ratio; + activeRows.clear(); + activeRows.push_back(row); + } + } - while (i < v.size() - 1 && fabs(v[i]) < btMachEps()) - i++; - if (v[i] > 0) - return true; - - return false; + if (activeRows.size() == 1) + { + return activeRows[0]; + } + } + // must not reach here. + isRayTermination = true; + return 0; } void btLemkeAlgorithm::GaussJordanEliminationStep(btMatrixXu& A, int pivotRowIndex, int pivotColumnIndex, const btAlignedObjectArray& basis) diff --git a/thirdparty/bullet/BulletDynamics/MLCPSolvers/btLemkeAlgorithm.h b/thirdparty/bullet/BulletDynamics/MLCPSolvers/btLemkeAlgorithm.h index 3c6bf72a233..6c498dd0a88 100644 --- a/thirdparty/bullet/BulletDynamics/MLCPSolvers/btLemkeAlgorithm.h +++ b/thirdparty/bullet/BulletDynamics/MLCPSolvers/btLemkeAlgorithm.h @@ -71,8 +71,7 @@ public: } protected: - int findLexicographicMinimum(const btMatrixXu& A, const int& pivotColIndex); - bool LexicographicPositive(const btVectorXu& v); + int findLexicographicMinimum(const btMatrixXu& A, const int& pivotColIndex, const int& z0Row, bool& isRayTermination); void GaussJordanEliminationStep(btMatrixXu& A, int pivotRowIndex, int pivotColumnIndex, const btAlignedObjectArray& basis); bool greaterZero(const btVectorXu& vector); bool validBasis(const btAlignedObjectArray& basis); diff --git a/thirdparty/bullet/BulletSoftBody/btSoftBody.cpp b/thirdparty/bullet/BulletSoftBody/btSoftBody.cpp index e91c1b9a4aa..c873099b499 100644 --- a/thirdparty/bullet/BulletSoftBody/btSoftBody.cpp +++ b/thirdparty/bullet/BulletSoftBody/btSoftBody.cpp @@ -2807,7 +2807,7 @@ bool btSoftBody::checkDeformableContact(const btCollisionObjectWrapper* colObjWr // // Compute barycentric coordinates (u, v, w) for // point p with respect to triangle (a, b, c) -static void getBarycentric(const btVector3& p, btVector3& a, btVector3& b, btVector3& c, btVector3& bary) +static void getBarycentric(const btVector3& p, const btVector3& a, const btVector3& b, const btVector3& c, btVector3& bary) { btVector3 v0 = b - a, v1 = c - a, v2 = p - a; btScalar d00 = v0.dot(v0); @@ -2816,8 +2816,17 @@ static void getBarycentric(const btVector3& p, btVector3& a, btVector3& b, btVec btScalar d20 = v2.dot(v0); btScalar d21 = v2.dot(v1); btScalar denom = d00 * d11 - d01 * d01; - bary.setY((d11 * d20 - d01 * d21) / denom); - bary.setZ((d00 * d21 - d01 * d20) / denom); + // In the case of a degenerate triangle, pick a vertex. + if (btFabs(denom) < SIMD_EPSILON) + { + bary.setY(btScalar(0.0)); + bary.setZ(btScalar(0.0)); + } + else + { + bary.setY((d11 * d20 - d01 * d21) / denom); + bary.setZ((d00 * d21 - d01 * d20) / denom); + } bary.setX(btScalar(1) - bary.getY() - bary.getZ()); } diff --git a/thirdparty/bullet/LinearMath/btConvexHull.cpp b/thirdparty/bullet/LinearMath/btConvexHull.cpp index e7de2a3694c..94b68baf54f 100644 --- a/thirdparty/bullet/LinearMath/btConvexHull.cpp +++ b/thirdparty/bullet/LinearMath/btConvexHull.cpp @@ -678,7 +678,9 @@ HullError HullLibrary::CreateConvexHull(const HullDesc &desc, // describes the if (vcount < 8) vcount = 8; btAlignedObjectArray vertexSource; - vertexSource.resize(static_cast(vcount)); + btVector3 zero; + zero.setZero(); + vertexSource.resize(static_cast(vcount), zero); btVector3 scale; diff --git a/thirdparty/bullet/LinearMath/btScalar.h b/thirdparty/bullet/LinearMath/btScalar.h index 9f5408c792f..dea1b05ea48 100644 --- a/thirdparty/bullet/LinearMath/btScalar.h +++ b/thirdparty/bullet/LinearMath/btScalar.h @@ -25,7 +25,7 @@ subject to the following restrictions: #include /* SVN $Revision$ on $Date$ from http://bullet.googlecode.com*/ -#define BT_BULLET_VERSION 324 +#define BT_BULLET_VERSION 325 inline int btGetVersion() { diff --git a/thirdparty/bullet/LinearMath/btSerializer.h b/thirdparty/bullet/LinearMath/btSerializer.h index 59695ab3263..86709566b53 100644 --- a/thirdparty/bullet/LinearMath/btSerializer.h +++ b/thirdparty/bullet/LinearMath/btSerializer.h @@ -481,7 +481,7 @@ public: buffer[9] = '3'; buffer[10] = '2'; - buffer[11] = '4'; + buffer[11] = '5'; } virtual void startSerialization() @@ -512,7 +512,7 @@ public: currentPtr += BT_HEADER_LENGTH; for (int i = 0; i < m_chunkPtrs.size(); i++) { - int curLength = sizeof(btChunk) + m_chunkPtrs[i]->m_length; + int curLength = (int)sizeof(btChunk) + m_chunkPtrs[i]->m_length; memcpy(currentPtr, m_chunkPtrs[i], curLength); btAlignedFree(m_chunkPtrs[i]); currentPtr += curLength; diff --git a/thirdparty/bullet/VERSION.txt b/thirdparty/bullet/VERSION.txt index bd23423169f..ed5e66e1dbe 100644 --- a/thirdparty/bullet/VERSION.txt +++ b/thirdparty/bullet/VERSION.txt @@ -1 +1 @@ -3.24 +3.25 diff --git a/thirdparty/bullet/patches/fix-unused-but-set-warning.patch b/thirdparty/bullet/patches/fix-unused-but-set-warning.patch deleted file mode 100644 index b0b38676f33..00000000000 --- a/thirdparty/bullet/patches/fix-unused-but-set-warning.patch +++ /dev/null @@ -1,17 +0,0 @@ -diff --git a/thirdparty/bullet/BulletSoftBody/btSparseSDF.h b/thirdparty/bullet/BulletSoftBody/btSparseSDF.h -index ae1288d9e6..243b80f8ae 100644 ---- a/thirdparty/bullet/BulletSoftBody/btSparseSDF.h -+++ b/thirdparty/bullet/BulletSoftBody/btSparseSDF.h -@@ -233,9 +233,9 @@ struct btSparseSdf - //int sz = sizeof(Cell); - if (ncells > m_clampCells) - { -- static int numResets = 0; -- numResets++; -- // printf("numResets=%d\n",numResets); -+ //static int numResets = 0; -+ //numResets++; -+ //printf("numResets=%d\n",numResets); - Reset(); - } -