Hey all,
I have made an example of a empty box using btCompoundShape (out of 5 btBoxShapes) and I made it static object.
Then I added a btBoxShape (lets call it falling box) inside the empty box (with some margin, so that the falling box can fall inside the empty box and hit its bottom).
However, I found that the collision between these two objects is not detected!
Here is my code:
https://gist.github.com/Ehsanizadi/d89f4a9a7f1658dc9ef5
From the line 54 up to 97: empty box definition (using btCompoundShape)
From the line 99 up to 110: falling box definition (using btBoxShape)
What do you think?
Extra comment: the funny fact is that if you add the falling box before the compound empty box, the collision will be detected! (why?)
btCompoundShape: collision detection problem! :?:
-
- Posts: 72
- Joined: Mon Dec 02, 2013 4:13 pm
-
- Posts: 72
- Joined: Mon Dec 02, 2013 4:13 pm
Re: btCompoundShape: collision detection problem! :?:
Any suggestion?
-
- Posts: 456
- Joined: Tue Dec 25, 2007 1:06 pm
Re: btCompoundShape: collision detection problem! :?:
It might be an "update AABB" problem.
I'd try to solve the problem this way:
Hope they're useful
I'd try to solve the problem this way:
- By NOT using btCompoundShape for static objects in the first place. Just add the child shapes directly to the world as static btRigidBodies (or plain btCollisionObjects if you like). Some tests I made some time ago showed a better performance (even if Bullet might have improved this with recent releases).
- Or by calling world->updateSingleAABB(emptyBoxRigidBody) (or something like that) after all the bodies have been added.
- Or maybe by trying to "activate" the bodies if they are sleeping (i.e. if you just placed a sleeping box in the empty shape, then the collision are not detected).
- Or maybe make the body fall starting from a place "outside" the compound empty static background and see if it works.
Hope they're useful
-
- Posts: 72
- Joined: Mon Dec 02, 2013 4:13 pm
Re: btCompoundShape: collision detection problem! :?:
Thanks for the hints:
1) the first suggestion for my case is not possible, because I have another compound shape which is dynamic object.
2) updating singleAABBs did not solve the problem, they still pass through eachother
3) I already activated them by : rigidbody->setActivationState(4);
4) Tried, but did not solve the problem.
1) the first suggestion for my case is not possible, because I have another compound shape which is dynamic object.
2) updating singleAABBs did not solve the problem, they still pass through eachother
3) I already activated them by : rigidbody->setActivationState(4);
4) Tried, but did not solve the problem.
-
- Posts: 456
- Joined: Tue Dec 25, 2007 1:06 pm
Re: btCompoundShape: collision detection problem! :?:
Not a big issue (you can just reuse the child shapes of the dynamic object, so that you have 5 new static bodies made with them, even if adding 5 new static box shapes shouldn't be a great deal too).Ehsanizadi wrote:1) the first suggestion for my case is not possible, because I have another compound shape which is dynamic object.
However that behaviour is very strange.
Can you confirm that is you add the static empty background box after all the other bodies all works as expected ? If this is the case that's the best solution you can find .
However it would be nice to have a reproduction example of it for further investigation.
What version of Bullet are you using ?
-
- Posts: 72
- Joined: Mon Dec 02, 2013 4:13 pm
Re: btCompoundShape: collision detection problem! :?:
Yes, if I add the compound shape after all of the bodies, only the bottom plate will be recognized.
As a result, if a small dynamic body falls into the box, it will be settled on the bottom plane of the empty box, However, in the case you apply a central force in horizontal direction, it will goes for ever! without "feeling" the vertical childshapes of the empty box.
I am currently working on that again, if I dont reach to a solution, I will try to simplify and narrow down the problem, so the example code will be shorter and easier to investigate, then I will post it again here.
I am using the current version of Bullet 3,
when there is a new change, I clone again and recompile. So, the version is the latest one.
As a result, if a small dynamic body falls into the box, it will be settled on the bottom plane of the empty box, However, in the case you apply a central force in horizontal direction, it will goes for ever! without "feeling" the vertical childshapes of the empty box.
I am currently working on that again, if I dont reach to a solution, I will try to simplify and narrow down the problem, so the example code will be shorter and easier to investigate, then I will post it again here.
I am using the current version of Bullet 3,
when there is a new change, I clone again and recompile. So, the version is the latest one.
-
- Posts: 456
- Joined: Tue Dec 25, 2007 1:06 pm
Re: btCompoundShape: collision detection problem! :?:
Ehsanizadi wrote:However, in the case you apply a central force in horizontal direction, it will goes for ever! without "feeling" the vertical childshapes of the empty box.
Another try (but I'm not very confident now):
- Can it be a problem with the physic world bounds ?
Are you using a btDbvhBroadphase ? Otherwise the bounds of the physic world should be specified in advance AFAIR.
Is your world big ? Maybe you should use BT_USE_DOUBLE_PRECISION (always: in the building of the library AND of your code), or try with a smaller test to see if it works (also don't try to use dynamic bodies that are too small).
Well, I hope that's not something releted to new versions (I'm still using older ones...)Ehsanizadi wrote:I am using the current version of Bullet 3,
when there is a new change, I clone again and recompile. So, the version is the latest one.
-
- Posts: 72
- Joined: Mon Dec 02, 2013 4:13 pm
Re: btCompoundShape: collision detection problem! :?:
Its not related to the world bounds.
I just found the source of problem. It is programming glitch rather than a Bullet-related one!
When I do "compoundShape->addChildShape(relTransform, childShape);" inside a "for" loop in c++, it will remain valid within that loop, not outside!
If I remove that for loop and do the "addChildShape" fuction inside the main block it will work well.
But just for the cause of my curiosity, if one have many objects as child shapes, it would be very overwhelming to write a new line for that (even for copy-pasting, it makes your programm so long), is there any other way to do that?
I just found the source of problem. It is programming glitch rather than a Bullet-related one!
When I do "compoundShape->addChildShape(relTransform, childShape);" inside a "for" loop in c++, it will remain valid within that loop, not outside!
If I remove that for loop and do the "addChildShape" fuction inside the main block it will work well.
But just for the cause of my curiosity, if one have many objects as child shapes, it would be very overwhelming to write a new line for that (even for copy-pasting, it makes your programm so long), is there any other way to do that?
-
- Posts: 456
- Joined: Tue Dec 25, 2007 1:06 pm
Re: btCompoundShape: collision detection problem! :?:
Well, this is probably a problem inside your code. All the collision shapes (including child shapes) should be, as usual, allocated on the heap and remain valid until at least one body uses them. And Remember to add the collision shape AFTER all child shapes have been updated (or call some methods to update the child shape manually).Ehsanizadi wrote: wrote:When I do "compoundShape->addChildShape(relTransform, childShape);" inside a "for" loop in c++, it will remain valid within that loop, not outside!
If I remove that for loop and do the "addChildShape" fuction inside the main block it will work well.
By using for loops .Ehsanizadi wrote: wrote: if one have many objects as child shapes, it would be very overwhelming to write a new line for that (even for copy-pasting, it makes your programm so long), is there any other way to do that?
It's a common practice to use btCompoundShapes of btconvexHullShapes generated using external tools (like HACD or V-HACD): see the Bullet convex decomposition demo for that.
-
- Posts: 72
- Joined: Mon Dec 02, 2013 4:13 pm
Re: btCompoundShape: collision detection problem! :?:
Yes,
Thanks for the help.
So this is "SOLVED" completely.
Thanks for the help.
So this is "SOLVED" completely.
-
- Posts: 10
- Joined: Wed Oct 24, 2018 8:38 am
Re: btCompoundShape: collision detection problem! :?:
Sorry, how did you solved the problem? Could you provide some code or function that you called to update child shapes?