btCollisionObject->setCollisionShape(); - replace mesh

ideasman42
Posts: 4
Joined: Sat Jul 25, 2009 6:06 pm

btCollisionObject->setCollisionShape(); - replace mesh

Post by ideasman42 »

hi, recently I tried writing a patch for Blender3D to allow replacing/updating the physics mesh.
This works ok except for one thing.

http://blenderartists.org/forum/showthr ... 081&page=4

Replacing the mesh of an object has no impact if another object is resting on it (even with no-sleep option from blender enabled).

The solution to this I found was to run..

Code: Select all

  btSoftRigidDynamicsWorld* dw= GetPhysicsEnvironment()->getDynamicsWorld();
  dw->removeCollisionObject(m_object);
  dw->addCollisionObject(m_object, GetCollisionFilterGroup(), GetCollisionFilterMask());
Id prefer not to have to add/remove the object, but for one its not too bad, however, when using linked instances it has to check every object in the physics world that could share the shape - and add/remove that.

Whilst this is possible Id really rather avoid doing it, Is there some way to refresh an object and make all objects resting on it re-check their collision state again?
ideasman42
Posts: 4
Joined: Sat Jul 25, 2009 6:06 pm

Re: btCollisionObject->setCollisionShape(); - replace mesh

Post by ideasman42 »

Hi, answered my own question, clearing the proxy cache works :)

Code: Select all

	/* without this, an object can rest on the old physics mesh
	 * and not move to account for the physics mesh, even with 'nosleep' */ 
	btSoftRigidDynamicsWorld* dw= GetPhysicsEnvironment()->getDynamicsWorld();
	btCollisionObjectArray &obarr= dw->getCollisionObjectArray();
	btCollisionObject *ob;
	btBroadphaseProxy* proxy;

	for(int i= 0; i < obarr.size(); i++) {
		ob= obarr[i];
		if (ob->getCollisionShape() == newShape); {
			proxy = obarr[i]->getBroadphaseHandle();
			
			if(proxy)
				dw->getPairCache()->cleanProxyFromPairs(proxy,dw->getDispatcher());
		}
	}
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: btCollisionObject->setCollisionShape(); - replace mesh

Post by Erwin Coumans »

Indeed, cleanProxyFromPairs should do the job (or removeCollisionObject/addCollisionObject).

Thanks!
Erwin