Hi all,
in the game I'm making, the map is made of cubes (it isn't a minecraft clone). There are lots of them, and although they're static bodies the perfomance is poor...
Is there any configuration to improve it?
Any advice is welcome... Thank you
Edit: First I created all the bodies with their respective shapes. Then I tried creating only one body with a compoundshape, but Im still getting bad FPS
Lots of static bodies
-
- Posts: 456
- Joined: Tue Dec 25, 2007 1:06 pm
Re: Lots of static bodies
Piter467 wrote:Is there any configuration to improve it?
Well, these are only my very generic suggestions (but I bet you already know them):Piter467 wrote:Edit: First I created all the bodies with their respective shapes. Then I tried creating only one body with a compoundshape, but Im still getting bad FPS
1) Unwrap your bodies from the btCompoundShape. AFAIK the btCompoundShape is not optimized for static objects.
2) Use: m_dynamicsWorld->setForceUpdateAllAabbs(false);
Create your bodies as static (not kinematic) and if you need to move them, call: m_dynamicsWorld->updateSingleAabb(myStaticBoxShapedCollisionObjectIveJustMoved);
3) [This optimizes memory only (not performance), and can be used only if the static boxes are not used in any constraints and if your code supports both btRigidBodies and 'naked' btCollisionObjects]: Add static objects as btCollisionObjects, in a similiar (the exact code has not been tested) way:
Code: Select all
btCollisionObject* co = new btCollisionObject();
co->setCollisionShape(myBoxShape);
co->setWorldTransform(T);
co->setActivationState(ISLAND_SLEEPING); // very important (otherwise bodies on it might not fall asleep!)
m_dynamicsWorld->addCollisionObject(co,btBroadphaseProxy::StaticFilter,btBroadphaseProxy::AllFilter&(~(btBroadphaseProxy::StaticFilter | btBroadphaseProxy::KinematicFilter)));
co->setCollisionFlags(co->getCollisionFlages|btCollisionObject::CF_STATIC_OBJECT); // This is an additional 'static' flag
co->setFriction(friction);
co->setRestitution(restitution);
4) Use a btDbvtBroadphase when you create your world (this should be the default).
5) [For memory only] If you use big btCollisionShapes, consider wrapping them inside btUniformScalingShapes/btScaledBvhTriangleMeshShapes when possible (although for plain btBoxShapes, I'm not sure this saves some byte or not); and of course reuse the same collision shapes whenever possible.
That's all that I use (but I've never needed to add a huge amount of static objects, so that the performance is poor, so far).
If you have other hints, please post them
-
- Posts: 2
- Joined: Sun Mar 09, 2014 2:35 pm
Re: Lots of static bodies
First of all, thank you Flix for your answer. I'm quite new to Bullet
I will try using
I will try using
since now what I do is join all the meshes (with a tool), export the obj, import it to Blender and then export the .bullet to load it later with the Bullet worldimporter. So, I think the only solution to my problem is to reduce the resolution of the mesh (.obj) by removing inner geometry, using the modifier Decimate, or by any other methods, so that it has less vertexes (= contact points).Flix wrote: co->setActivationState(ISLAND_SLEEPING); // very important (otherwise bodies on it might not fall asleep!)
co->setCollisionFlags(co->getCollisionFlages|btCollisionObject::CF_STATIC_OBJECT); // This is an additional 'static' flag
-
- Posts: 456
- Joined: Tue Dec 25, 2007 1:06 pm
Re: Lots of static bodies
Yes, you can just have a single btBvhTriangleMeshShape out of it if you want.Piter467 wrote:now what I do is join all the meshes (with a tool), export the obj, import it to Blender and then export the .bullet to load it later with the Bullet worldimporter. So, I think the only solution to my problem is to reduce the resolution of the mesh (.obj) by removing inner geometry, using the modifier Decimate, or by any other methods, so that it has less vertexes (= contact points).