Sign in to follow this  

Using Bullet Physics - Optimizing Scenes with Static Mesh

This topic is 1199 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

I am building an engine that supports importing mesh from large FBX files. I can get the scene to load fine and have basic interaction with the scene but when I start attempting to interact with the scene even using basic objects I get serious performance degradation.

My goal is to get a walkable scene with static mesh of a range of sizes with basic interactivity.

Therefore I am hoping there may be some optimization tips folks can share. I will also post some of the code below for how I am using Bullet.

  • I am using "btBvhTriangleMeshShape" objects for my scene and initializing them using a "btTriangleIndexVertexArray" object for initialization.
  • I was thinking about using "btConvexHullShape" objects instead but then I generally lose certain information such as collision detection for objects with holes in it like walls with windows, etc.
  • I also wanted to switch to the MultiThreaded version of Bullet but the demo doesn't compile, I get errors like the following:
    1>MultiThreadedDemo.obj : error LNK2019: unresolved external symbol "public: __thiscall SpuGatheringCollisionDispatcher::SpuGatheringCollisionDispatcher(class btThreadSupportInterface *,unsigned int,class btCollisionConfiguration *)" (??0SpuGatheringCollisionDispatcher@@QAE@PAVbtThreadSupportInterface@@IPAVbtCollisionConfiguration@@@Z) referenced in function "public: virtual void __thiscall MultiThreadedDemo::initPhysics(void)" (?initPhysics@MultiThreadedDemo@@UAEXXZ)
    1>MultiThreadedDemo.obj : error LNK2019: unresolved external symbol "public: __thiscall Win32ThreadSupport::Win32ThreadSupport(struct Win32ThreadSupport::Win32ThreadConstructionInfo const &)" (??0Win32ThreadSupport@@QAE@ABUWin32ThreadConstructionInfo@0@@Z) referenced in function "class btThreadSupportInterface * __cdecl createSolverThreadSupport(int)" (?createSolverThreadSupport@@YAPAVbtThreadSupportInterface@@H@Z)
    1>MultiThreadedDemo.obj : error LNK2019: unresolved external symbol "void __cdecl processCollisionTask(void *,void *)" (?processCollisionTask@@YAXPAX0@Z) referenced in function "public: virtual void __thiscall MultiThreadedDemo::initPhysics(void)" (?initPhysics@MultiThreadedDemo@@UAEXXZ)
    1>MultiThreadedDemo.obj : error LNK2019: unresolved external symbol "void * __cdecl createCollisionLocalStoreMemory(void)" (?createCollisionLocalStoreMemory@@YAPAXXZ) referenced in function "public: virtual void __thiscall MultiThreadedDemo::initPhysics(void)" (?initPhysics@MultiThreadedDemo@@UAEXXZ)
    1>MultiThreadedDemo.obj : error LNK2019: unresolved external symbol "void __cdecl deleteCollisionLocalStoreMemory(void)" (?deleteCollisionLocalStoreMemory@@YAXXZ) referenced in function "public: void __thiscall MultiThreadedDemo::exitPhysics(void)" (?exitPhysics@MultiThreadedDemo@@QAEXXZ)
    1>MultiThreadedDemo.obj : error LNK2019: unresolved external symbol "void __cdecl SolverThreadFunc(void *,void *)" (?SolverThreadFunc@@YAXPAX0@Z) referenced in function "class btThreadSupportInterface * __cdecl createSolverThreadSupport(int)" (?createSolverThreadSupport@@YAPAVbtThreadSupportInterface@@H@Z)
    1>MultiThreadedDemo.obj : error LNK2019: unresolved external symbol "void * __cdecl SolverlsMemoryFunc(void)" (?SolverlsMemoryFunc@@YAPAXXZ) referenced in function "class btThreadSupportInterface * __cdecl createSolverThreadSupport(int)" (?createSolverThreadSupport@@YAPAVbtThreadSupportInterface@@H@Z)
    1>MultiThreadedDemo.obj : error LNK2019: unresolved external symbol "public: __thiscall btParallelConstraintSolver::btParallelConstraintSolver(class btThreadSupportInterface *)" (??0btParallelConstraintSolver@@QAE@PAVbtThreadSupportInterface@@@Z) referenced in function "public: virtual void __thiscall MultiThreadedDemo::initPhysics(void)" (?initPhysics@MultiThreadedDemo@@UAEXXZ)
    

And here is the code I am using for my current scene:

How I am initializing Bullet:
 

broadphase = new btDbvtBroadphase();
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0, -9.8f, 0));

How I am stepping the world.
 

dynamicsWorld->stepSimulation(DeltaTime, SimulationSpeed);

/*

Where simulation speed generally set to 7 but can be changed in environment.

*/

And here is my code for static mesh:
 


	btTriangleIndexVertexArray* PhysicsMeshInterface =
		new btTriangleIndexVertexArray(NumberOfTriangles,
		(GLint*)IndicesPointer,
		3 * sizeof(GLint),
		NumberOfIndVertices,
		VerticesPointer,
		3 * sizeof(GLfloat));

	btBvhTriangleMeshShape* StaticTriangleMeshShape = new btBvhTriangleMeshShape(PhysicsMeshInterface, useQuantizedAabbCompression);

        /*

        PhysicsShape is a pointer to a "btCollisionShape" object.

        */

	PhysicsShape = StaticTriangleMeshShape;

	btTransform TransformFromOpenGL;

	TransformFromOpenGL.setFromOpenGLMatrix(ModelMatrixPointer);

	PhysicsShapeMotionState = new btDefaultMotionState(TransformFromOpenGL);

	btAssert((!PhysicsShape || PhysicsShape->getShapeType() != INVALID_SHAPE_PROXYTYPE));

	/*


        ShapeMass and ShapeInertia are "zeroed" out in the constructor for this class instance that wraps around the Bullet Object in my engine.

        */


        btRigidBody::btRigidBodyConstructionInfo PhysicsShapeCI(ShapeMass, PhysicsShapeMotionState, PhysicsShape, ShapeInertia);

	PhysicsShapeRigidBody = new btRigidBody(PhysicsShapeCI);

	PhysicsShapeRigidBody->setRestitution(ShapeRestitution);

	PhysicsShapeRigidBody->setUserPointer(this);

	CurrentPhysicsWorld->addRigidBody(PhysicsShapeRigidBody);

Thank you for any time and assistance you can provide.

Share this post


Link to post
Share on other sites

This topic is 1199 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this