Add support to serialize btOptimizedBvh/btQuantizedBvh for a btBvhTriangleMeshShape (using the new btSerializer). This is a new implementation, with full cross-platform support.
So it is different from the in-place method (btQuantizedBvh::serializeInPlace/deserializeInPlace). It is also possible to serialize/deserialize just the bvh, using the btSerializer (needs some code snippet/helper) See also http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=4770
This commit is contained in:
@@ -17,6 +17,7 @@ subject to the following restrictions:
|
||||
|
||||
#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btOptimizedBvh.h"
|
||||
#include "LinearMath/btSerializer.h"
|
||||
|
||||
///Bvh Concave triangle mesh is a static-triangle mesh shape with Bounding Volume Hierarchy optimization.
|
||||
///Uses an interface to access the triangles to allow for sharing graphics/physics triangles.
|
||||
@@ -364,3 +365,54 @@ void btBvhTriangleMeshShape::setOptimizedBvh(btOptimizedBvh* bvh, const btVect
|
||||
}
|
||||
|
||||
|
||||
|
||||
///fills the dataBuffer and returns the struct name (and 0 on failure)
|
||||
const char* btBvhTriangleMeshShape::serialize(void* dataBuffer, btSerializer* serializer) const
|
||||
{
|
||||
btTriangleMeshShapeData* trimeshData = (btTriangleMeshShapeData*) dataBuffer;
|
||||
|
||||
btCollisionShape::serialize(&trimeshData->m_collisionShapeData,serializer);
|
||||
|
||||
m_meshInterface->serialize(&trimeshData->m_meshInterface, serializer);
|
||||
|
||||
trimeshData->m_collisionMargin = float(m_collisionMargin);
|
||||
|
||||
if (m_bvh)
|
||||
{
|
||||
void* chunk = serializer->findPointer(m_bvh);
|
||||
if (chunk)
|
||||
{
|
||||
#ifdef BT_USE_DOUBLE_PRECISION
|
||||
trimeshData->m_quantizedDoubleBvh = (btQuantizedBvhData*)chunk;
|
||||
trimeshData->m_quantizedFloatBvh = 0;
|
||||
#else
|
||||
trimeshData->m_quantizedFloatBvh = (btQuantizedBvhData*)chunk;
|
||||
trimeshData->m_quantizedDoubleBvh= 0;
|
||||
#endif //BT_USE_DOUBLE_PRECISION
|
||||
} else
|
||||
{
|
||||
|
||||
#ifdef BT_USE_DOUBLE_PRECISION
|
||||
trimeshData->m_quantizedDoubleBvh = (btQuantizedBvhData*)m_bvh;
|
||||
trimeshData->m_quantizedFloatBvh = 0;
|
||||
#else
|
||||
trimeshData->m_quantizedFloatBvh = (btQuantizedBvhData*)m_bvh;
|
||||
trimeshData->m_quantizedDoubleBvh= 0;
|
||||
#endif //BT_USE_DOUBLE_PRECISION
|
||||
|
||||
int sz = m_bvh->calculateSerializeBufferSizeNew();
|
||||
btChunk* chunk = serializer->allocate(sz,1);
|
||||
const char* structType = m_bvh->serialize(chunk->m_oldPtr, serializer);
|
||||
serializer->finalizeChunk(chunk,structType,BT_QUANTIZED_BVH_CODE,m_bvh);
|
||||
}
|
||||
} else
|
||||
{
|
||||
trimeshData->m_quantizedFloatBvh = 0;
|
||||
trimeshData->m_quantizedDoubleBvh = 0;
|
||||
}
|
||||
|
||||
return "btTriangleMeshShapeData";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -83,32 +83,35 @@ public:
|
||||
return m_useQuantizedAabbCompression;
|
||||
}
|
||||
|
||||
//virtual int calculateSerializeBufferSize();
|
||||
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;
|
||||
|
||||
virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
|
||||
|
||||
};
|
||||
|
||||
#if 0
|
||||
struct btBvhTriangleMeshShapeData
|
||||
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
|
||||
struct btTriangleMeshShapeData
|
||||
{
|
||||
btCollisionShapeData m_collisionShapeData;
|
||||
|
||||
btTriangleMeshShapeData m_trimeshData;
|
||||
|
||||
//btOptimizedBvhData m_bvh;
|
||||
btStridingMeshInterfaceData m_meshInterface;
|
||||
|
||||
char m_useQuantizedAabbCompression;
|
||||
char m_ownsBvh;
|
||||
btQuantizedBvhFloatData *m_quantizedFloatBvh;
|
||||
btQuantizedBvhDoubleData *m_quantizedDoubleBvh;
|
||||
|
||||
float m_collisionMargin;
|
||||
|
||||
char m_pad3[4];
|
||||
|
||||
};
|
||||
|
||||
SIMD_FORCE_INLINE int btBvhTriangleMeshShape::calculateSerializeBufferSize()
|
||||
|
||||
SIMD_FORCE_INLINE int btBvhTriangleMeshShape::calculateSerializeBufferSize() const
|
||||
{
|
||||
return sizeof(btBvhTriangleMeshShapeData);
|
||||
return sizeof(btTriangleMeshShapeData);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif //BVH_TRIANGLE_MESH_SHAPE_H
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
void updateBvhNodes(btStridingMeshInterface* meshInterface,int firstNode,int endNode,int index);
|
||||
|
||||
/// Data buffer MUST be 16 byte aligned
|
||||
virtual bool serialize(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian) const
|
||||
virtual bool serializeInPlace(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian) const
|
||||
{
|
||||
return btQuantizedBvh::serialize(o_alignedDataBuffer,i_dataBufferSize,i_swapEndian);
|
||||
|
||||
|
||||
@@ -209,16 +209,3 @@ btVector3 btTriangleMeshShape::localGetSupportingVertex(const btVector3& vec) co
|
||||
}
|
||||
|
||||
|
||||
///fills the dataBuffer and returns the struct name (and 0 on failure)
|
||||
const char* btTriangleMeshShape::serialize(void* dataBuffer, btSerializer* serializer) const
|
||||
{
|
||||
btTriangleMeshShapeData* trimeshData = (btTriangleMeshShapeData*) dataBuffer;
|
||||
|
||||
btCollisionShape::serialize(&trimeshData->m_collisionShapeData,serializer);
|
||||
|
||||
m_meshInterface->serialize(&trimeshData->m_meshInterface, serializer);
|
||||
|
||||
trimeshData->m_collisionMargin = float(m_collisionMargin);
|
||||
|
||||
return "btTriangleMeshShapeData";
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ subject to the following restrictions:
|
||||
#include "btStridingMeshInterface.h"
|
||||
|
||||
|
||||
|
||||
///The btTriangleMeshShape is an internal concave triangle mesh interface. Don't use this class directly, use btBvhTriangleMeshShape instead.
|
||||
class btTriangleMeshShape : public btConcaveShape
|
||||
{
|
||||
@@ -80,31 +79,10 @@ public:
|
||||
//debugging
|
||||
virtual const char* getName()const {return "TRIANGLEMESH";}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
|
||||
struct btTriangleMeshShapeData
|
||||
{
|
||||
btCollisionShapeData m_collisionShapeData;
|
||||
|
||||
btStridingMeshInterfaceData m_meshInterface;
|
||||
|
||||
float m_collisionMargin;
|
||||
|
||||
char m_padding[4];
|
||||
};
|
||||
|
||||
|
||||
SIMD_FORCE_INLINE int btTriangleMeshShape::calculateSerializeBufferSize() const
|
||||
{
|
||||
return sizeof(btTriangleMeshShapeData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user