bullet: Sync with upstream 3.17

Stop include Bullet headers using `-isystem` for GCC/Clang as it misleads
SCons into not properly rebuilding all files when headers change.

This means we also need to make sure Bullet builds without warning, and
current version fares fairly well, there were just a couple to fix (patch
included).

Increase minimum version for distro packages to 2.90 (this was never released
as the "next" version after 2.89 was 3.05... but that covers it too).

Fixes #43868.

(cherry picked from commit b7901c773c)
This commit is contained in:
Rémi Verschelde 2021-09-29 15:47:08 +02:00
parent 4a9a231566
commit 71f8b809b2
No known key found for this signature in database
GPG key ID: C3336907360768E1
24 changed files with 326 additions and 79 deletions

View file

@ -10,7 +10,7 @@ env_bullet = env_modules.Clone()
thirdparty_obj = [] thirdparty_obj = []
if env["builtin_bullet"]: if env["builtin_bullet"]:
# Build only version 2 for now (as of 2.89) # Build only "Bullet2" API (not "Bullet3" folders).
# Sync file list with relevant upstream CMakeLists.txt for each folder. # Sync file list with relevant upstream CMakeLists.txt for each folder.
if env["float"] == "64": if env["float"] == "64":
env.Append(CPPDEFINES=["BT_USE_DOUBLE_PRECISION=1"]) env.Append(CPPDEFINES=["BT_USE_DOUBLE_PRECISION=1"])
@ -189,6 +189,7 @@ if env["builtin_bullet"]:
"LinearMath/btGeometryUtil.cpp", "LinearMath/btGeometryUtil.cpp",
"LinearMath/btPolarDecomposition.cpp", "LinearMath/btPolarDecomposition.cpp",
"LinearMath/btQuickprof.cpp", "LinearMath/btQuickprof.cpp",
"LinearMath/btReducedVector.cpp",
"LinearMath/btSerializer.cpp", "LinearMath/btSerializer.cpp",
"LinearMath/btSerializer64.cpp", "LinearMath/btSerializer64.cpp",
"LinearMath/btThreads.cpp", "LinearMath/btThreads.cpp",
@ -200,11 +201,7 @@ if env["builtin_bullet"]:
thirdparty_sources = [thirdparty_dir + file for file in bullet2_src] thirdparty_sources = [thirdparty_dir + file for file in bullet2_src]
# Treat Bullet headers as system headers to avoid raising warnings. Not supported on MSVC. env_bullet.Prepend(CPPPATH=[thirdparty_dir])
if not env.msvc:
env_bullet.Append(CPPFLAGS=["-isystem", Dir(thirdparty_dir).path])
else:
env_bullet.Prepend(CPPPATH=[thirdparty_dir])
if env["target"] == "debug" or env["target"] == "release_debug": if env["target"] == "debug" or env["target"] == "release_debug":
env_bullet.Append(CPPDEFINES=["DEBUG"]) env_bullet.Append(CPPDEFINES=["DEBUG"])

View file

