Merging physics environments

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

Merging physics environments

Post by ideasman42 »

Hi, currently Im adding a feature to blender where you can merge 2 scenes. Currently its working with logic/render meshes but not physics data.

Currently Im going over the objects from one btSoftRigidDynamicsWorld, removing them and adding to another this isnt optimal but for now I just want to get something working..

Code: Select all

	btSoftRigidDynamicsWorld* dw= getDynamicsWorld();
	btSoftRigidDynamicsWorld* dw_other= other->getDynamicsWorld();

	btCollisionObjectArray &obarr= dw->getCollisionObjectArray();
	btCollisionObjectArray &obarr_other= dw->getCollisionObjectArray();

	btCollisionObject *ob;

	while(obarr_other.size()) {
		short int m_collisionFilterGroup = 0;
		short int m_collisionFilterMask = 0;

		ob= obarr_other[0];
		btBroadphaseProxy *proxy = ob->getBroadphaseHandle();

		if(proxy) {
			m_collisionFilterGroup= proxy->m_collisionFilterGroup;
			m_collisionFilterMask= proxy->m_collisionFilterMask;
		}

		dw_other->removeCollisionObject(ob);

		/* add to the new scene */
		dw->addCollisionObject(ob, m_collisionFilterGroup, m_collisionFilterMask);
	}
This is crashing in bullet however Im not asking to debug this problem.... Im just wondering if anyone has done this before and how they did it... OR, does bullet provide a better way to do this.

Incase the crash is useful, here it is.

Code: Select all

	Thread [1] (Suspended: Signal 'SIGSEGV' received. Description: Segmentation fault.)	
	25 removeleaf() /mnt/test/storage/music/blender-svn/blender25/extern/bullet2/src/BulletCollision/BroadphaseCollision/btDbvt.cpp:184 0x089d0bbd	
	24 btDbvt::remove() /mnt/test/storage/music/blender-svn/blender25/extern/bullet2/src/BulletCollision/BroadphaseCollision/btDbvt.cpp:557 0x089d2016	
	23 btDbvtBroadphase::destroyProxy() /mnt/test/storage/music/blender-svn/blender25/extern/bullet2/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp:198 0x089cd28c	
	22 btCollisionWorld::removeCollisionObject() /mnt/test/storage/music/blender-svn/blender25/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp:214 0x089f1f08	
	21 CcdPhysicsEnvironment::MergeEnvironment() /mnt/test/storage/music/blender-svn/blender25/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp:1774 0x08873d9c	
	20 KX_Scene::MergeScene() /mnt/test/storage/music/blender-svn/blender25/source/gameengine/Ketsji/KX_Scene.cpp:1706 0x088f74cd	
	19 KX_BlenderSceneConverter::LinkBlendFile() /mnt/test/storage/music/blender-svn/blender25/source/gameengine/Converter/KX_BlenderSceneConverter.cpp:1088 0x08839b90	
	18 gLoadLibrary() /mnt/test/storage/music/blender-svn/blender25/source/gameengine/Ketsji/KX_PythonInit.cpp:578 0x088deca4	
	17 PyCFunction_Call() /root/Python-3.1/Objects/methodobject.c:81 0xb787ba13	
Parent is NULL in the last line of this function, but perhaps this is because Im using a bad method.

Code: Select all

static btDbvtNode*				removeleaf(	btDbvt* pdbvt,
										   btDbvtNode* leaf)
{
	if(leaf==pdbvt->m_root)
	{
		pdbvt->m_root=0;
		return(0);
	}
	else
	{
		btDbvtNode*	parent=leaf->parent;
		btDbvtNode*	prev=parent->parent;