2017-08-01 14:30:58 +02:00
|
|
|
/*
|
|
|
|
Bullet Continuous Collision Detection and Physics Library
|
2022-01-06 23:37:49 +01:00
|
|
|
Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
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.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "btSoftBodyRigidBodyCollisionConfiguration.h"
|
|
|
|
#include "btSoftRigidCollisionAlgorithm.h"
|
|
|
|
#include "btSoftBodyConcaveCollisionAlgorithm.h"
|
|
|
|
#include "btSoftSoftCollisionAlgorithm.h"
|
|
|
|
|
|
|
|
#include "LinearMath/btPoolAllocator.h"
|
|
|
|
|
|
|
|
#define ENABLE_SOFTBODY_CONCAVE_COLLISIONS 1
|
|
|
|
|
|
|
|
btSoftBodyRigidBodyCollisionConfiguration::btSoftBodyRigidBodyCollisionConfiguration(const btDefaultCollisionConstructionInfo& constructionInfo)
|
2019-01-03 14:26:51 +01:00
|
|
|
: btDefaultCollisionConfiguration(constructionInfo)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
void* mem;
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
mem = btAlignedAlloc(sizeof(btSoftSoftCollisionAlgorithm::CreateFunc), 16);
|
|
|
|
m_softSoftCreateFunc = new (mem) btSoftSoftCollisionAlgorithm::CreateFunc;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
mem = btAlignedAlloc(sizeof(btSoftRigidCollisionAlgorithm::CreateFunc), 16);
|
|
|
|
m_softRigidConvexCreateFunc = new (mem) btSoftRigidCollisionAlgorithm::CreateFunc;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
mem = btAlignedAlloc(sizeof(btSoftRigidCollisionAlgorithm::CreateFunc), 16);
|
|
|
|
m_swappedSoftRigidConvexCreateFunc = new (mem) btSoftRigidCollisionAlgorithm::CreateFunc;
|
|
|
|
m_swappedSoftRigidConvexCreateFunc->m_swapped = true;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
#ifdef ENABLE_SOFTBODY_CONCAVE_COLLISIONS
|
2019-01-03 14:26:51 +01:00
|
|
|
mem = btAlignedAlloc(sizeof(btSoftBodyConcaveCollisionAlgorithm::CreateFunc), 16);
|
|
|
|
m_softRigidConcaveCreateFunc = new (mem) btSoftBodyConcaveCollisionAlgorithm::CreateFunc;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
mem = btAlignedAlloc(sizeof(btSoftBodyConcaveCollisionAlgorithm::CreateFunc), 16);
|
|
|
|
m_swappedSoftRigidConcaveCreateFunc = new (mem) btSoftBodyConcaveCollisionAlgorithm::SwappedCreateFunc;
|
|
|
|
m_swappedSoftRigidConcaveCreateFunc->m_swapped = true;
|
2017-08-01 14:30:58 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//replace pool by a new one, with potential larger size
|
|
|
|
|
|
|
|
if (m_ownsCollisionAlgorithmPool && m_collisionAlgorithmPool)
|
|
|
|
{
|
|
|
|
int curElemSize = m_collisionAlgorithmPool->getElementSize();
|
|
|
|
///calculate maximum element size, big enough to fit any collision algorithm in the memory pool
|
|
|
|
|
|
|
|
int maxSize0 = sizeof(btSoftSoftCollisionAlgorithm);
|
|
|
|
int maxSize1 = sizeof(btSoftRigidCollisionAlgorithm);
|
|
|
|
int maxSize2 = sizeof(btSoftBodyConcaveCollisionAlgorithm);
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
int collisionAlgorithmMaxElementSize = btMax(maxSize0, maxSize1);
|
|
|
|
collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize, maxSize2);
|
|
|
|
|
2017-08-01 14:30:58 +02:00
|
|
|
if (collisionAlgorithmMaxElementSize > curElemSize)
|
|
|
|
{
|
|
|
|
m_collisionAlgorithmPool->~btPoolAllocator();
|
|
|
|
btAlignedFree(m_collisionAlgorithmPool);
|
2019-01-03 14:26:51 +01:00
|
|
|
void* mem = btAlignedAlloc(sizeof(btPoolAllocator), 16);
|
|
|
|
m_collisionAlgorithmPool = new (mem) btPoolAllocator(collisionAlgorithmMaxElementSize, constructionInfo.m_defaultMaxCollisionAlgorithmPoolSize);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
btSoftBodyRigidBodyCollisionConfiguration::~btSoftBodyRigidBodyCollisionConfiguration()
|
|
|
|
{
|
|
|
|
m_softSoftCreateFunc->~btCollisionAlgorithmCreateFunc();
|
2019-01-03 14:26:51 +01:00
|
|
|
btAlignedFree(m_softSoftCreateFunc);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
m_softRigidConvexCreateFunc->~btCollisionAlgorithmCreateFunc();
|
2019-01-03 14:26:51 +01:00
|
|
|
btAlignedFree(m_softRigidConvexCreateFunc);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
m_swappedSoftRigidConvexCreateFunc->~btCollisionAlgorithmCreateFunc();
|
2019-01-03 14:26:51 +01:00
|
|
|
btAlignedFree(m_swappedSoftRigidConvexCreateFunc);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
#ifdef ENABLE_SOFTBODY_CONCAVE_COLLISIONS
|
|
|
|
m_softRigidConcaveCreateFunc->~btCollisionAlgorithmCreateFunc();
|
2019-01-03 14:26:51 +01:00
|
|
|
btAlignedFree(m_softRigidConcaveCreateFunc);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
m_swappedSoftRigidConcaveCreateFunc->~btCollisionAlgorithmCreateFunc();
|
2019-01-03 14:26:51 +01:00
|
|
|
btAlignedFree(m_swappedSoftRigidConcaveCreateFunc);
|
2017-08-01 14:30:58 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
///creation of soft-soft and soft-rigid, and otherwise fallback to base class implementation
|
2019-01-03 14:26:51 +01:00
|
|
|
btCollisionAlgorithmCreateFunc* btSoftBodyRigidBodyCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
|
|
|
///try to handle the softbody interactions first
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
if ((proxyType0 == SOFTBODY_SHAPE_PROXYTYPE) && (proxyType1 == SOFTBODY_SHAPE_PROXYTYPE))
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return m_softSoftCreateFunc;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///softbody versus convex
|
2019-01-03 14:26:51 +01:00
|
|
|
if (proxyType0 == SOFTBODY_SHAPE_PROXYTYPE && btBroadphaseProxy::isConvex(proxyType1))
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return m_softRigidConvexCreateFunc;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///convex versus soft body
|
2019-01-03 14:26:51 +01:00
|
|
|
if (btBroadphaseProxy::isConvex(proxyType0) && proxyType1 == SOFTBODY_SHAPE_PROXYTYPE)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return m_swappedSoftRigidConvexCreateFunc;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ENABLE_SOFTBODY_CONCAVE_COLLISIONS
|
|
|
|
///softbody versus convex
|
2019-01-03 14:26:51 +01:00
|
|
|
if (proxyType0 == SOFTBODY_SHAPE_PROXYTYPE && btBroadphaseProxy::isConcave(proxyType1))
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return m_softRigidConcaveCreateFunc;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
///convex versus soft body
|
2019-01-03 14:26:51 +01:00
|
|
|
if (btBroadphaseProxy::isConcave(proxyType0) && proxyType1 == SOFTBODY_SHAPE_PROXYTYPE)
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
return m_swappedSoftRigidConcaveCreateFunc;
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
///fallback to the regular rigid collision shape
|
2019-01-03 14:26:51 +01:00
|
|
|
return btDefaultCollisionConfiguration::getCollisionAlgorithmCreateFunc(proxyType0, proxyType1);
|
2017-08-01 14:30:58 +02:00
|
|
|
}
|