When the rigid body becomes more, the program becomes stuck

Post Reply
water
Posts: 33
Joined: Fri Jun 05, 2020 8:36 am

When the rigid body becomes more, the program becomes stuck

Post by water »

I want to achieve the collision effect of small balls, but I found that when I increase the number of small balls, the program becomes stuck. What should I do to solve this problem? Thank you very much
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: When the rigid body becomes more, the program becomes stuck

Post by drleviathan »

How many small balls are you talking about? What are the parameters of the hardware you're using?

You might be running into the limits of Bullet on your system. There is a way to obtain detailed stats about where time is being spent inside the stepSimulation() context, which would help you identify your bottleneck. For info about how to do it: search for CProfileManager in these forums.
water
Posts: 33
Joined: Fri Jun 05, 2020 8:36 am

Re: When the rigid body becomes more, the program becomes stuck

Post by water »

I have encountered this problem, can you tell me what I should do? thank you

Code: Select all

CProfileManager::dumpAll();
Error 2 error C2653: 'CProfileManager' : is not a class or namespace name
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: When the rigid body becomes more, the program becomes stuck

Post by drleviathan »

You have #include the right header file to obtain the CProfileManager declarations.
water
Posts: 33
Joined: Fri Jun 05, 2020 8:36 am

Re: When the rigid body becomes more, the program becomes stuck

Post by water »

In other posts, you mentioned the reason why my program will get stuck. What should I do to avoid it. Thank you very much
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: When the rigid body becomes more, the program becomes stuck

Post by drleviathan »

If you actually follow through with the CProfileManager stuff then you would get an idea as to where the bottlenecks are and how much time is spent in the various steps of the simulation. This would help you solve your problem, and also help you determine if you are actually fixing it with any workarounds.

Some workarounds that occur to me:

(1) Simplify your mesh as much as possible. Use fewer triangles.

(2) Break your mesh into multiple meshes. Right now your mesh has a big bounding box and its triangles are rather sparse in that box. Break your mesh into chunks such that each chunk's bounding box is more cube-like. I suspect this could lead to better performance because the bounding volume hierarchies (BVH) used in the btBvhTriangleMeshShape (which I assume you are using) will be simpler.

(3) Take smaller sub-steps and don't run in real-time. Run your simulation over-night. Dunno if this is possible for your usage case.

(4) Change the scale of your simulation. I don't know how small/big your mesh is, but Bullet works best when objects are on the order of 1-10 meters, so to optimize against margin/tunelling/penetration artifacts (which can also introduce CPU overhead) your balls and the mesh triangles should be in that range.

(5) Buy a really expensive machine with lots of RAM. Dunno how much this would help, but I'd be interested in hearing about your results.
water
Posts: 33
Joined: Fri Jun 05, 2020 8:36 am

Re: When the rigid body becomes more, the program becomes stuck

Post by water »

I found that the model I imported was composed of 15000 vertices, that is, 5000 faces. I think it is because there are too many faces that make it run slowly. I reprocessed the model, set the model to collapse, and now the faces are reduced to 3000. I tried to run it, and it was a lot faster.

In addition, I saw in the user manual that "The profiling feature can be switched off by defining #define BT_NO_PROFILE 1 in
Bullet/src/LinearMath/btQuickProf.h "but I still can't use cprofilemanager:: dumpall() after adding the header file btquickprof. h;
Did I use the wrong place? Can you point it out for me? thank you

Code: Select all

		for (int i = 0; i < numManifolds; i++)
		{
			btTransform trans;
			btPersistentManifold * contactManifold = mp_btDynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
			int numContacts = contactManifold->getNumContacts();
			if (numContacts > 0)
			{
				cerr << "get" << endl;
			}
		}
		mp_btDynamicsWorld->stepSimulation(1.f / 60.f, 10);
		CProfileManager::dumpAll();
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: When the rigid body becomes more, the program becomes stuck

Post by drleviathan »

(1) Your Bullet libraries (LinearMath, specifically) must be compiled with:

Code: Select all

-DBT_ENABLE_PROFILE
This may mean you need to compile the libs from source and add that option.

(2) You wouldn't want to dumpAll() every step because that would make your simulation much slower than it already is, and would flood your stdout. So instead you would rig a trigger to only dump on command, or every once in a while.

(3) You want to reset before the step, and then dumpAll() right after. So the code might look something like this:

Code: Select all

CProfileManager::Reset();

world->stepSimulation(deltaTime);

if (dump_stats_next_step) {
    CProfileManager::Increment_Frame_Counter();
    CProfileManger::dumpAll();
    dump_stats_next_step = false;
} 
Post Reply