some minor work on soft body, to make it easier to integrate into apps.
This commit is contained in:
@@ -46,6 +46,7 @@ IMPLICIT_CONVEX_SHAPES_START_HERE,
|
|||||||
CONCAVE_SHAPES_START_HERE,
|
CONCAVE_SHAPES_START_HERE,
|
||||||
//keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy!
|
//keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy!
|
||||||
TRIANGLE_MESH_SHAPE_PROXYTYPE,
|
TRIANGLE_MESH_SHAPE_PROXYTYPE,
|
||||||
|
SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE,
|
||||||
///used for demo integration FAST/Swift collision library and Bullet
|
///used for demo integration FAST/Swift collision library and Bullet
|
||||||
FAST_CONCAVE_MESH_PROXYTYPE,
|
FAST_CONCAVE_MESH_PROXYTYPE,
|
||||||
//terrain
|
//terrain
|
||||||
|
|||||||
@@ -117,5 +117,5 @@ const btVector3& btScaledBvhTriangleMeshShape::getLocalScaling() const
|
|||||||
void btScaledBvhTriangleMeshShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
|
void btScaledBvhTriangleMeshShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
|
||||||
{
|
{
|
||||||
///don't make this a movable object!
|
///don't make this a movable object!
|
||||||
btAssert(0);
|
// btAssert(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public:
|
|||||||
virtual int getShapeType() const
|
virtual int getShapeType() const
|
||||||
{
|
{
|
||||||
//use un-used 'FAST_CONCAVE_MESH_PROXYTYPE' for now, later add SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE to btBroadphaseProxy.h
|
//use un-used 'FAST_CONCAVE_MESH_PROXYTYPE' for now, later add SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE to btBroadphaseProxy.h
|
||||||
return FAST_CONCAVE_MESH_PROXYTYPE;
|
return SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
|
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
|
||||||
@@ -49,6 +49,16 @@ public:
|
|||||||
|
|
||||||
virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
|
virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
|
||||||
|
|
||||||
|
btBvhTriangleMeshShape* getChildShape()
|
||||||
|
{
|
||||||
|
return m_bvhTriMeshShape;
|
||||||
|
}
|
||||||
|
|
||||||
|
const btBvhTriangleMeshShape* getChildShape() const
|
||||||
|
{
|
||||||
|
return m_bvhTriMeshShape;
|
||||||
|
}
|
||||||
|
|
||||||
//debugging
|
//debugging
|
||||||
virtual const char* getName()const {return "SCALEDBVHTRIANGLEMESH";}
|
virtual const char* getName()const {return "SCALEDBVHTRIANGLEMESH";}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ subject to the following restrictions:
|
|||||||
#include "BulletCollision/BroadphaseCollision/btDbvt.h"
|
#include "BulletCollision/BroadphaseCollision/btDbvt.h"
|
||||||
|
|
||||||
class btBroadphaseInterface;
|
class btBroadphaseInterface;
|
||||||
class btCollisionDispatcher;
|
class btDispatcher;
|
||||||
|
|
||||||
/* btSoftBodyWorldInfo */
|
/* btSoftBodyWorldInfo */
|
||||||
struct btSoftBodyWorldInfo
|
struct btSoftBodyWorldInfo
|
||||||
@@ -39,7 +39,7 @@ struct btSoftBodyWorldInfo
|
|||||||
btScalar water_offset;
|
btScalar water_offset;
|
||||||
btVector3 water_normal;
|
btVector3 water_normal;
|
||||||
btBroadphaseInterface* m_broadphase;
|
btBroadphaseInterface* m_broadphase;
|
||||||
btCollisionDispatcher* m_dispatcher;
|
btDispatcher* m_dispatcher;
|
||||||
btVector3 m_gravity;
|
btVector3 m_gravity;
|
||||||
btSparseSdf<3> m_sparsesdf;
|
btSparseSdf<3> m_sparsesdf;
|
||||||
};
|
};
|
||||||
@@ -607,6 +607,7 @@ public:
|
|||||||
virtual ~btSoftBody();
|
virtual ~btSoftBody();
|
||||||
/* Check for existing link */
|
/* Check for existing link */
|
||||||
|
|
||||||
|
btAlignedObjectArray<int> m_userIndexMapping;
|
||||||
|
|
||||||
virtual void setCollisionShape(btCollisionShape* collisionShape)
|
virtual void setCollisionShape(btCollisionShape* collisionShape)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ subject to the following restrictions:
|
|||||||
#include "btSoftBody.h"
|
#include "btSoftBody.h"
|
||||||
#include "btSoftBodyHelpers.h"
|
#include "btSoftBodyHelpers.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
btSoftRigidDynamicsWorld::btSoftRigidDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration)
|
btSoftRigidDynamicsWorld::btSoftRigidDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration)
|
||||||
:btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration)
|
:btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration)
|
||||||
{
|
{
|
||||||
@@ -28,6 +32,11 @@ m_drawFlags = fDrawFlags::Std;
|
|||||||
m_drawNodeTree = true;
|
m_drawNodeTree = true;
|
||||||
m_drawFaceTree = false;
|
m_drawFaceTree = false;
|
||||||
m_drawClusterTree = false;
|
m_drawClusterTree = false;
|
||||||
|
m_sbi.m_broadphase = pairCache;
|
||||||
|
m_sbi.m_dispatcher = dispatcher;
|
||||||
|
m_sbi.m_sparsesdf.Initialize();
|
||||||
|
m_sbi.m_sparsesdf.Reset();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
btSoftRigidDynamicsWorld::~btSoftRigidDynamicsWorld()
|
btSoftRigidDynamicsWorld::~btSoftRigidDynamicsWorld()
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ subject to the following restrictions:
|
|||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h"
|
|
||||||
|
|
||||||
#ifndef BT_SOFT_RIGID_DYNAMICS_WORLD_H
|
#ifndef BT_SOFT_RIGID_DYNAMICS_WORLD_H
|
||||||
#define BT_SOFT_RIGID_DYNAMICS_WORLD_H
|
#define BT_SOFT_RIGID_DYNAMICS_WORLD_H
|
||||||
|
|
||||||
class btSoftBody;
|
#include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h"
|
||||||
|
#include "btSoftBody.h"
|
||||||
|
|
||||||
typedef btAlignedObjectArray<btSoftBody*> btSoftBodyArray;
|
typedef btAlignedObjectArray<btSoftBody*> btSoftBodyArray;
|
||||||
|
|
||||||
class btSoftRigidDynamicsWorld : public btDiscreteDynamicsWorld
|
class btSoftRigidDynamicsWorld : public btDiscreteDynamicsWorld
|
||||||
@@ -29,6 +29,7 @@ class btSoftRigidDynamicsWorld : public btDiscreteDynamicsWorld
|
|||||||
bool m_drawNodeTree;
|
bool m_drawNodeTree;
|
||||||
bool m_drawFaceTree;
|
bool m_drawFaceTree;
|
||||||
bool m_drawClusterTree;
|
bool m_drawClusterTree;
|
||||||
|
btSoftBodyWorldInfo m_sbi;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@@ -41,7 +42,6 @@ protected:
|
|||||||
void solveSoftBodiesConstraints();
|
void solveSoftBodiesConstraints();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
btSoftRigidDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration);
|
btSoftRigidDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration);
|
||||||
@@ -57,6 +57,15 @@ public:
|
|||||||
int getDrawFlags() const { return(m_drawFlags); }
|
int getDrawFlags() const { return(m_drawFlags); }
|
||||||
void setDrawFlags(int f) { m_drawFlags=f; }
|
void setDrawFlags(int f) { m_drawFlags=f; }
|
||||||
|
|
||||||
|
btSoftBodyWorldInfo& getWorldInfo()
|
||||||
|
{
|
||||||
|
return m_sbi;
|
||||||
|
}
|
||||||
|
const btSoftBodyWorldInfo& getWorldInfo() const
|
||||||
|
{
|
||||||
|
return m_sbi;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
btSoftBodyArray& getSoftBodyArray()
|
btSoftBodyArray& getSoftBodyArray()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -869,6 +869,8 @@ bool HullLibrary::CleanupVertices(unsigned int svcount,
|
|||||||
{
|
{
|
||||||
if ( svcount == 0 ) return false;
|
if ( svcount == 0 ) return false;
|
||||||
|
|
||||||
|
m_vertexIndexMapping.resize(0);
|
||||||
|
|
||||||
|
|
||||||
#define EPSILON btScalar(0.000001) /* close enough to consider two btScalaring point numbers to be 'the same'. */
|
#define EPSILON btScalar(0.000001) /* close enough to consider two btScalaring point numbers to be 'the same'. */
|
||||||
|
|
||||||
@@ -1027,6 +1029,7 @@ bool HullLibrary::CleanupVertices(unsigned int svcount,
|
|||||||
v[0] = px;
|
v[0] = px;
|
||||||
v[1] = py;
|
v[1] = py;
|
||||||
v[2] = pz;
|
v[2] = pz;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -1041,6 +1044,7 @@ bool HullLibrary::CleanupVertices(unsigned int svcount,
|
|||||||
dest[2] = pz;
|
dest[2] = pz;
|
||||||
vcount++;
|
vcount++;
|
||||||
}
|
}
|
||||||
|
m_vertexIndexMapping.push_back(j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1116,13 +1120,22 @@ bool HullLibrary::CleanupVertices(unsigned int svcount,
|
|||||||
|
|
||||||
void HullLibrary::BringOutYourDead(const btVector3* verts,unsigned int vcount, btVector3* overts,unsigned int &ocount,unsigned int *indices,unsigned indexcount)
|
void HullLibrary::BringOutYourDead(const btVector3* verts,unsigned int vcount, btVector3* overts,unsigned int &ocount,unsigned int *indices,unsigned indexcount)
|
||||||
{
|
{
|
||||||
|
btAlignedObjectArray<int>tmpIndices;
|
||||||
|
tmpIndices.resize(m_vertexIndexMapping.size());
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0;i<m_vertexIndexMapping.size();i++)
|
||||||
|
{
|
||||||
|
tmpIndices[i] = m_vertexIndexMapping[i];
|
||||||
|
}
|
||||||
|
|
||||||
TUIntArray usedIndices;
|
TUIntArray usedIndices;
|
||||||
usedIndices.resize(static_cast<int>(vcount));
|
usedIndices.resize(static_cast<int>(vcount));
|
||||||
memset(&usedIndices[0],0,sizeof(unsigned int)*vcount);
|
memset(&usedIndices[0],0,sizeof(unsigned int)*vcount);
|
||||||
|
|
||||||
ocount = 0;
|
ocount = 0;
|
||||||
|
|
||||||
for (unsigned int i=0; i<indexcount; i++)
|
for (i=0; i<indexcount; i++)
|
||||||
{
|
{
|
||||||
unsigned int v = indices[i]; // original array index
|
unsigned int v = indices[i]; // original array index
|
||||||
|
|
||||||
@@ -1141,11 +1154,19 @@ void HullLibrary::BringOutYourDead(const btVector3* verts,unsigned int vcount, b
|
|||||||
overts[ocount][1] = verts[v][1];
|
overts[ocount][1] = verts[v][1];
|
||||||
overts[ocount][2] = verts[v][2];
|
overts[ocount][2] = verts[v][2];
|
||||||
|
|
||||||
|
for (int k=0;k<m_vertexIndexMapping.size();k++)
|
||||||
|
{
|
||||||
|
if (tmpIndices[k]==v)
|
||||||
|
m_vertexIndexMapping[k]=ocount;
|
||||||
|
}
|
||||||
|
|
||||||
ocount++; // increment output vert count
|
ocount++; // increment output vert count
|
||||||
|
|
||||||
btAssert( ocount >=0 && ocount <= vcount );
|
btAssert( ocount >=0 && ocount <= vcount );
|
||||||
|
|
||||||
usedIndices[static_cast<int>(v)] = ocount; // assign new index remapping
|
usedIndices[static_cast<int>(v)] = ocount; // assign new index remapping
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -192,6 +192,9 @@ class HullLibrary
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
btAlignedObjectArray<int> m_vertexIndexMapping;
|
||||||
|
|
||||||
|
|
||||||
HullError CreateConvexHull(const HullDesc& desc, // describes the input request
|
HullError CreateConvexHull(const HullDesc& desc, // describes the input request
|
||||||
HullResult& result); // contains the resulst
|
HullResult& result); // contains the resulst
|
||||||
HullError ReleaseResult(HullResult &result); // release memory allocated for this result, we are done with it.
|
HullError ReleaseResult(HullResult &result); // release memory allocated for this result, we are done with it.
|
||||||
|
|||||||
Reference in New Issue
Block a user