make btHashMap data protected (not private) for easier serialization

move btTriangleInfoMap.h into its own header, into the BulletCollision/CollisionShapes folder
add btTriangleInfoMap pointer to btBvhTriangleMeshShape, so we don't need to use the 'userpointer' anymore
preparation for serialization of btTriangleInfoMap.

See also http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=4603&start=30
This commit is contained in:
erwin.coumans
2010-02-23 09:52:39 +00:00
parent 2a2c82b7ce
commit 621eddb769
10 changed files with 171 additions and 73 deletions

View File

@@ -464,11 +464,11 @@ void BenchmarkDemo::createWall(const btVector3& offsetPosition,int stackSize,con
btVector3 localInertia(0,0,0); btVector3 localInertia(0,0,0);
blockShape->calculateLocalInertia(mass,localInertia); blockShape->calculateLocalInertia(mass,localInertia);
// float diffX = boxSize[0] * 1.0f; // btScalar diffX = boxSize[0] * 1.0f;
float diffY = boxSize[1] * 1.0f; btScalar diffY = boxSize[1] * 1.0f;
float diffZ = boxSize[2] * 1.0f; btScalar diffZ = boxSize[2] * 1.0f;
float offset = -stackSize * (diffZ * 2.0f) * 0.5f; btScalar offset = -stackSize * (diffZ * 2.0f) * 0.5f;
btVector3 pos(0.0f, diffY, 0.0f); btVector3 pos(0.0f, diffY, 0.0f);
btTransform trans; btTransform trans;
@@ -491,24 +491,24 @@ void BenchmarkDemo::createWall(const btVector3& offsetPosition,int stackSize,con
void BenchmarkDemo::createPyramid(const btVector3& offsetPosition,int stackSize,const btVector3& boxSize) void BenchmarkDemo::createPyramid(const btVector3& offsetPosition,int stackSize,const btVector3& boxSize)
{ {
float space = 0.000f; btScalar space = 0.000f;
btVector3 pos(0.0f, boxSize[1], 0.0f); btVector3 pos(0.0f, boxSize[1], 0.0f);
btBoxShape* blockShape = new btBoxShape(btVector3(boxSize[0]-COLLISION_RADIUS,boxSize[1]-COLLISION_RADIUS,boxSize[2]-COLLISION_RADIUS)); btBoxShape* blockShape = new btBoxShape(btVector3(boxSize[0]-COLLISION_RADIUS,boxSize[1]-COLLISION_RADIUS,boxSize[2]-COLLISION_RADIUS));
btTransform trans; btTransform trans;
trans.setIdentity(); trans.setIdentity();
float mass = 1.f; btScalar mass = 1.f;
btVector3 localInertia(0,0,0); btVector3 localInertia(0,0,0);
blockShape->calculateLocalInertia(mass,localInertia); blockShape->calculateLocalInertia(mass,localInertia);
float diffX = boxSize[0]; btScalar diffX = boxSize[0];
float diffY = boxSize[1]; btScalar diffY = boxSize[1];
float diffZ = boxSize[2]; btScalar diffZ = boxSize[2];
float offsetX = -stackSize * (diffX * 2.0f + space) * 0.5f; btScalar offsetX = -stackSize * (diffX * 2.0f + space) * 0.5f;
float offsetZ = -stackSize * (diffZ * 2.0f + space) * 0.5f; btScalar offsetZ = -stackSize * (diffZ * 2.0f + space) * 0.5f;
while(stackSize) { while(stackSize) {
for(int j=0;j<stackSize;j++) { for(int j=0;j<stackSize;j++) {
pos[2] = offsetZ + (float)j * (diffZ * 2.0f + space); pos[2] = offsetZ + (float)j * (diffZ * 2.0f + space);

View File

@@ -30,7 +30,7 @@ subject to the following restrictions:
#include "GlutStuff.h" #include "GlutStuff.h"
#include "GLDebugDrawer.h" #include "GLDebugDrawer.h"
float yaw=0.f,pitch=0.f,roll=0.f; btScalar yaw=0.f,pitch=0.f,roll=0.f;
const int maxNumObjects = 4; const int maxNumObjects = 4;
const int numObjects = 2; const int numObjects = 2;

View File

@@ -172,6 +172,7 @@ SET(CollisionShapes_HDRS
CollisionShapes/btTriangleCallback.h CollisionShapes/btTriangleCallback.h
CollisionShapes/btTriangleIndexVertexArray.h CollisionShapes/btTriangleIndexVertexArray.h
CollisionShapes/btTriangleIndexVertexMaterialArray.h CollisionShapes/btTriangleIndexVertexMaterialArray.h
CollisionShapes/btTriangleInfoMap.h
CollisionShapes/btTriangleMesh.h CollisionShapes/btTriangleMesh.h
CollisionShapes/btTriangleMeshShape.h CollisionShapes/btTriangleMeshShape.h
CollisionShapes/btTriangleShape.h CollisionShapes/btTriangleShape.h

View File

@@ -315,10 +315,10 @@ struct btConnectivityProcessor : public btTriangleCallback
void btGenerateInternalEdgeInfo (btBvhTriangleMeshShape*trimeshShape, btTriangleInfoMap* triangleInfoMap) void btGenerateInternalEdgeInfo (btBvhTriangleMeshShape*trimeshShape, btTriangleInfoMap* triangleInfoMap)
{ {
//the user pointer shouldn't already be used for other purposes, we intend to store connectivity info there! //the user pointer shouldn't already be used for other purposes, we intend to store connectivity info there!
if (trimeshShape->getUserPointer()) if (trimeshShape->getTriangleInfoMap())
return; return;
trimeshShape->setUserPointer(triangleInfoMap); trimeshShape->setTriangleInfoMap(triangleInfoMap);
btStridingMeshInterface* meshInterface = trimeshShape->getMeshInterface(); btStridingMeshInterface* meshInterface = trimeshShape->getMeshInterface();
const btVector3& meshScaling = meshInterface->getScaling(); const btVector3& meshScaling = meshInterface->getScaling();
@@ -456,7 +456,8 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject*
if (colObj0->getCollisionShape()->getShapeType() != TRIANGLE_SHAPE_PROXYTYPE) if (colObj0->getCollisionShape()->getShapeType() != TRIANGLE_SHAPE_PROXYTYPE)
return; return;
btTriangleInfoMap* triangleInfoMapPtr = (btTriangleInfoMap*) colObj0->getRootCollisionShape()->getUserPointer(); btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)colObj0->getRootCollisionShape();
btTriangleInfoMap* triangleInfoMapPtr = (btTriangleInfoMap*) trimesh->getTriangleInfoMap();
if (!triangleInfoMapPtr) if (!triangleInfoMapPtr)
return; return;

View File

@@ -5,6 +5,8 @@
#include "LinearMath/btHashMap.h" #include "LinearMath/btHashMap.h"
#include "LinearMath/btVector3.h" #include "LinearMath/btVector3.h"
#include "BulletCollision/CollisionShapes/btTriangleInfoMap.h"
///The btInternalEdgeUtility helps to avoid or reduce artifacts due to wrong collision normals caused by internal edges. ///The btInternalEdgeUtility helps to avoid or reduce artifacts due to wrong collision normals caused by internal edges.
///See also http://code.google.com/p/bullet/issues/detail?id=27 ///See also http://code.google.com/p/bullet/issues/detail?id=27
@@ -13,58 +15,7 @@ class btCollisionObject;
class btManifoldPoint; class btManifoldPoint;
class btIDebugDraw; class btIDebugDraw;
///for btTriangleInfo m_flags
#define TRI_INFO_V0V1_CONVEX 1
#define TRI_INFO_V1V2_CONVEX 2
#define TRI_INFO_V2V0_CONVEX 4
#define TRI_INFO_V0V1_SWAP_NORMALB 8
#define TRI_INFO_V1V2_SWAP_NORMALB 16
#define TRI_INFO_V2V0_SWAP_NORMALB 32
///The btTriangleInfo structure stores information to adjust collision normals to avoid collisions against internal edges
///it can be generated using
struct btTriangleInfo
{
btTriangleInfo()
{
m_edgeV0V1Angle = SIMD_2_PI;
m_edgeV1V2Angle = SIMD_2_PI;
m_edgeV2V0Angle = SIMD_2_PI;
m_flags=0;
}
int m_flags;
btScalar m_edgeV0V1Angle;
btScalar m_edgeV1V2Angle;
btScalar m_edgeV2V0Angle;
};
typedef btHashMap<btHashInt,btTriangleInfo> btInternalTriangleInfoMap;
///The btTriangleInfoMap stores edge angle information for some triangles. You can compute this information yourself or using btGenerateInternalEdgeInfo.
struct btTriangleInfoMap : public btInternalTriangleInfoMap
{
btScalar m_convexEpsilon;///used to determine if an edge or contact normal is convex, using the dot product
btScalar m_planarEpsilon; ///used to determine if a triangle edge is planar with zero angle
btScalar m_equalVertexThreshold; ///used to compute connectivity: if the distance between two vertices is smaller than m_equalVertexThreshold, they are considered to be 'shared'
btScalar m_edgeDistanceThreshold; ///used to determine edge contacts: if the closest distance between a contact point and an edge is smaller than this distance threshold it is considered to "hit the edge"
btScalar m_zeroAreaThreshold; ///used to determine if a triangle is degenerate (length squared of cross product of 2 triangle edges < threshold)
btTriangleInfoMap()
{
m_convexEpsilon = 0.00f;
m_planarEpsilon = 0.0001f;
m_equalVertexThreshold = btScalar(0.0001)*btScalar(0.0001);
m_edgeDistanceThreshold = btScalar(0.1);
m_zeroAreaThreshold = btScalar(0.0001)*btScalar(0.0001);
}
};
enum btInternalEdgeAdjustFlags enum btInternalEdgeAdjustFlags
{ {

View File

@@ -24,6 +24,7 @@ subject to the following restrictions:
btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh) btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh)
:btTriangleMeshShape(meshInterface), :btTriangleMeshShape(meshInterface),
m_bvh(0), m_bvh(0),
m_triangleInfoMap(0),
m_useQuantizedAabbCompression(useQuantizedAabbCompression), m_useQuantizedAabbCompression(useQuantizedAabbCompression),
m_ownsBvh(false) m_ownsBvh(false)
{ {
@@ -43,6 +44,7 @@ m_ownsBvh(false)
btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression,const btVector3& bvhAabbMin,const btVector3& bvhAabbMax,bool buildBvh) btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression,const btVector3& bvhAabbMin,const btVector3& bvhAabbMax,bool buildBvh)
:btTriangleMeshShape(meshInterface), :btTriangleMeshShape(meshInterface),
m_bvh(0), m_bvh(0),
m_triangleInfoMap(0),
m_useQuantizedAabbCompression(useQuantizedAabbCompression), m_useQuantizedAabbCompression(useQuantizedAabbCompression),
m_ownsBvh(false) m_ownsBvh(false)
{ {

View File

@@ -19,7 +19,7 @@ subject to the following restrictions:
#include "btTriangleMeshShape.h" #include "btTriangleMeshShape.h"
#include "btOptimizedBvh.h" #include "btOptimizedBvh.h"
#include "LinearMath/btAlignedAllocator.h" #include "LinearMath/btAlignedAllocator.h"
#include "btTriangleInfoMap.h"
///The btBvhTriangleMeshShape is a static-triangle mesh shape with several optimizations, such as bounding volume hierarchy and cache friendly traversal for PlayStation 3 Cell SPU. It is recommended to enable useQuantizedAabbCompression for better memory usage. ///The btBvhTriangleMeshShape is a static-triangle mesh shape with several optimizations, such as bounding volume hierarchy and cache friendly traversal for PlayStation 3 Cell SPU. It is recommended to enable useQuantizedAabbCompression for better memory usage.
///It takes a triangle mesh as input, for example a btTriangleMesh or btTriangleIndexVertexArray. The btBvhTriangleMeshShape class allows for triangle mesh deformations by a refit or partialRefit method. ///It takes a triangle mesh as input, for example a btTriangleMesh or btTriangleIndexVertexArray. The btBvhTriangleMeshShape class allows for triangle mesh deformations by a refit or partialRefit method.
@@ -29,6 +29,8 @@ ATTRIBUTE_ALIGNED16(class) btBvhTriangleMeshShape : public btTriangleMeshShape
{ {
btOptimizedBvh* m_bvh; btOptimizedBvh* m_bvh;
btTriangleInfoMap* m_triangleInfoMap;
bool m_useQuantizedAabbCompression; bool m_useQuantizedAabbCompression;
bool m_ownsBvh; bool m_ownsBvh;
bool m_pad[11];////need padding due to alignment bool m_pad[11];////need padding due to alignment
@@ -37,7 +39,7 @@ public:
BT_DECLARE_ALIGNED_ALLOCATOR(); BT_DECLARE_ALIGNED_ALLOCATOR();
btBvhTriangleMeshShape() : btTriangleMeshShape(0),m_bvh(0),m_ownsBvh(false) {m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;}; btBvhTriangleMeshShape() : btTriangleMeshShape(0),m_bvh(0),m_triangleInfoMap(0),m_ownsBvh(false) {m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;};
btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true); btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true);
///optionally pass in a larger bvh aabb, used for quantization. This allows for deformations within this aabb ///optionally pass in a larger bvh aabb, used for quantization. This allows for deformations within this aabb
@@ -73,7 +75,6 @@ public:
return m_bvh; return m_bvh;
} }
void setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& localScaling=btVector3(1,1,1)); void setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& localScaling=btVector3(1,1,1));
void buildOptimizedBvh(); void buildOptimizedBvh();
@@ -83,6 +84,21 @@ public:
return m_useQuantizedAabbCompression; return m_useQuantizedAabbCompression;
} }
void setTriangleInfoMap(btTriangleInfoMap* triangleInfoMap)
{
m_triangleInfoMap = triangleInfoMap;
}
const btTriangleInfoMap* getTriangleInfoMap() const
{
return m_triangleInfoMap;
}
btTriangleInfoMap* getTriangleInfoMap()
{
return m_triangleInfoMap;
}
virtual int calculateSerializeBufferSize() const; virtual int calculateSerializeBufferSize() const;
///fills the dataBuffer and returns the struct name (and 0 on failure) ///fills the dataBuffer and returns the struct name (and 0 on failure)
@@ -100,6 +116,8 @@ struct btTriangleMeshShapeData
btQuantizedBvhFloatData *m_quantizedFloatBvh; btQuantizedBvhFloatData *m_quantizedFloatBvh;
btQuantizedBvhDoubleData *m_quantizedDoubleBvh; btQuantizedBvhDoubleData *m_quantizedDoubleBvh;
btTriangleInfoMapData *m_triangleInfoMap;
float m_collisionMargin; float m_collisionMargin;
char m_pad3[4]; char m_pad3[4];

View File

@@ -0,0 +1,124 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2010 Erwin Coumans http://bulletphysics.org
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.
*/
#ifndef _BT_TRIANGLE_INFO_MAP_H
#define _BT_TRIANGLE_INFO_MAP_H
#include "LinearMath/btHashMap.h"
#include "LinearMath/btSerializer.h"
///for btTriangleInfo m_flags
#define TRI_INFO_V0V1_CONVEX 1
#define TRI_INFO_V1V2_CONVEX 2
#define TRI_INFO_V2V0_CONVEX 4
#define TRI_INFO_V0V1_SWAP_NORMALB 8
#define TRI_INFO_V1V2_SWAP_NORMALB 16
#define TRI_INFO_V2V0_SWAP_NORMALB 32
///The btTriangleInfo structure stores information to adjust collision normals to avoid collisions against internal edges
///it can be generated using
struct btTriangleInfo
{
btTriangleInfo()
{
m_edgeV0V1Angle = SIMD_2_PI;
m_edgeV1V2Angle = SIMD_2_PI;
m_edgeV2V0Angle = SIMD_2_PI;
m_flags=0;
}
int m_flags;
btScalar m_edgeV0V1Angle;
btScalar m_edgeV1V2Angle;
btScalar m_edgeV2V0Angle;
};
typedef btHashMap<btHashInt,btTriangleInfo> btInternalTriangleInfoMap;
///The btTriangleInfoMap stores edge angle information for some triangles. You can compute this information yourself or using btGenerateInternalEdgeInfo.
struct btTriangleInfoMap : public btInternalTriangleInfoMap
{
btScalar m_convexEpsilon;///used to determine if an edge or contact normal is convex, using the dot product
btScalar m_planarEpsilon; ///used to determine if a triangle edge is planar with zero angle
btScalar m_equalVertexThreshold; ///used to compute connectivity: if the distance between two vertices is smaller than m_equalVertexThreshold, they are considered to be 'shared'
btScalar m_edgeDistanceThreshold; ///used to determine edge contacts: if the closest distance between a contact point and an edge is smaller than this distance threshold it is considered to "hit the edge"
btScalar m_zeroAreaThreshold; ///used to determine if a triangle is degenerate (length squared of cross product of 2 triangle edges < threshold)
btTriangleInfoMap()
{
m_convexEpsilon = 0.00f;
m_planarEpsilon = 0.0001f;
m_equalVertexThreshold = btScalar(0.0001)*btScalar(0.0001);
m_edgeDistanceThreshold = btScalar(0.1);
m_zeroAreaThreshold = btScalar(0.0001)*btScalar(0.0001);
}
virtual int calculateSerializeBufferSize() const;
///fills the dataBuffer and returns the struct name (and 0 on failure)
virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
};
struct btTriangleInfoData
{
int m_flags;
float m_edgeV0V1Angle;
float m_edgeV1V2Angle;
float m_edgeV2V0Angle;
};
struct btTriangleInfoMapData
{
float m_convexEpsilon;
float m_planarEpsilon;
float m_equalVertexThreshold;
float m_edgeDistanceThreshold;
float m_zeroAreaThreshold;
int m_hashTableSize;
int *m_hashTablePtr;
int m_nextSize;
int *m_nextPtr;
int m_numValues;
btTriangleInfoData *m_valueArrayPtr;
int m_numKeys;
int *m_keyArrayPtr;
};
SIMD_FORCE_INLINE int btTriangleInfoMap::calculateSerializeBufferSize() const
{
return sizeof(btTriangleInfoMapData);
}
///fills the dataBuffer and returns the struct name (and 0 on failure)
SIMD_FORCE_INLINE const char* btTriangleInfoMap::serialize(void* dataBuffer, btSerializer* serializer) const
{
///todo
return 0;
}
#endif //_BT_TRIANGLE_INFO_MAP_H

View File

@@ -569,10 +569,10 @@ SIMD_FORCE_INLINE const char* btGeneric6DofConstraint::serialize(void* dataBuffe
int i; int i;
for (i=0;i<3;i++) for (i=0;i<3;i++)
{ {
dof->m_angularLowerLimit.m_floats[i] = m_angularLimits[i].m_loLimit; dof->m_angularLowerLimit.m_floats[i] = float(m_angularLimits[i].m_loLimit);
dof->m_angularUpperLimit.m_floats[i] = m_angularLimits[i].m_hiLimit; dof->m_angularUpperLimit.m_floats[i] = float(m_angularLimits[i].m_hiLimit);
dof->m_linearLowerLimit.m_floats[i] = m_linearLimits.m_lowerLimit[i]; dof->m_linearLowerLimit.m_floats[i] = float(m_linearLimits.m_lowerLimit[i]);
dof->m_linearUpperLimit.m_floats[i] = m_linearLimits.m_upperLimit[i]; dof->m_linearUpperLimit.m_floats[i] = float(m_linearLimits.m_upperLimit[i]);
} }
dof->m_useLinearReferenceFrameA = m_useLinearReferenceFrameA? 1 : 0; dof->m_useLinearReferenceFrameA = m_useLinearReferenceFrameA? 1 : 0;

View File

@@ -199,6 +199,7 @@ template <class Key, class Value>
class btHashMap class btHashMap
{ {
protected:
btAlignedObjectArray<int> m_hashTable; btAlignedObjectArray<int> m_hashTable;
btAlignedObjectArray<int> m_next; btAlignedObjectArray<int> m_next;