Saving/Loading the world at runtime

sjeps
Posts: 6
Joined: Fri Jun 03, 2011 10:09 am

Saving/Loading the world at runtime

Post by sjeps »

Is ti possible to implement some kind of save/state for a world?
I would like to press a key to save the whole world to a backup, and load it when i press another, so i use it at run time. It is possible?
I'm trying something like this with no success:

Code: Select all

btDynamicsWorld * backw;

.
.
.

//save
case GLUT_KEY_F7 :{
backw=new btDiscreteDynamicsWorld((const btDiscreteDynamicsWorld &)m_dynamicsWorld);
}

//load
case GLUT_KEY_F8 :{
m_dynamicsWorld=new btDiscreteDynamicsWorld((const btDiscreteDynamicsWorld &)backw);
}
sjeps
Posts: 6
Joined: Fri Jun 03, 2011 10:09 am

Re: Saving/Loading the world at runtime

Post by sjeps »

up
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Saving/Loading the world at runtime

Post by Flix »

Never tried, but maybe the Bullet appSerializeDemo can be helpful.
The idea is to save the whole dynamic world to a file and to load it back later.
It may be possible to save/load it to/from memory: you may check it.

[Edit:] Before loading the world back, you probably need to delete (and clean) the current world you're using and to assign its pointer to the new one you're loading.
rraallvv
Posts: 30
Joined: Thu Feb 09, 2012 2:39 am

Re: Saving/Loading the world at runtime

Post by rraallvv »

Flix wrote:Never tried, but maybe the Bullet appSerializeDemo can be helpful.
The idea is to save the whole dynamic world to a file and to load it back later.
It may be possible to save/load it to/from memory: you may check it.

[Edit:] Before loading the world back, you probably need to delete (and clean) the current world you're using and to assign its pointer to the new one you're loading.
I'm using btDefaultSerializer to save a btDiscreteDynamicsWorld object then load it back using btBulletWorldImporter, the problem is that motion state and some flags are not restored back.

Is there a way to save and load every bit of information in a btRigidBody?
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Saving/Loading the world at runtime

Post by Flix »

rraallvv wrote:I'm using btDefaultSerializer to save a btDiscreteDynamicsWorld object then load it back using btBulletWorldImporter, the problem is that motion state and some flags are not restored back. Is there a way to save and load every bit of information in a btRigidBody?
You're right. Motion states are not saved, although they can be probably recreated after loading in most cases. (I think the reason is that usually users derive their own motion states, and Bullet does not know how to serialize user classes...). The main difficulty is that the Bullet file format is not so easy to extend (maybe because there are no code samples about it), and saving extra files side-by-side with .bullet files is not always comfortable.
Thus I think that the answer to your question is negative :?
rraallvv
Posts: 30
Joined: Thu Feb 09, 2012 2:39 am

Re: Saving/Loading the world at runtime

Post by rraallvv »

Flix wrote:You're right. Motion states are not saved...
I have a carousel or merry-go-round that the user can rotate, the object is a kinematic body, I change the body's position using the default motion state.

Do you know if it is posible to merge motion state and body's transform before serialization in order to be able to restore back the object's last position and rotation.

I'm using the following code, but it doesn't work

Code: Select all

	btDefaultMotionState* motionState = (btDefaultMotionState*) carousel->getMotionState();
		
	btTransform motionStateTransform;
	motionState->getWorldTransform(motionStateTransform);

	btTransform bodyTransform = carousel->getWorldTransform();
		
	bodyTransform = bodyTransform * motionStateTransform;
	//bodyTransform = motionStateTransform * bodyTransform;
		
	carousel->setWorldTransform(bodyTransform);