@ -20,13 +20,15 @@ Files extracted from upstream source:
## bullet ## bullet
- Upstream: https://github.com/bulletphysics/bullet3 - Upstream: https://github.com/bulletphysics/bullet3
- Version: 3.08 (df09fd9ed37e365ceae884ca7f620b61607dae2e, 2020) - Version: 3.17 (ebe1916b90acae8b13cd8c6b637d8327cdc64e94, 2021)
- License: zlib - License: zlib
Files extracted from upstream source: Files extracted from upstream source:
- src/* apart from CMakeLists.txt and premake4.lua files - `src/*` apart from CMakeLists.txt and premake4.lua files
- LICENSE.txt - `LICENSE.txt`, and `VERSION` as `VERSION.txt`
Includes a warning fix which should be upstreamed soon (see patch in `patches`).
## certs ## certs

View file

@ -80,6 +80,7 @@ struct ClipVertex
btVector3 v; btVector3 v;
int id; int id;
//b2ContactID id; //b2ContactID id;
//b2ContactID id;
}; };
#define b2Dot(a, b) (a).dot(b) #define b2Dot(a, b) (a).dot(b)

View file

@ -24,6 +24,7 @@ subject to the following restrictions:
#define WANTS_DEACTIVATION 3 #define WANTS_DEACTIVATION 3
#define DISABLE_DEACTIVATION 4 #define DISABLE_DEACTIVATION 4
#define DISABLE_SIMULATION 5 #define DISABLE_SIMULATION 5
#define FIXED_BASE_MULTI_BODY 6
struct btBroadphaseProxy; struct btBroadphaseProxy;
class btCollisionShape; class btCollisionShape;
@ -304,7 +305,7 @@ public:
SIMD_FORCE_INLINE bool isActive() const SIMD_FORCE_INLINE bool isActive() const
{ {
return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION)); return ((getActivationState() != FIXED_BASE_MULTI_BODY) && (getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
} }
void setRestitution(btScalar rest) void setRestitution(btScalar rest)

View file

@ -1037,7 +1037,7 @@ struct btSingleSweepCallback : public btBroadphaseRayCallback
m_castShape(castShape) m_castShape(castShape)
{ {
btVector3 unnormalizedRayDir = (m_convexToTrans.getOrigin() - m_convexFromTrans.getOrigin()); btVector3 unnormalizedRayDir = (m_convexToTrans.getOrigin() - m_convexFromTrans.getOrigin());
btVector3 rayDir = unnormalizedRayDir.normalized(); btVector3 rayDir = unnormalizedRayDir.fuzzyZero() ? btVector3(btScalar(0.0), btScalar(0.0), btScalar(0.0)) : unnormalizedRayDir.normalized();
///what about division by zero? --> just set rayDirection[i] to INF/BT_LARGE_FLOAT ///what about division by zero? --> just set rayDirection[i] to INF/BT_LARGE_FLOAT
m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0]; m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0];
m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1]; m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1];
@ -1294,9 +1294,7 @@ public:
btVector3 normalColor(1, 1, 0); btVector3 normalColor(1, 1, 0);
m_debugDrawer->drawLine(center, center + normal, normalColor); m_debugDrawer->drawLine(center, center + normal, normalColor);
} }
m_debugDrawer->drawLine(wv0, wv1, m_color); m_debugDrawer->drawTriangle(wv0, wv1, wv2, m_color, 1.0);
m_debugDrawer->drawLine(wv1, wv2, m_color);
m_debugDrawer->drawLine(wv2, wv0, m_color);
} }
}; };

View file

@ -17,6 +17,47 @@ subject to the following restrictions:
#include "LinearMath/btTransformUtil.h" #include "LinearMath/btTransformUtil.h"
btHeightfieldTerrainShape::btHeightfieldTerrainShape(
int heightStickWidth, int heightStickLength,
const float* heightfieldData, btScalar minHeight, btScalar maxHeight,
int upAxis, bool flipQuadEdges)
: m_userValue3(0), m_triangleInfoMap(0)
{
initialize(heightStickWidth, heightStickLength, heightfieldData,
/*heightScale=*/1, minHeight, maxHeight, upAxis, PHY_FLOAT,
flipQuadEdges);
}
btHeightfieldTerrainShape::btHeightfieldTerrainShape(
int heightStickWidth, int heightStickLength, const double* heightfieldData,
btScalar minHeight, btScalar maxHeight, int upAxis, bool flipQuadEdges)
: m_userValue3(0), m_triangleInfoMap(0)
{
initialize(heightStickWidth, heightStickLength, heightfieldData,
/*heightScale=*/1, minHeight, maxHeight, upAxis, PHY_DOUBLE,
flipQuadEdges);
}
btHeightfieldTerrainShape::btHeightfieldTerrainShape(
int heightStickWidth, int heightStickLength, const short* heightfieldData, btScalar heightScale,
btScalar minHeight, btScalar maxHeight, int upAxis, bool flipQuadEdges)
: m_userValue3(0), m_triangleInfoMap(0)
{
initialize(heightStickWidth, heightStickLength, heightfieldData,
heightScale, minHeight, maxHeight, upAxis, PHY_SHORT,
flipQuadEdges);
}
btHeightfieldTerrainShape::btHeightfieldTerrainShape(
int heightStickWidth, int heightStickLength, const unsigned char* heightfieldData, btScalar heightScale,
btScalar minHeight, btScalar maxHeight, int upAxis, bool flipQuadEdges)
: m_userValue3(0), m_triangleInfoMap(0)
{
initialize(heightStickWidth, heightStickLength, heightfieldData,
heightScale, minHeight, maxHeight, upAxis, PHY_UCHAR,
flipQuadEdges);
}
btHeightfieldTerrainShape::btHeightfieldTerrainShape( btHeightfieldTerrainShape::btHeightfieldTerrainShape(
int heightStickWidth, int heightStickLength, const void* heightfieldData, int heightStickWidth, int heightStickLength, const void* heightfieldData,
btScalar heightScale, btScalar minHeight, btScalar maxHeight, int upAxis, btScalar heightScale, btScalar minHeight, btScalar maxHeight, int upAxis,
@ -24,6 +65,10 @@ btHeightfieldTerrainShape::btHeightfieldTerrainShape(
:m_userValue3(0), :m_userValue3(0),
m_triangleInfoMap(0) m_triangleInfoMap(0)
{ {
// legacy constructor: Assumes PHY_FLOAT means btScalar.
#ifdef BT_USE_DOUBLE_PRECISION
if (hdt == PHY_FLOAT) hdt = PHY_DOUBLE;
#endif
initialize(heightStickWidth, heightStickLength, heightfieldData, initialize(heightStickWidth, heightStickLength, heightfieldData,
heightScale, minHeight, maxHeight, upAxis, hdt, heightScale, minHeight, maxHeight, upAxis, hdt,
flipQuadEdges); flipQuadEdges);
@ -33,9 +78,12 @@ btHeightfieldTerrainShape::btHeightfieldTerrainShape(int heightStickWidth, int h
: m_userValue3(0), : m_userValue3(0),
m_triangleInfoMap(0) m_triangleInfoMap(0)
{ {
// legacy constructor: support only float or unsigned char, // legacy constructor: support only btScalar or unsigned char data,
// and min height is zero // and min height is zero.
PHY_ScalarType hdt = (useFloatData) ? PHY_FLOAT : PHY_UCHAR; PHY_ScalarType hdt = (useFloatData) ? PHY_FLOAT : PHY_UCHAR;
#ifdef BT_USE_DOUBLE_PRECISION
if (hdt == PHY_FLOAT) hdt = PHY_DOUBLE;
#endif
btScalar minHeight = 0.0f; btScalar minHeight = 0.0f;
// previously, height = uchar * maxHeight / 65535. // previously, height = uchar * maxHeight / 65535.
@ -59,7 +107,7 @@ void btHeightfieldTerrainShape::initialize(
// btAssert(heightScale) -- do we care? Trust caller here // btAssert(heightScale) -- do we care? Trust caller here
btAssert(minHeight <= maxHeight); // && "bad min/max height"); btAssert(minHeight <= maxHeight); // && "bad min/max height");
btAssert(upAxis >= 0 && upAxis < 3); // && "bad upAxis--should be in range [0,2]"); btAssert(upAxis >= 0 && upAxis < 3); // && "bad upAxis--should be in range [0,2]");
btAssert(hdt != PHY_UCHAR || hdt != PHY_FLOAT || hdt != PHY_SHORT); // && "Bad height data type enum"); btAssert(hdt != PHY_UCHAR || hdt != PHY_FLOAT || hdt != PHY_DOUBLE || hdt != PHY_SHORT); // && "Bad height data type enum");
// initialize member variables // initialize member variables
m_shapeType = TERRAIN_SHAPE_PROXYTYPE; m_shapeType = TERRAIN_SHAPE_PROXYTYPE;
@ -152,6 +200,12 @@ btHeightfieldTerrainShape::getRawHeightFieldValue(int x, int y) const
break; break;
} }
case PHY_DOUBLE:
{
val = m_heightfieldDataDouble[(y * m_heightStickWidth) + x];
break;
}
case PHY_UCHAR: case PHY_UCHAR:
{ {
unsigned char heightFieldValue = m_heightfieldDataUnsignedChar[(y * m_heightStickWidth) + x]; unsigned char heightFieldValue = m_heightfieldDataUnsignedChar[(y * m_heightStickWidth) + x];
@ -232,6 +286,30 @@ getQuantized(
return (int)(x + 0.5); return (int)(x + 0.5);
} }
// Equivalent to std::minmax({a, b, c}).
// Performs at most 3 comparisons.
static btHeightfieldTerrainShape::Range minmaxRange(btScalar a, btScalar b, btScalar c)
{
if (a > b)
{
if (b > c)
return btHeightfieldTerrainShape::Range(c, a);
else if (a > c)
return btHeightfieldTerrainShape::Range(b, a);
else
return btHeightfieldTerrainShape::Range(b, c);
}
else
{
if (a > c)
return btHeightfieldTerrainShape::Range(c, b);
else if (b > c)
return btHeightfieldTerrainShape::Range(a, b);
else
return btHeightfieldTerrainShape::Range(a, c);
}
}
/// given input vector, return quantized version /// given input vector, return quantized version
/** /**
This routine is basically determining the gridpoint indices for a given This routine is basically determining the gridpoint indices for a given
@ -334,7 +412,8 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
} }
// TODO If m_vboundsGrid is available, use it to determine if we really need to process this area // TODO If m_vboundsGrid is available, use it to determine if we really need to process this area
const Range aabbUpRange(aabbMin[m_upAxis], aabbMax[m_upAxis]);
for (int j = startJ; j < endJ; j++) for (int j = startJ; j < endJ; j++)
{ {
for (int x = startX; x < endX; x++) for (int x = startX; x < endX; x++)
@ -349,29 +428,51 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
if (m_flipQuadEdges || (m_useDiamondSubdivision && !((j + x) & 1)) || (m_useZigzagSubdivision && !(j & 1))) if (m_flipQuadEdges || (m_useDiamondSubdivision && !((j + x) & 1)) || (m_useZigzagSubdivision && !(j & 1)))
{ {
//first triangle
getVertex(x, j, vertices[indices[0]]); getVertex(x, j, vertices[indices[0]]);
getVertex(x, j + 1, vertices[indices[1]]); getVertex(x, j + 1, vertices[indices[1]]);
getVertex(x + 1, j + 1, vertices[indices[2]]); getVertex(x + 1, j + 1, vertices[indices[2]]);
callback->processTriangle(vertices, 2 * x, j);
//second triangle // Skip triangle processing if the triangle is out-of-AABB.
// getVertex(x,j,vertices[0]);//already got this vertex before, thanks to Danny Chapman Range upRange = minmaxRange(vertices[0][m_upAxis], vertices[1][m_upAxis], vertices[2][m_upAxis]);
getVertex(x + 1, j + 1, vertices[indices[1]]);
if (upRange.overlaps(aabbUpRange))
callback->processTriangle(vertices, 2 * x, j);
// already set: getVertex(x, j, vertices[indices[0]])
// equivalent to: getVertex(x + 1, j + 1, vertices[indices[1]]);
vertices[indices[1]] = vertices[indices[2]];
getVertex(x + 1, j, vertices[indices[2]]); getVertex(x + 1, j, vertices[indices[2]]);
callback->processTriangle(vertices, 2 * x+1, j); upRange.min = btMin(upRange.min, vertices[indices[2]][m_upAxis]);
upRange.max = btMax(upRange.max, vertices[indices[2]][m_upAxis]);
if (upRange.overlaps(aabbUpRange))
callback->processTriangle(vertices, 2 * x + 1, j);
} }
else else
{ {
//first triangle
getVertex(x, j, vertices[indices[0]]); getVertex(x, j, vertices[indices[0]]);
getVertex(x, j + 1, vertices[indices[1]]); getVertex(x, j + 1, vertices[indices[1]]);
getVertex(x + 1, j, vertices[indices[2]]); getVertex(x + 1, j, vertices[indices[2]]);
callback->processTriangle(vertices, 2 * x, j);
//second triangle // Skip triangle processing if the triangle is out-of-AABB.
getVertex(x + 1, j, vertices[indices[0]]); Range upRange = minmaxRange(vertices[0][m_upAxis], vertices[1][m_upAxis], vertices[2][m_upAxis]);
//getVertex(x,j+1,vertices[1]);
if (upRange.overlaps(aabbUpRange))
callback->processTriangle(vertices, 2 * x, j);
// already set: getVertex(x, j + 1, vertices[indices[1]]);
// equivalent to: getVertex(x + 1, j, vertices[indices[0]]);
vertices[indices[0]] = vertices[indices[2]];
getVertex(x + 1, j + 1, vertices[indices[2]]); getVertex(x + 1, j + 1, vertices[indices[2]]);
callback->processTriangle(vertices, 2 * x+1, j); upRange.min = btMin(upRange.min, vertices[indices[2]][m_upAxis]);
upRange.max = btMax(upRange.max, vertices[indices[2]][m_upAxis]);
if (upRange.overlaps(aabbUpRange))
callback->processTriangle(vertices, 2 * x + 1, j);
} }
} }
} }
@ -846,4 +947,4 @@ void btHeightfieldTerrainShape::buildAccelerator(int chunkSize)
void btHeightfieldTerrainShape::clearAccelerator() void btHeightfieldTerrainShape::clearAccelerator()
{ {
m_vboundsGrid.clear(); m_vboundsGrid.clear();
} }

View file

@ -50,17 +50,15 @@ subject to the following restrictions:
The heightfield heights are determined from the data type used for the The heightfield heights are determined from the data type used for the
heightfieldData array. heightfieldData array.
- PHY_UCHAR: height at a point is the uchar value at the - unsigned char: height at a point is the uchar value at the
grid point, multipled by heightScale. uchar isn't recommended grid point, multipled by heightScale. uchar isn't recommended
because of its inability to deal with negative values, and because of its inability to deal with negative values, and
low resolution (8-bit). low resolution (8-bit).
- PHY_SHORT: height at a point is the short int value at that grid - short: height at a point is the short int value at that grid
point, multipled by heightScale. point, multipled by heightScale.
- PHY_FLOAT: height at a point is the float value at that grid - float or dobule: height at a point is the value at that grid point.
point. heightScale is ignored when using the float heightfield
data type.
Whatever the caller specifies as minHeight and maxHeight will be honored. Whatever the caller specifies as minHeight and maxHeight will be honored.
The class will not inspect the heightfield to discover the actual minimum The class will not inspect the heightfield to discover the actual minimum
@ -75,6 +73,14 @@ btHeightfieldTerrainShape : public btConcaveShape
public: public:
struct Range struct Range
{ {
Range() {}
Range(btScalar min, btScalar max) : min(min), max(max) {}
bool overlaps(const Range& other) const
{
return !(min > other.max || max < other.min);
}
btScalar min; btScalar min;
btScalar max; btScalar max;
}; };
@ -95,7 +101,8 @@ protected:
union { union {
const unsigned char* m_heightfieldDataUnsignedChar; const unsigned char* m_heightfieldDataUnsignedChar;
const short* m_heightfieldDataShort; const short* m_heightfieldDataShort;
const btScalar* m_heightfieldDataFloat; const float* m_heightfieldDataFloat;
const double* m_heightfieldDataDouble;
const void* m_heightfieldDataUnknown; const void* m_heightfieldDataUnknown;
}; };
@ -135,11 +142,33 @@ protected:
public: public:
BT_DECLARE_ALIGNED_ALLOCATOR(); BT_DECLARE_ALIGNED_ALLOCATOR();
/// preferred constructor /// preferred constructors
btHeightfieldTerrainShape(
int heightStickWidth, int heightStickLength,
const float* heightfieldData, btScalar minHeight, btScalar maxHeight,
int upAxis, bool flipQuadEdges);
btHeightfieldTerrainShape(
int heightStickWidth, int heightStickLength,
const double* heightfieldData, btScalar minHeight, btScalar maxHeight,
int upAxis, bool flipQuadEdges);
btHeightfieldTerrainShape(
int heightStickWidth, int heightStickLength,
const short* heightfieldData, btScalar heightScale, btScalar minHeight, btScalar maxHeight,
int upAxis, bool flipQuadEdges);
btHeightfieldTerrainShape(
int heightStickWidth, int heightStickLength,
const unsigned char* heightfieldData, btScalar heightScale, btScalar minHeight, btScalar maxHeight,
int upAxis, bool flipQuadEdges);
/// legacy constructor
/** /**
This constructor supports a range of heightfield This constructor supports a range of heightfield
data types, and allows for a non-zero minimum height value. data types, and allows for a non-zero minimum height value.
heightScale is needed for any integer-based heightfield data types. heightScale is needed for any integer-based heightfield data types.
This legacy constructor considers `PHY_FLOAT` to mean `btScalar`.
With `BT_USE_DOUBLE_PRECISION`, it will expect `heightfieldData`
to be double-precision.
*/ */
btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength, btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength,
const void* heightfieldData, btScalar heightScale, const void* heightfieldData, btScalar heightScale,
@ -150,7 +179,7 @@ public:
/// legacy constructor /// legacy constructor
/** /**
The legacy constructor assumes the heightfield has a minimum height The legacy constructor assumes the heightfield has a minimum height
of zero. Only unsigned char or floats are supported. For legacy of zero. Only unsigned char or btScalar data are supported. For legacy
compatibility reasons, heightScale is calculated as maxHeight / 65535 compatibility reasons, heightScale is calculated as maxHeight / 65535
(and is only used when useFloatData = false). (and is only used when useFloatData = false).
*/ */
@ -218,4 +247,4 @@ public:
} }
}; };
#endif //BT_HEIGHTFIELD_TERRAIN_SHAPE_H #endif //BT_HEIGHTFIELD_TERRAIN_SHAPE_H

View file

@ -33,8 +33,8 @@
namespace namespace
{ {
const btScalar SLEEP_EPSILON = btScalar(0.05); // this is a squared velocity (m^2 s^-2) const btScalar INITIAL_SLEEP_EPSILON = btScalar(0.05); // this is a squared velocity (m^2 s^-2)
const btScalar SLEEP_TIMEOUT = btScalar(2); // in seconds const btScalar INITIAL_SLEEP_TIMEOUT = btScalar(2); // in seconds
} // namespace } // namespace
void btMultiBody::spatialTransform(const btMatrix3x3 &rotation_matrix, // rotates vectors in 'from' frame to vectors in 'to' frame void btMultiBody::spatialTransform(const btMatrix3x3 &rotation_matrix, // rotates vectors in 'from' frame to vectors in 'to' frame
@ -110,6 +110,9 @@ btMultiBody::btMultiBody(int n_links,
m_canSleep(canSleep), m_canSleep(canSleep),
m_canWakeup(true), m_canWakeup(true),
m_sleepTimer(0), m_sleepTimer(0),
m_sleepEpsilon(INITIAL_SLEEP_EPSILON),
m_sleepTimeout(INITIAL_SLEEP_TIMEOUT),
m_userObjectPointer(0), m_userObjectPointer(0),
m_userIndex2(-1), m_userIndex2(-1),
m_userIndex(-1), m_userIndex(-1),
@ -1411,7 +1414,7 @@ void btMultiBody::solveImatrix(const btSpatialForceVector &rhs, btSpatialMotionV
} }
} }
void btMultiBody::mulMatrix(btScalar *pA, btScalar *pB, int rowsA, int colsA, int rowsB, int colsB, btScalar *pC) const void btMultiBody::mulMatrix(const btScalar *pA, const btScalar *pB, int rowsA, int colsA, int rowsB, int colsB, btScalar *pC) const
{ {
for (int row = 0; row < rowsA; row++) for (int row = 0; row < rowsA; row++)
{ {
@ -2104,10 +2107,10 @@ void btMultiBody::checkMotionAndSleepIfRequired(btScalar timestep)
motion += m_realBuf[i] * m_realBuf[i]; motion += m_realBuf[i] * m_realBuf[i];
} }
if (motion < SLEEP_EPSILON) if (motion < m_sleepEpsilon)
{ {
m_sleepTimer += timestep; m_sleepTimer += timestep;
if (m_sleepTimer > SLEEP_TIMEOUT) if (m_sleepTimer > m_sleepTimeout)
{ {
goToSleep(); goToSleep();
} }

View file

@ -545,7 +545,10 @@ public:
{ {
m_canWakeup = canWakeup; m_canWakeup = canWakeup;
} }
bool isAwake() const { return m_awake; } bool isAwake() const
{
return m_awake;
}
void wakeUp(); void wakeUp();
void goToSleep(); void goToSleep();
void checkMotionAndSleepIfRequired(btScalar timestep); void checkMotionAndSleepIfRequired(btScalar timestep);
@ -726,6 +729,17 @@ public:
bool isLinkAndAllAncestorsKinematic(const int i) const; bool isLinkAndAllAncestorsKinematic(const int i) const;
void setSleepThreshold(btScalar sleepThreshold)
{
m_sleepEpsilon = sleepThreshold;
}
void setSleepTimeout(btScalar sleepTimeout)
{
this->m_sleepTimeout = sleepTimeout;
}
private: private:
btMultiBody(const btMultiBody &); // not implemented btMultiBody(const btMultiBody &); // not implemented
void operator=(const btMultiBody &); // not implemented void operator=(const btMultiBody &); // not implemented
@ -745,7 +759,7 @@ private:
} }
} }
void mulMatrix(btScalar * pA, btScalar * pB, int rowsA, int colsA, int rowsB, int colsB, btScalar *pC) const; void mulMatrix(const btScalar *pA, const btScalar *pB, int rowsA, int colsA, int rowsB, int colsB, btScalar *pC) const;
private: private:
btMultiBodyLinkCollider *m_baseCollider; //can be NULL btMultiBodyLinkCollider *m_baseCollider; //can be NULL
@ -801,6 +815,8 @@ private:
bool m_canSleep; bool m_canSleep;
bool m_canWakeup; bool m_canWakeup;
btScalar m_sleepTimer; btScalar m_sleepTimer;
btScalar m_sleepEpsilon;
btScalar m_sleepTimeout;
void *m_userObjectPointer; void *m_userObjectPointer;
int m_userIndex2; int m_userIndex2;

View file

@ -61,7 +61,8 @@ btScalar btMultiBodyConstraint::fillMultiBodyConstraint(btMultiBodySolverConstra
btScalar lowerLimit, btScalar upperLimit, btScalar lowerLimit, btScalar upperLimit,
bool angConstraint, bool angConstraint,
btScalar relaxation, btScalar relaxation,
bool isFriction, btScalar desiredVelocity, btScalar cfmSlip) bool isFriction, btScalar desiredVelocity, btScalar cfmSlip,
btScalar damping)
{ {
solverConstraint.m_multiBodyA = m_bodyA; solverConstraint.m_multiBodyA = m_bodyA;
solverConstraint.m_multiBodyB = m_bodyB; solverConstraint.m_multiBodyB = m_bodyB;
@ -348,7 +349,7 @@ btScalar btMultiBodyConstraint::fillMultiBodyConstraint(btMultiBodySolverConstra
{ {
btScalar positionalError = 0.f; btScalar positionalError = 0.f;
btScalar velocityError = desiredVelocity - rel_vel; // * damping; btScalar velocityError = (desiredVelocity - rel_vel) * damping;
btScalar erp = infoGlobal.m_erp2; btScalar erp = infoGlobal.m_erp2;

View file

@ -94,7 +94,7 @@ protected:
bool angConstraint = false, bool angConstraint = false,
btScalar relaxation = 1.f, btScalar relaxation = 1.f,
bool isFriction = false, btScalar desiredVelocity = 0, btScalar cfmSlip = 0); bool isFriction = false, btScalar desiredVelocity = 0, btScalar cfmSlip = 0, btScalar damping = 1.0);
public: public:
BT_DECLARE_ALIGNED_ALLOCATOR(); BT_DECLARE_ALIGNED_ALLOCATOR();

View file

@ -137,7 +137,14 @@ void btMultiBodyDynamicsWorld::updateActivationState(btScalar timeStep)
btMultiBodyLinkCollider* col = body->getBaseCollider(); btMultiBodyLinkCollider* col = body->getBaseCollider();
if (col && col->getActivationState() == ACTIVE_TAG) if (col && col->getActivationState() == ACTIVE_TAG)
{ {
col->setActivationState(WANTS_DEACTIVATION); if (body->hasFixedBase())
{
col->setActivationState(FIXED_BASE_MULTI_BODY);
} else
{
col->setActivationState(WANTS_DEACTIVATION);
}
col->setDeactivationTime(0.f); col->setDeactivationTime(0.f);
} }
for (int b = 0; b < body->getNumLinks(); b++) for (int b = 0; b < body->getNumLinks(); b++)

View file

@ -42,6 +42,7 @@ void btMultiBodyJointMotor::finalizeMultiDof()
int linkDoF = 0; int linkDoF = 0;
unsigned int offset = 6 + (m_bodyA->getLink(m_linkA).m_dofOffset + linkDoF); unsigned int offset = 6 + (m_bodyA->getLink(m_linkA).m_dofOffset + linkDoF);
// row 0: the lower bound
// row 0: the lower bound // row 0: the lower bound
jacobianA(0)[offset] = 1; jacobianA(0)[offset] = 1;

View file

@ -26,10 +26,13 @@ btMultiBodySphericalJointMotor::btMultiBodySphericalJointMotor(btMultiBody* body
: btMultiBodyConstraint(body, body, link, body->getLink(link).m_parent, 3, true, MULTIBODY_CONSTRAINT_SPHERICAL_MOTOR), : btMultiBodyConstraint(body, body, link, body->getLink(link).m_parent, 3, true, MULTIBODY_CONSTRAINT_SPHERICAL_MOTOR),
m_desiredVelocity(0, 0, 0), m_desiredVelocity(0, 0, 0),
m_desiredPosition(0,0,0,1), m_desiredPosition(0,0,0,1),
m_kd(1.), m_use_multi_dof_params(false),
m_kp(0.2), m_kd(1., 1., 1.),
m_kp(0.2, 0.2, 0.2),
m_erp(1), m_erp(1),
m_rhsClamp(SIMD_INFINITY) m_rhsClamp(SIMD_INFINITY),
m_maxAppliedImpulseMultiDof(maxMotorImpulse, maxMotorImpulse, maxMotorImpulse),
m_damping(1.0, 1.0, 1.0)
{ {
m_maxAppliedImpulse = maxMotorImpulse; m_maxAppliedImpulse = maxMotorImpulse;
@ -44,6 +47,7 @@ void btMultiBodySphericalJointMotor::finalizeMultiDof()
int linkDoF = 0; int linkDoF = 0;
unsigned int offset = 6 + (m_bodyA->getLink(m_linkA).m_dofOffset + linkDoF); unsigned int offset = 6 + (m_bodyA->getLink(m_linkA).m_dofOffset + linkDoF);
// row 0: the lower bound
// row 0: the lower bound // row 0: the lower bound
jacobianA(0)[offset] = 1; jacobianA(0)[offset] = 1;
@ -138,7 +142,8 @@ btQuaternion relRot = currentQuat.inverse() * desiredQuat;
btScalar currentVelocity = m_bodyA->getJointVelMultiDof(m_linkA)[dof]; btScalar currentVelocity = m_bodyA->getJointVelMultiDof(m_linkA)[dof];
btScalar desiredVelocity = this->m_desiredVelocity[row]; btScalar desiredVelocity = this->m_desiredVelocity[row];
btScalar velocityError = desiredVelocity - currentVelocity; double kd = m_use_multi_dof_params ? m_kd[row % 3] : m_kd[0];
btScalar velocityError = (desiredVelocity - currentVelocity) * kd;
btMatrix3x3 frameAworld; btMatrix3x3 frameAworld;
frameAworld.setIdentity(); frameAworld.setIdentity();
@ -151,12 +156,16 @@ btQuaternion relRot = currentQuat.inverse() * desiredQuat;
case btMultibodyLink::eSpherical: case btMultibodyLink::eSpherical:
{ {
btVector3 constraintNormalAng = frameAworld.getColumn(row % 3); btVector3 constraintNormalAng = frameAworld.getColumn(row % 3);
posError = m_kp*angleDiff[row % 3]; double kp = m_use_multi_dof_params ? m_kp[row % 3] : m_kp[0];
posError = kp*angleDiff[row % 3];
double max_applied_impulse = m_use_multi_dof_params ? m_maxAppliedImpulseMultiDof[row % 3] : m_maxAppliedImpulse;
fillMultiBodyConstraint(constraintRow, data, 0, 0, constraintNormalAng, fillMultiBodyConstraint(constraintRow, data, 0, 0, constraintNormalAng,
btVector3(0,0,0), dummy, dummy, btVector3(0,0,0), dummy, dummy,
posError, posError,
infoGlobal, infoGlobal,
-m_maxAppliedImpulse, m_maxAppliedImpulse, true); -max_applied_impulse, max_applied_impulse, true,
1.0, false, 0, 0,
m_damping[row % 3]);
constraintRow.m_orgConstraint = this; constraintRow.m_orgConstraint = this;
constraintRow.m_orgDofIndex = row; constraintRow.m_orgDofIndex = row;
break; break;

View file

@ -26,10 +26,13 @@ class btMultiBodySphericalJointMotor : public btMultiBodyConstraint
protected: protected:
btVector3 m_desiredVelocity; btVector3 m_desiredVelocity;
btQuaternion m_desiredPosition; btQuaternion m_desiredPosition;
btScalar m_kd; bool m_use_multi_dof_params;
btScalar m_kp; btVector3 m_kd;
btVector3 m_kp;
btScalar m_erp; btScalar m_erp;
btScalar m_rhsClamp; //maximum error btScalar m_rhsClamp; //maximum error
btVector3 m_maxAppliedImpulseMultiDof;
btVector3 m_damping;
public: public:
btMultiBodySphericalJointMotor(btMultiBody* body, int link, btScalar maxMotorImpulse); btMultiBodySphericalJointMotor(btMultiBody* body, int link, btScalar maxMotorImpulse);
@ -44,16 +47,32 @@ public:
btMultiBodyJacobianData& data, btMultiBodyJacobianData& data,
const btContactSolverInfo& infoGlobal); const btContactSolverInfo& infoGlobal);
virtual void setVelocityTarget(const btVector3& velTarget, btScalar kd = 1.f) virtual void setVelocityTarget(const btVector3& velTarget, btScalar kd = 1.0)
{
m_desiredVelocity = velTarget;
m_kd = btVector3(kd, kd, kd);
m_use_multi_dof_params = false;
}
virtual void setVelocityTargetMultiDof(const btVector3& velTarget, const btVector3& kd = btVector3(1.0, 1.0, 1.0))
{ {
m_desiredVelocity = velTarget; m_desiredVelocity = velTarget;
m_kd = kd; m_kd = kd;
m_use_multi_dof_params = true;
} }
virtual void setPositionTarget(const btQuaternion& posTarget, btScalar kp = 1.f) virtual void setPositionTarget(const btQuaternion& posTarget, btScalar kp =1.f)
{
m_desiredPosition = posTarget;
m_kp = btVector3(kp, kp, kp);
m_use_multi_dof_params = false;
}
virtual void setPositionTargetMultiDof(const btQuaternion& posTarget, const btVector3& kp = btVector3(1.f, 1.f, 1.f))
{ {
m_desiredPosition = posTarget; m_desiredPosition = posTarget;
m_kp = kp; m_kp = kp;
m_use_multi_dof_params = true;
} }
virtual void setErp(btScalar erp) virtual void setErp(btScalar erp)
@ -68,6 +87,28 @@ public:
{ {
m_rhsClamp = rhsClamp; m_rhsClamp = rhsClamp;
} }
btScalar getMaxAppliedImpulseMultiDof(int i) const
{
return m_maxAppliedImpulseMultiDof[i];
}
void setMaxAppliedImpulseMultiDof(const btVector3& maxImp)
{
m_maxAppliedImpulseMultiDof = maxImp;
m_use_multi_dof_params = true;
}
btScalar getDamping(int i) const
{
return m_damping[i];
}
void setDamping(const btVector3& damping)
{
m_damping = damping;
}
virtual void debugDraw(class btIDebugDraw* drawer) virtual void debugDraw(class btIDebugDraw* drawer)
{ {
//todo(erwincoumans) //todo(erwincoumans)

View file

@ -532,7 +532,7 @@ void btMLCPSolver::createMLCP(const btContactSolverInfo& infoGlobal)
J_transpose = J.transpose(); J_transpose = J.transpose();
btMatrixXu& tmp = m_scratchTmp; btMatrixXu& tmp = m_scratchTmp;
//Minv.printMatrix("Minv=");
{ {
{ {
BT_PROFILE("J*Minv"); BT_PROFILE("J*Minv");
@ -543,7 +543,7 @@ void btMLCPSolver::createMLCP(const btContactSolverInfo& infoGlobal)
m_A = tmp * J_transpose; m_A = tmp * J_transpose;
} }
} }
//J.printMatrix("J");
if (1) if (1)
{ {
// add cfm to the diagonal of m_A // add cfm to the diagonal of m_A

View file

@ -405,6 +405,10 @@ void btDeformableBodySolver::predictMotion(btScalar solverdt)
for (int i = 0; i < m_softBodies.size(); ++i) for (int i = 0; i < m_softBodies.size(); ++i)
{ {
btSoftBody* psb = m_softBodies[i]; btSoftBody* psb = m_softBodies[i];
/* Clear contacts */
psb->m_nodeRigidContacts.resize(0);
psb->m_faceRigidContacts.resize(0);
psb->m_faceNodeContacts.resize(0);
if (psb->isActive()) if (psb->isActive())
{ {
@ -472,10 +476,6 @@ void btDeformableBodySolver::predictDeformableMotion(btSoftBody* psb, btScalar d
{ {
psb->updateFaceTree(true, true); psb->updateFaceTree(true, true);
} }
/* Clear contacts */
psb->m_nodeRigidContacts.resize(0);
psb->m_faceRigidContacts.resize(0);
psb->m_faceNodeContacts.resize(0);
/* Optimize dbvt's */ /* Optimize dbvt's */
// psb->m_ndbvt.optimizeIncremental(1); // psb->m_ndbvt.optimizeIncremental(1);
// psb->m_fdbvt.optimizeIncremental(1); // psb->m_fdbvt.optimizeIncremental(1);

View file

@ -29,7 +29,7 @@ class btDeformableMousePickingForce : public btDeformableLagrangianForce
public: public:
typedef btAlignedObjectArray<btVector3> TVStack; typedef btAlignedObjectArray<btVector3> TVStack;
btDeformableMousePickingForce(btScalar k, btScalar d, const btSoftBody::Face& face, btVector3 mouse_pos, btScalar maxForce = 0.3) : m_elasticStiffness(k), m_dampingStiffness(d), m_face(face), m_mouse_pos(mouse_pos), m_maxForce(maxForce) btDeformableMousePickingForce(btScalar k, btScalar d, const btSoftBody::Face& face, const btVector3& mouse_pos, btScalar maxForce = 0.3) : m_elasticStiffness(k), m_dampingStiffness(d), m_face(face), m_mouse_pos(mouse_pos), m_maxForce(maxForce)
{ {
} }

View file

@ -1317,8 +1317,8 @@ public:
} }
for (int k = 0; k < m_faceNodeContacts.size(); ++k) for (int k = 0; k < m_faceNodeContacts.size(); ++k)
{ {
int i = indices[k]; int idx = indices[k];
btSoftBody::DeformableFaceNodeContact& c = m_faceNodeContacts[i]; btSoftBody::DeformableFaceNodeContact& c = m_faceNodeContacts[idx];
btSoftBody::Node* node = c.m_node; btSoftBody::Node* node = c.m_node;
btSoftBody::Face* face = c.m_face; btSoftBody::Face* face = c.m_face;
const btVector3& w = c.m_bary; const btVector3& w = c.m_bary;

View file

@ -4,8 +4,8 @@ Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
This software is provided 'as-is', without any express or implied warranty. This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely, including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions: subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
@ -21,7 +21,7 @@ subject to the following restrictions:
///The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations. ///The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
///Typical use case: create a debug drawer object, and assign it to a btCollisionWorld or btDynamicsWorld using setDebugDrawer and call debugDrawWorld. ///Typical use case: create a debug drawer object, and assign it to a btCollisionWorld or btDynamicsWorld using setDebugDrawer and call debugDrawWorld.
///A class that implements the btIDebugDraw interface has to implement the drawLine method at a minimum. ///A class that implements the btIDebugDraw interface will need to provide non-empty implementations of the the drawLine and getDebugMode methods at a minimum.
///For color arguments the X,Y,Z components refer to Red, Green and Blue each in the range [0..1] ///For color arguments the X,Y,Z components refer to Red, Green and Blue each in the range [0..1]
class btIDebugDraw class btIDebugDraw
{ {

View file

@ -25,7 +25,7 @@ subject to the following restrictions:
#include <float.h> #include <float.h>
/* SVN $Revision$ on $Date$ from http://bullet.googlecode.com*/ /* SVN $Revision$ on $Date$ from http://bullet.googlecode.com*/
#define BT_BULLET_VERSION 308 #define BT_BULLET_VERSION 317
inline int btGetVersion() inline int btGetVersion()
{ {

View file

@ -480,8 +480,8 @@ public:
} }
buffer[9] = '3'; buffer[9] = '3';
buffer[10] = '0'; buffer[10] = '1';
buffer[11] = '8'; buffer[11] = '7';
} }
virtual void startSerialization() virtual void startSerialization()
@ -499,7 +499,6 @@ public:
writeDNA(); writeDNA();
//if we didn't pre-allocate a buffer, we need to create a contiguous buffer now //if we didn't pre-allocate a buffer, we need to create a contiguous buffer now
int mysize = 0;
if (!m_totalSize) if (!m_totalSize)
{ {
if (m_buffer) if (m_buffer)
@ -511,14 +510,12 @@ public:
unsigned char* currentPtr = m_buffer; unsigned char* currentPtr = m_buffer;
writeHeader(m_buffer); writeHeader(m_buffer);
currentPtr += BT_HEADER_LENGTH; currentPtr += BT_HEADER_LENGTH;
mysize += BT_HEADER_LENGTH;
for (int i = 0; i < m_chunkPtrs.size(); i++) for (int i = 0; i < m_chunkPtrs.size(); i++)
{ {
int curLength = sizeof(btChunk) + m_chunkPtrs[i]->m_length; int curLength = sizeof(btChunk) + m_chunkPtrs[i]->m_length;
memcpy(currentPtr, m_chunkPtrs[i], curLength); memcpy(currentPtr, m_chunkPtrs[i], curLength);
btAlignedFree(m_chunkPtrs[i]); btAlignedFree(m_chunkPtrs[i]);
currentPtr += curLength; currentPtr += curLength;
mysize += curLength;
} }
} }

1
thirdparty/bullet/VERSION.txt vendored Normal file
View file

@ -0,0 +1 @@
3.17

View file

@ -0,0 +1,42 @@
diff --git a/thirdparty/bullet/BulletSoftBody/btSoftBody.h b/thirdparty/bullet/BulletSoftBody/btSoftBody.h
index f578487b8c..dfde8fd1e4 100644
--- a/thirdparty/bullet/BulletSoftBody/btSoftBody.h
+++ b/thirdparty/bullet/BulletSoftBody/btSoftBody.h
@@ -1317,8 +1317,8 @@ public:
}
for (int k = 0; k < m_faceNodeContacts.size(); ++k)
{
- int i = indices[k];
- btSoftBody::DeformableFaceNodeContact& c = m_faceNodeContacts[i];
+ int idx = indices[k];
+ btSoftBody::DeformableFaceNodeContact& c = m_faceNodeContacts[idx];
btSoftBody::Node* node = c.m_node;
btSoftBody::Face* face = c.m_face;
const btVector3& w = c.m_bary;
diff --git a/thirdparty/bullet/LinearMath/btSerializer.h b/thirdparty/bullet/LinearMath/btSerializer.h
index ce4fc34e20..11592d2ccd 100644
--- a/thirdparty/bullet/LinearMath/btSerializer.h
+++ b/thirdparty/bullet/LinearMath/btSerializer.h
@@ -499,7 +499,6 @@ public:
writeDNA();
//if we didn't pre-allocate a buffer, we need to create a contiguous buffer now
- int mysize = 0;
if (!m_totalSize)
{
if (m_buffer)
@@ -511,14 +510,12 @@ public:
unsigned char* currentPtr = m_buffer;
writeHeader(m_buffer);
currentPtr += BT_HEADER_LENGTH;
- mysize += BT_HEADER_LENGTH;
for (int i = 0; i < m_chunkPtrs.size(); i++)
{
int curLength = sizeof(btChunk) + m_chunkPtrs[i]->m_length;
memcpy(currentPtr, m_chunkPtrs[i], curLength);
btAlignedFree(m_chunkPtrs[i]);
currentPtr += curLength;
- mysize += curLength;
}
}