Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri May 25, 2012 2:45 am 
Offline

Joined: Fri May 25, 2012 2:34 am
Posts: 2
Hi guys,
I'm pretty new to bullet and I'm writing a simple serializer/deserializer. I'm finding that I can serialize/deserialize all my rigidbodies and collision shapes but when I call SetUserPointer with some custom data ( a char* with a GUID in it ) on the object, this user data doesnt seem to serialize and I just get a null pointer on loading for the user pointer. Anyone used this functionality and seen similar results? Presumably, I doing something wrong?

Here is an extract of the code: (Notice I tried to set user pointer on the shape and the rigidbody to no success.
.......

btTriangleMesh* trimesh = new btTriangleMesh();

for ( unsigned int i=0;i<pMeshData->m_positions.size()/3;i+=3)
{
btVector3 vertex1 = btVector3(static_cast<float>(pMeshData->m_positions[i].mData[0]),static_cast<float>(pMeshData->m_positions[i].mData[1]),static_cast<float>(pMeshData->m_positions[i].mData[2]));
btVector3 vertex2 = btVector3(static_cast<float>(pMeshData->m_positions[i+1].mData[0]),static_cast<float>(pMeshData->m_positions[i+1].mData[1]),static_cast<float>(pMeshData->m_positions[i+2].mData[2]));
btVector3 vertex3 = btVector3(static_cast<float>(pMeshData->m_positions[i+2].mData[0]),static_cast<float>(pMeshData->m_positions[i+2].mData[1]),static_cast<float>(pMeshData->m_positions[i+2].mData[2]));

trimesh->addTriangle(vertex1,vertex2,vertex3);
}


bool useQuantizedAabbCompression = true;
btBvhTriangleMeshShape * physicShape = new btBvhTriangleMeshShape(trimesh, useQuantizedAabbCompression);

btTransform shapeTransform;
shapeTransform.setIdentity();

// Create MotionState and RigidBody object for the ground shape
btDefaultMotionState* motionState = new btDefaultMotionState(shapeTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(0, motionState, physicShape, btVector3(0, 0, 0));
btRigidBody* pRigidBody = new btRigidBody(rbInfo);

struct UserData
{
char mName[64];
};
UserData* userData = new UserData();

snprintf (userData->mName,64,"%s",stringGUID);

pRigidBody->getCollisionShape()->setUserPointer(userData);
pRigidBody->setUserPointer(userData);

m_dynamicsWorld->addRigidBody(pRigidBody);
m_collisionShapes.push_back(physicShape);


///serializing the data.

int maxSerializeBufferSize = 1024*1024*1;
btDefaultSerializer* serializer = new btDefaultSerializer(maxSerializeBufferSize);

for (int i=0;i<m_collisionShapes.size();i++)
{
char* name = new char[20];

sprintf(name,"name%d",i);
serializer->registerNameForPointer(m_collisionShapes[i],name);
}

m_dynamicsWorld->serialize(serializer);

const unsigned char* pBuffer = serializer->getBufferPointer());
const unsigned int worldBufferSize = serializer->getCurrentBufferSize();


Top
 Profile  
 
PostPosted: Fri May 25, 2012 7:50 am 
Offline

Joined: Fri Jun 24, 2011 8:53 am
Posts: 130
Of course it does not serialize. How would you serialize an opaque blob which you know nothing about? Even supposing we just serialize the pointer value itself, how would we use it - it carries no information at all after loading, it would just be a random number.

You have to enumerate all the pointers yourself, serialize the pointed objects and build a way to restore those associations after loading. Or perhaps while loading, by modifying the provided deserializer code.

EDIT: I checked now and it seems there might be a function doing that for you, btDefaultSerializer provides a function registerNameForPointer , I'm not sure what it does exactly but I'd totally look in that direction!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group