Hello, I'm pretty new to bullet.
I wanted to combine two rigid bodies into a single rigid body. i.e:
What is the fastest way to do this (as in computationally)? I will potentially have a lot of these combined rigid bodies, and they will all be constructed from different types and different amounts of shapes.
Also can this be done with hulls? GImpact shapes?
Combining two Rigid Bodies?
-
- Posts: 50
- Joined: Thu Mar 24, 2016 10:22 am
- Location: France
Re: Combining two Rigid Bodies?
Hello,
Compounds shapes exists for this purpose.
You can combine several shapes in a Compound shape and then use it to create a single RigidBody.
Compounds shapes exists for this purpose.
You can combine several shapes in a Compound shape and then use it to create a single RigidBody.
-
- Posts: 6
- Joined: Tue Jun 02, 2020 2:57 pm
Re: Combining two Rigid Bodies?
Thanks for the response!
What if the rigid bodies have differing masses?
What if the rigid bodies have differing masses?
-
- Posts: 50
- Joined: Thu Mar 24, 2016 10:22 am
- Location: France
Re: Combining two Rigid Bodies?
It allows to combine different shapes in the Compound one to create a single RigidBody so you have only one mass to handle.
On your exemple, you will create 2 btBoxShape, add them as child in a btCompoundShape and then create a RigidBody based on the Compound shape.
You can find sample code here https://github.com/bulletphysics/bullet ... -333561874
On your exemple, you will create 2 btBoxShape, add them as child in a btCompoundShape and then create a RigidBody based on the Compound shape.
You can find sample code here https://github.com/bulletphysics/bullet ... -333561874
-
- Posts: 6
- Joined: Tue Jun 02, 2020 2:57 pm
Re: Combining two Rigid Bodies?
I see. But What if I want them to maintain two the different masses? i.e. something small and heavy attached to something large and light. Pushing on the large light object would force it to pivot around the smaller object with more mass.
I looked into something called P2P Constraint with Bullet, and that's ALMOST what I want, but I don't want to allow independent rotation, if that makes sense?
I looked into something called P2P Constraint with Bullet, and that's ALMOST what I want, but I don't want to allow independent rotation, if that makes sense?
-
- Posts: 50
- Joined: Thu Mar 24, 2016 10:22 am
- Location: France
Re: Combining two Rigid Bodies?
Yes if you need to link 2 existing RigidBodies you have to use constraints.
Here is some of them with explanations : https://knowledge.autodesk.com/support/ ... D-htm.html
For your example, the Fixed constraint has 0 degree of freedom and will so avoid independent rotation and translation between RigidBodies
Here is some of them with explanations : https://knowledge.autodesk.com/support/ ... D-htm.html
For your example, the Fixed constraint has 0 degree of freedom and will so avoid independent rotation and translation between RigidBodies
-
- Posts: 6
- Joined: Tue Jun 02, 2020 2:57 pm
Re: Combining two Rigid Bodies?
Since I have you, do you know the performance impacts of using a LOT of constraints in a scene? I assume it's much slower than doing what you suggested earlier, i.e. using compound shape?
-
- Posts: 849
- Joined: Tue Sep 30, 2014 6:03 pm
- Location: San Francisco
Re: Combining two Rigid Bodies?
Another way to do it would be to use a btCompoundShape but to compute the correct: totalMass, centerOfMass, and inertiaTensor for a heavy object connected to a lighter one. Then you would set the local transform of each sub-shape relative to the centerOfMass (e.g. centerOfMass = local <0,0,0>), and set the totalMass, and the inertiaTensor accordingly. That will produce the expected results.
That said, it would be a little tricky to get exactly right. In general: you would have to diagonalize the centerOfMass-frame inertia tensor and back-rotate the subshapes such that its eigen vectors align with local cardinal axes.
That said, it would be a little tricky to get exactly right. In general: you would have to diagonalize the centerOfMass-frame inertia tensor and back-rotate the subshapes such that its eigen vectors align with local cardinal axes.
-
- Posts: 6
- Joined: Tue Jun 02, 2020 2:57 pm
Re: Combining two Rigid Bodies?
That would certainly solve the mass issue... But then there's also the other properties, bounciness, friction, that could be different between the bodies. I'll try the constraint for now, but if it's not performant enough I may need to give up that dream in favor for the compound shape solution.
Thanks all!
Thanks all!
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Combining two Rigid Bodies?
btCompoundShape::calculatePrincipalAxisTransform can compute the new masses and offsets:
https://pybullet.org/Bullet/BulletFull/ ... tml#l00216
Another option is using btMultiBody and fixed joints. In PyBullet there is an example 'combine_urdf' that can combine two bodies.
All the details are hidden in C++ though. https://github.com/erwincoumans/bullet3 ... ineUrdf.py
https://pybullet.org/Bullet/BulletFull/ ... tml#l00216
Another option is using btMultiBody and fixed joints. In PyBullet there is an example 'combine_urdf' that can combine two bodies.
All the details are hidden in C++ though. https://github.com/erwincoumans/bullet3 ... ineUrdf.py
-
- Posts: 6
- Joined: Tue Jun 02, 2020 2:57 pm
Re: Combining two Rigid Bodies?
Is this possible in bullet 2?Erwin Coumans wrote: ↑Wed Jun 03, 2020 10:50 pm btCompoundShape::calculatePrincipalAxisTransform can compute the new masses and offsets:
https://pybullet.org/Bullet/BulletFull/ ... tml#l00216
Another option is using btMultiBody and fixed joints. In PyBullet there is an example 'combine_urdf' that can combine two bodies.
All the details are hidden in C++ though. https://github.com/erwincoumans/bullet3 ... ineUrdf.py