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:
erwin.coumans
2010-02-23 09:03:46 +00:00
parent e4c3c2a1a2
commit 41e9115bca
15 changed files with 929 additions and 451 deletions

View File

@@ -162,6 +162,11 @@ void btBulletFile::parseData()
m_constraints.push_back((bStructHandle*) id);
}
if (dataChunk.code == BT_QUANTIZED_BVH_CODE)
{
m_bvhs.push_back((bStructHandle*) id);
}
if (dataChunk.code == BT_COLLISIONOBJECT_CODE)
{
m_collisionObjects.push_back((bStructHandle*) id);

View File

@@ -25,6 +25,8 @@ subject to the following restrictions:
#define BT_RIGIDBODY_CODE MAKE_ID('R','B','D','Y')
#define BT_CONSTRAINT_CODE MAKE_ID('C','O','N','S')
#define BT_BOXSHAPE_CODE MAKE_ID('B','O','X','S')
#define BT_QUANTIZED_BVH_CODE MAKE_ID('Q','B','V','H')
#define BT_SHAPE_CODE MAKE_ID('S','H','A','P')
@@ -48,6 +50,8 @@ namespace bParse {
btAlignedObjectArray<bStructHandle*> m_collisionShapes;
btAlignedObjectArray<bStructHandle*> m_constraints;
btAlignedObjectArray<bStructHandle*> m_bvhs;
btBulletFile();

View File

@@ -282,7 +282,22 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
btVector3 scaling; scaling.deSerializeFloat(trimesh->m_meshInterface.m_scaling);
meshInterface->setScaling(scaling);
btCollisionShape* trimeshShape = createBvhTriangleMeshShape(meshInterface);
btOptimizedBvh* bvh = 0;
if (trimesh->m_quantizedFloatBvh)
{
bvh = createOptimizedBvh();
bvh->deSerializeFloat(*trimesh->m_quantizedFloatBvh);
}
if (trimesh->m_quantizedDoubleBvh)
{
bvh = createOptimizedBvh();
bvh->deSerializeDouble(*trimesh->m_quantizedDoubleBvh);
}
btCollisionShape* trimeshShape = createBvhTriangleMeshShape(meshInterface,bvh);
trimeshShape->setMargin(trimesh->m_collisionMargin);
shape = trimeshShape;
@@ -750,8 +765,20 @@ btTriangleIndexVertexArray* btBulletWorldImporter::createTriangleMeshContainer()
{
return new btTriangleIndexVertexArray();
}
btCollisionShape* btBulletWorldImporter::createBvhTriangleMeshShape(btStridingMeshInterface* trimesh)
btOptimizedBvh* btBulletWorldImporter::createOptimizedBvh()
{
return new btOptimizedBvh();
}
btCollisionShape* btBulletWorldImporter::createBvhTriangleMeshShape(btStridingMeshInterface* trimesh, btOptimizedBvh* bvh)
{
if (bvh)
{
btBvhTriangleMeshShape* bvhTriMesh = new btBvhTriangleMeshShape(trimesh,bvh->isQuantized(), false);
bvhTriMesh->setOptimizedBvh(bvh);
return bvhTriMesh;
}
return new btBvhTriangleMeshShape(trimesh,true);
}
btCollisionShape* btBulletWorldImporter::createConvexTriangleMeshShape(btStridingMeshInterface* trimesh)

View File

@@ -36,6 +36,7 @@ class btTriangleIndexVertexArray;
class btStridingMeshInterface;
struct btStridingMeshInterfaceData;
class btGImpactMeshShape;
class btOptimizedBvh;
namespace bParse
{
@@ -114,7 +115,8 @@ public:
virtual btCollisionShape* createCylinderShapeY(btScalar radius,btScalar height);
virtual btCollisionShape* createCylinderShapeZ(btScalar radius,btScalar height);
virtual class btTriangleIndexVertexArray* createTriangleMeshContainer();
virtual btCollisionShape* createBvhTriangleMeshShape(btStridingMeshInterface* trimesh);
virtual btCollisionShape* createBvhTriangleMeshShape(btStridingMeshInterface* trimesh, btOptimizedBvh* bvh);
virtual btOptimizedBvh* createOptimizedBvh();
virtual btCollisionShape* createConvexTriangleMeshShape(btStridingMeshInterface* trimesh);
virtual btGImpactMeshShape* createGimpactShape(btStridingMeshInterface* trimesh);
virtual class btConvexHullShape* createConvexHullShape();

View File

@@ -122,13 +122,14 @@ typedef unsigned long uintptr_t;
#include "LinearMath/btVector3.h"
#include "LinearMath/btMatrix3x3.h"
#include "LinearMath/btTransform.h"
#include "BulletCollision/BroadphaseCollision/btQuantizedBvh.h"
#include "BulletCollision/CollisionShapes/btCollisionShape.h"
#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
#include "BulletCollision/CollisionShapes/btConvexInternalShape.h"
#include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
#include "BulletCollision/CollisionShapes/btConvexHullShape.h"
#include "BulletCollision/CollisionShapes/btStridingMeshInterface.h"
#include "BulletCollision/CollisionShapes/btTriangleMeshShape.h"
#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
#include "BulletCollision/CollisionShapes/btCylinderShape.h"
#include "BulletCollision/CollisionShapes/btCapsuleShape.h"
@@ -160,12 +161,13 @@ char *includefiles[] = {
"../../../src/LinearMath/btVector3.h",
"../../../src/LinearMath/btMatrix3x3.h",
"../../../src/LinearMath/btTransform.h",
"../../../src/BulletCollision/BroadphaseCollision/btQuantizedBvh.h",
"../../../src/BulletCollision/CollisionShapes/btCollisionShape.h",
"../../../src/BulletCollision/CollisionShapes/btStaticPlaneShape.h",
"../../../src/BulletCollision/CollisionShapes/btConvexInternalShape.h",
"../../../src/BulletCollision/CollisionShapes/btMultiSphereShape.h",
"../../../src/BulletCollision/CollisionShapes/btStridingMeshInterface.h",
"../../../src/BulletCollision/CollisionShapes/btTriangleMeshShape.h",
"../../../src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h",
"../../../src/BulletCollision/CollisionShapes/btCompoundShape.h",
"../../../src/BulletCollision/CollisionShapes/btCylinderShape.h",
"../../../src/BulletCollision/CollisionShapes/btCapsuleShape.h",