Serialization
Posted: Sun Dec 05, 2010 10:05 pm
Hi guys,
I'm currently trying to save and read collisionshape data in/from a file. To do this I tried to serialize the data like Erwin describes here.
The saving process seems to work well, but when I want to recreate the saved collisionshape with btBulletWorldImporter, it tells me that there aren't any collisionshapes. I stepped into the loading methods with the debugger - it seems that there is no parsing. Then I tried first to create a btBulletFile with my data from the file but this time I got an assertion.
My saving code:
The code for the loading
Has anyone an idea what I am doing wrong or could try next?
Thanks for your answers
I'm currently trying to save and read collisionshape data in/from a file. To do this I tried to serialize the data like Erwin describes here.
The saving process seems to work well, but when I want to recreate the saved collisionshape with btBulletWorldImporter, it tells me that there aren't any collisionshapes. I stepped into the loading methods with the debugger - it seems that there is no parsing. Then I tried first to create a btBulletFile with my data from the file but this time I got an assertion.
My saving code:
Code: Select all
// ...
int maxSerializeBufferSize = 1024*1024*5;
btDefaultSerializer Serializer(maxSerializeBufferSize);
Serializer.startSerialization();
if(m_pCollisionShape)
m_pCollisionShape->serializeSingleShape(&Serializer);
else
{
btBoxShape BoxShape(btVector3(2,2,2));
BoxShape.serializeSingleShape(&Serializer);
}
Serializer.finishSerialization();
FileOut.CollisionShapeDataSize = Serializer.getCurrentBufferSize();
std::ofstream Stream(GetFilename());
Stream.write((char*)&FileOut, sizeof(File));
Stream.write((char*)Serializer.getBufferPointer(), FileOut.CollisionShapeDataSize);Code: Select all
// ...
char* pCollisionShapeData = new char[FileIn.CollisionShapeDataSize];
Stream.read(pCollisionShapeData, FileIn.CollisionShapeDataSize);
btBulletWorldImporter Importer(0);
if(Importer.loadFileFromMemory(pCollisionShapeData, FileIn.CollisionShapeDataSize) && Importer.getNumCollisionShapes())
{
btCollisionShape* pShape = Importer.getCollisionShapeByIndex(0);
if(pShape->getShapeType() == BOX_SHAPE_PROXYTYPE)
m_pCollisionShape = new btBoxShape(*static_cast<btBoxShape*>(pShape));
else if(pShape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
m_pCollisionShape = new btBvhTriangleMeshShape(*static_cast<btBvhTriangleMeshShape*>(pShape));
}
else
{
// ...
}
delete[] pCollisionShapeData;Thanks for your answers