Sleeping/Waking callbacks

optime
Posts: 7
Joined: Mon Oct 30, 2006 7:44 pm

Sleeping/Waking callbacks

Post by optime »

Hi,

I am looking for a way to manually put btRigidBodies manually to sleep but have not found anything in the docs. Did I miss it?

Also I would like to set callbacks to be called when a btRigidBody wakes up and when it is beeing put to sleep by Bullet. I can leverage several optimizations in the graphics engine this way. Is such functionality already implemented?

Thanks!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Sleeping/Waking callbacks

Post by Erwin Coumans »

You can call

Code: Select all

body->setActivationState(ACTIVE_TAG)
to activate objects.

You can also prevent certain objects from ever falling asleep/get deactivated by calling:

Code: Select all

body->setActivationState(DISABLE_DEACTIVATION)
btMotionState::setWorldTransform gets only called by Bullet for active objects, so your derived version of btMotionState (for example BulletC4MotionState or btDefaultMotionState) can be used to detect active objects.

There is no put-to-sleep callback yet, I'll propose some implementation.
Thanks,
Erwin
optime wrote:Hi,

I am looking for a way to manually put btRigidBodies manually to sleep but have not found anything in the docs. Did I miss it?

Also I would like to set callbacks to be called when a btRigidBody wakes up and when it is beeing put to sleep by Bullet. I can leverage several optimizations in the graphics engine this way. Is such functionality already implemented?

Thanks!
optime
Posts: 7
Joined: Mon Oct 30, 2006 7:44 pm

Post by optime »

Thanks for looking into this. PutToSleep is useful to me because there is a huge load on the simulation when loading a new world in game (stacked objects that are fine visually and need only to be active when they are subject to force other then gravity for example).

What about the onWake/onSleep callbacks?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

optime wrote:Thanks for looking into this. PutToSleep is useful to me because there is a huge load on the simulation when loading a new world in game (stacked objects that are fine visually and need only to be active when they are subject to force other then gravity for example).

What about the onWake/onSleep callbacks?
the btMotionState 'setWorldTransform' is only called for awake objects, isn't that enough for a 'onWake' detection?

I can add virtual deactivation method in btMotionState that you can override to do things for objects that fall asleep (or even disable the sleeping for another frame).

Is that OK?
Thanks,
Erwin
optime
Posts: 7
Joined: Mon Oct 30, 2006 7:44 pm

Post by optime »

Erwin Coumans wrote: the btMotionState 'setWorldTransform' is only called for onWake, isn't that enough for a 'onWake' detection?
It is sufficient. I would like to call functions that reset shadow caches and the like whenever an object is awaking, calling those more often is not that optimal. But you are right, I can track changes of object state in the app myself this way. Thanks once again.
Erwin Coumans wrote: I can add virtual deactivation method in btMotionState that you can override to do things for objects that fall asleep (or even disable the sleeping for another frame).
This would be very useful!