More work on serialization and BulletFileLoader
This commit is contained in:
@@ -1252,6 +1252,28 @@ void btCollisionWorld::serializeCollisionObjects(btDefaultSerializer* serializer
|
||||
chunk->m_oldPtr = colObj;
|
||||
}
|
||||
}
|
||||
|
||||
///keep track of shapes already serialized
|
||||
btHashMap<btHashPtr,btCollisionShape*> serializedShapes;
|
||||
|
||||
for (i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
btCollisionObject* colObj = m_collisionObjects[i];
|
||||
btCollisionShape* shape = colObj->getCollisionShape();
|
||||
|
||||
if (!serializedShapes.find(shape))
|
||||
{
|
||||
serializedShapes.insert(shape,shape);
|
||||
//serialize all collision shapes
|
||||
int len = shape->calculateSerializeBufferSize();
|
||||
btChunk* chunk = serializer->allocate(len,1);
|
||||
const char* structType = shape->serialize(chunk->m_oldPtr);
|
||||
chunk->m_dna_nr = serializer->getReverseType(structType);
|
||||
chunk->m_chunkCode = BT_SHAPE_CODE;
|
||||
chunk->m_oldPtr = shape;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1273,18 +1295,6 @@ void btCollisionWorld::serialize(btDefaultSerializer* serializer)
|
||||
|
||||
serializeCollisionObjects(serializer);
|
||||
|
||||
#if 0
|
||||
{
|
||||
//serialize all collision shapes
|
||||
int len = boxShape->calculateSerializeBufferSize();
|
||||
btChunk* chunk = serializer->allocate(len,1);
|
||||
const char* structType = boxShape->serialize(chunk->m_oldPtr);
|
||||
chunk->m_dna_nr = serializer->getReverseType(structType);
|
||||
chunk->m_chunkCode = BT_BOXSHAPE_CODE;
|
||||
chunk->m_oldPtr = boxShape;
|
||||
}
|
||||
#endif
|
||||
|
||||
serializer->writeDNA();
|
||||
}
|
||||
|
||||
|
||||
@@ -310,43 +310,9 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual int calculateSerializeBufferSize();
|
||||
|
||||
///fills the dataBuffer and returns the struct name (and 0 on failure)
|
||||
virtual const char* serialize(void* dataBuffer) const;
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct btBoxShapeData
|
||||
{
|
||||
btCollisionShapeData m_collisionShapeData;
|
||||
btVector3Data m_halfExtents;
|
||||
btVector3Data m_localScaling;
|
||||
};
|
||||
|
||||
|
||||
|
||||
SIMD_FORCE_INLINE int btBoxShape::calculateSerializeBufferSize()
|
||||
{
|
||||
return sizeof(btBoxShapeData);
|
||||
}
|
||||
|
||||
///fills the dataBuffer and returns the struct name (and 0 on failure)
|
||||
SIMD_FORCE_INLINE const char* btBoxShape::serialize(void* dataBuffer) const
|
||||
{
|
||||
btBoxShapeData* boxData = (btBoxShapeData*) dataBuffer;
|
||||
btCollisionShape::serialize(&boxData->m_collisionShapeData);
|
||||
|
||||
m_implicitShapeDimensions.serialize(boxData->m_halfExtents);
|
||||
m_localScaling.serialize(boxData->m_localScaling);
|
||||
return "btBoxShapeData";
|
||||
}
|
||||
|
||||
|
||||
#endif //OBB_BOX_MINKOWSKI_H
|
||||
|
||||
|
||||
|
||||
@@ -109,11 +109,54 @@ public:
|
||||
btAssert(0);
|
||||
}
|
||||
|
||||
virtual int calculateSerializeBufferSize();
|
||||
|
||||
///fills the dataBuffer and returns the struct name (and 0 on failure)
|
||||
virtual const char* serialize(void* dataBuffer) const;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
struct btConvexInternalShapeData
|
||||
{
|
||||
btCollisionShapeData m_collisionShapeData;
|
||||
|
||||
btVector3Data m_localScaling;
|
||||
|
||||
btVector3Data m_implicitShapeDimensions;
|
||||
|
||||
btScalar m_collisionMargin;
|
||||
|
||||
char m_padding[4];
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
SIMD_FORCE_INLINE int btConvexInternalShape::calculateSerializeBufferSize()
|
||||
{
|
||||
return sizeof(btConvexInternalShapeData);
|
||||
}
|
||||
|
||||
///fills the dataBuffer and returns the struct name (and 0 on failure)
|
||||
SIMD_FORCE_INLINE const char* btConvexInternalShape::serialize(void* dataBuffer) const
|
||||
{
|
||||
btConvexInternalShapeData* shapeData = (btConvexInternalShapeData*) dataBuffer;
|
||||
btCollisionShape::serialize(&shapeData->m_collisionShapeData);
|
||||
|
||||
m_implicitShapeDimensions.serialize(shapeData->m_implicitShapeDimensions);
|
||||
m_localScaling.serialize(shapeData->m_localScaling);
|
||||
shapeData->m_collisionMargin = m_collisionMargin;
|
||||
|
||||
return "btConvexInternalShapeData";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///btConvexInternalAabbCachingShape adds local aabb caching for convex shapes, to avoid expensive bounding box calculations
|
||||
class btConvexInternalAabbCachingShape : public btConvexInternalShape
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user