Serialization of btRigidBody

zoubi
Posts: 3
Joined: Mon Nov 05, 2012 11:20 am

Serialization of btRigidBody

Post by zoubi »

Hello all,

We are currently using version 2.78 of Bullet, and noticed a problem with the serialization / deserialization of bullet objects.

To serialize, we use this kind of code:

Code: Select all

btDefaultSerializer
        serializer( maximum_buffer_size );

    serializer.startSerialization();
    Object->getCollisionShape()->serializeSingleShape( &serializer );
    Object->serializeSingleObject( &serializer );
    serializer.finishSerialization();
(we also serializethe btMotionState instance attached to the rigid body)

To deserialize, we use the buffer given to us by the serialization, and we use the btBulletWorldImporter class, with its loadFileFromMemory function, and we assign our btRigidBody instance using the getRigidBodyByIndex function. We do this process for each of the instances we have.

The problem we noticed is that some (or all?) of the properties are not properly set after deserialization ( angularFactor for example).

After a quick look in the latest version of bullet, we noticed that you refactored the btBulletWorldImporter class, and that you manually set the friction and the restitution to the rigid bodies in convertAllObjects.

We are wondering if this is a know bug? Or maybe we don't use the correct way to deserialize the buffer we got from the serialization?


Why didn't you choose a symetric way of saving / loading data?
MaxDZ8
Posts: 149
Joined: Fri Jun 24, 2011 8:53 am

Re: Serialization of btRigidBody

Post by MaxDZ8 »

zoubi wrote:We are wondering if this is a know bug? Or maybe we don't use the correct way to deserialize the buffer we got from the serialization?
Why didn't you choose a symetric way of saving / loading data?
I also wonder why. The serialization looks symmetric to me, it's just incomplete.
For example, in 2.78 I'm also using, serialization does not save broadphase masks. This happens for a reason and I'm fine with it as I need to remap them anyway. It appears to me your setting could be saved with ease.
What I did is to have a derived class which injects proper code for the extra settings, which are pulled out another structure by order.
To my own surprise, this function override takes extremely little time. I guess the compiler de-virtualized the call and perhaps even inlined it.

I guess bullet serialization is intended to be a minimal baseline. It appears to make sense to me. In my assets, no more than 5% of the bodies require special set-up. Saving default values for the other 95% would be just wasteful.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Serialization of btRigidBody

Post by Erwin Coumans »

The serialization structures are decoupled from the actual Bullet structures. The Bullet serialization is symmetric in that it saves and loads the same serialization data.

For example, for a btRigidBody, the serialization data is btRigidBodyFloatData (or btRigidBodyDoubleData in double precision mode). btBulletFile will correctly import the btRigidBodyFloatData.

The btBulletWorldImporter indeed doesn't restore all data from btRigidBodyFloatData to btRigidBody. It should be trivial to add the missing functions. If you do so, please consider contributing this.