How to completely disable/enable a btRigidBody

Post Reply
mogumbo
Posts: 6
Joined: Tue May 24, 2016 8:15 pm

How to completely disable/enable a btRigidBody

Post by mogumbo »

I have a simulation with a long chain of rigid bodies. It's almost working except I need to be able to disable most of the bodies most of the time. I am able to sort of do this by using forceActivationState(DISABLE_SIMULATION) and later enable them with forceActivationState(ACTIVE_TAG). This causes disabled bodies to be disconnected from one another, however they appear to still be colliding with one another and still getting influenced by bodies that have not been disabled. Also, the amount of CPU time used stays high as if all bodies are active in the simulation.

I tried btDiscreteDynamicsWorld::removeRigidBody() to completely remove bodies from the simulation, but it causes an assertion in Bullet.

Also tried btDiscreteDynamicsWorld::removeConstraint() to explicitly remove the constraints connected to disabled bodies. This causes the whole simulation to go very unstable very fast.

Is there a correct way to remove bodies from and insert them back into the simulation?
MRENOU
Posts: 9
Joined: Thu May 26, 2016 11:50 am

Re: How to completely disable/enable a btRigidBody

Post by MRENOU »

Hi mogumbo,

In fact you need to remove constraint before removing rigidbodies, using world->removeConstraint() and world->removeRigidBody().

For example, if you have an hinge constraint between bodyA and bodyB, you will do :

Code: Select all

world->removeConstraint(hingeConstraint);

world->removeRigidBody(bodyA);
world->removeRigidBody(bodyB);
And you will add your bodies the same way you did it before.

Hope this would help.
Martin
mogumbo
Posts: 6
Joined: Tue May 24, 2016 8:15 pm

Re: How to completely disable/enable a btRigidBody

Post by mogumbo »

Thanks for the response. It seems I can avoid crashes by removing both the rigid body and the constraint instead of only the rigid body. However, the order doesn't appear to make any difference.

My simulation still goes wildly unstable if I remove constraints, so I'll keep trying to figure that out for now.
mogumbo
Posts: 6
Joined: Tue May 24, 2016 8:15 pm

Re: How to completely disable/enable a btRigidBody

Post by mogumbo »

Okay, I figured out the instability. I wasn't setting the disableCollisionsBetweenLinkedBodies flag when re-adding constraints to the scene.

So the answer to my original question appears to be: to completely disable a rigid body you must completely remove it and its constraints from the scene. I'm still curious what all the enable/disable logic is for if it can't completely disable a rigid body.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: How to completely disable/enable a btRigidBody

Post by benelot »

The enable/disable logic (if you mean disable deactivation etc) is to reduce the load on the physics engine. If an object stops moving, it deactivates, and is only activated again if hit by another moving object.
Post Reply