glue/divide 400 bodies by btCompoundShape = low performance

Post Reply
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

glue/divide 400 bodies by btCompoundShape = low performance

Post by hyyou »

I have used 400 boxs shape to create 400 btRigidBody (1:1, I don't share shape to keep it simple.), then I want to glue them together.

To avoid instability and performance issue, instead of using btConstraint, I have decided to use btCompoundShape to create a new big body.

This is pseudo algorithm.
Glue
● all btRigidBody mask = 0 (remove & readd)
● new btCompoundShape from 400 btRigidBodies (using 400 relative transformation and their shapes)
● enable my custom function to set transformation of 400 btRigidBody to appropriate values, using transformation of btCompoundShape. The function is executed in every time step. (cost only little)

Divide
● remove and delete btCompoundShape
● disable the function
● restore btRigidBody mask (remove & readd)

From the profile, the remove & readd cost a lot (10+ ms in release mode), can I avoid it?
Note that, all 400 boxes are not touching each other, and performance in the other time steps are very nice (<2 ms).

The problem boil down to the performance hit of a single line that called 400 times.

Code: Select all

dynamicsWorld->removeRigidBody(body);
I don't find any clue about this, with my respect, if any reader has any slightest idea, please reply.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: glue/divide 400 bodies by btCompoundShape = low performa

Post by benelot »

First of all, you should try to share shapes if possible, but that might be for a later stage. Furthermore I think it is very expensive to remove the compound shape as it has to remove all 400 btRigidBodies at once (you could measure the time by adding the rigidbodies without compound shape and then remove them all, also you can look into the code).

What does "disable the function" do? Why do you have to remove them all and then readd?
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: glue/divide 400 bodies by btCompoundShape = low performa

Post by hyyou »

Hi, benelot.

disable the function = ignoring all callback

When the body is removed / re-added, the callback of the body should be disabled, otherwise fake response (in gameplay) can occur, e.g. a bullet collide with a rocket twice.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: glue/divide 400 bodies by btCompoundShape = low performa

Post by benelot »

Do you really have to remove all the boxes at once? You might also be able to disable the whole shape at once and then reenable it when needed later. Or, since you called the step divide, are you changing the number of boxes by dividing? Adding and removing should only be called when necessary, meaning if something is set up and if something leaves the world forever or for a long time at least.
Post Reply