Does MultiSphereShape really support individual sphere scaling and repositioning?

Post Reply
mqnc
Posts: 6
Joined: Fri Jun 29, 2018 10:23 am

Does MultiSphereShape really support individual sphere scaling and repositioning?

Post by mqnc »

Hi!

http://bulletphysics.org/mediawiki-1.5. ... ion_Shapes says "Also since the spheres can be independently scaled in each of the 3 dimensions, ..."

http://bulletphysics.com/Bullet/BulletF ... Shape.html says "It is possible to animate the spheres for deformation, but call 'recalcLocalAabb' after changing any sphere position/radius"

However, examining the source here http://bulletphysics.com/Bullet/BulletF ... ource.html I can't see how either of the functionalities is supposed to work. Am I missing something? Do I have to recreate the shape in every step for morphing?

Cheers,
mqnc
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Does MultiSphereShape really support individual sphere scaling and repositioning?

Post by drleviathan »

A btRigidBody has a btCollisionShape. It is possible to change the internal structure of the shape on fly... with two caveats and one warning:

(1) The internal state of the shape will not be correct until you also update its local AABB. Specifically for a btMultiSphereShape this means: after you've added/removed/scaled one or more spheres you must call recalcLocalAABB().

(2) The broadphase caches the local AABB of the btCollisionObjects in the world, so if you change the local AABB of a btRigidBody's shape you must also update its corresponding entry in the broadphase. One way to do this is to remove it from the world and immediately re-add it. There is a CPU cost associated with each add/remove, but typically low as long as you have less than a few tens of thousands of objects in the world. This may reset any persistent contact manifolds. Finally, there may be a more efficient way to do it if you were to dig deep into code of the broadphase you're using.

(3) Danger: changing the shape of bodies on the fly can introduce penetrations, and will result in non-physical behavior. It is not possible to convey the velocity of the collision shape's surface to the contact points, so you'll cause Bullet's penetration resolver code to kick in. It is relatively stable and doesn't pump much energy into the system, but the results are still non-physical.
mqnc
Posts: 6
Joined: Fri Jun 29, 2018 10:23 am

Re: Does MultiSphereShape really support individual sphere scaling and repositioning?

Post by mqnc »

Hi, thanks for your answer!

I am using bullet for static collision detection only, I just care about whether meshes intersect or not. I'm working with btCollisionWorld and btCollisionObject, no dynamics.

What I mean is that btMultiSphereShape has the following members (all private):

btAlignedObjectArray< btVector3 > m_localPositionArray // sphere centers I suppose
btAlignedObjectArray< btScalar > m_radiArray // sphere radi

and the following methods:

btMultiSphereShape (const btVector3 *positions, const btScalar *radi, int numSpheres)
calculateLocalInertia (btScalar mass, btVector3 &inertia) const
virtual btVector3 localGetSupportingVertexWithoutMargin (const btVector3 &vec) const
batchedUnitVectorGetSupportingVertexWithoutMargin (const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const
getSphereCount () const
getSpherePosition (int index) const
getSphereRadius (int index) const
getName () const
calculateSerializeBufferSize () const
serialize (void *dataBuffer, btSerializer *serializer) const

I don't see how the spheres "can be independently scaled in each of the 3 dimensions" when the object doesn't hold information about different ellipsis radi along each axis. Or does this mean that all spheres together can be stretched along x, y or z by some global scale factor? And I also don't understand how I'm able to change the sphere positions other than deleting and recreating the complete btMultiSphereShape.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Does MultiSphereShape really support individual sphere scaling and repositioning?

Post by drleviathan »

It sounds like you want to use anisotropic scaling of spheres, so they would collide as ellipsoids. Alas, Bullet does not support that. If you really want ellipsoidal shapes then your best approximations would be achieved by using btConvexHull shapes instead.

It is true: btMultiSphereShape does not support moving/changing its spheres. However, you could derive your own custom FancyMultiSphereShape from it and add API that supports it. The trick is that your class would have to update the shape's local AABB under the hood, and your project would still need custom code outside FancyMultiSphereShape that remembers to update the AABB of the broadphase proxy.
mqnc
Posts: 6
Joined: Fri Jun 29, 2018 10:23 am

Re: Does MultiSphereShape really support individual sphere scaling and repositioning?

Post by mqnc »

Thanks again! I worked around those things now. But why are those features explicitly stated in the wiki and in Doxygen then? Should that be changed or do I get it wrong?

Again with more context:

http://bulletphysics.org/mediawiki-1.5. ... ion_Shapes
btMultiSphereShape
A convex shape defined by spheres. Useful for representing bevelled boxes or other shapes without sharp corners. Also since the spheres can be independently scaled in each of the 3 dimensions, a btMultiSphereShape containing just one sphere can be useful to create ellipsoids (squashed spheres), which is not possible with btSphereShape.

http://bulletphysics.com/Bullet/BulletF ... Shape.html
The btMultiSphereShape represents the convex hull of a collection of spheres.
You can create special capsules or other smooth volumes. It is possible to animate the spheres for deformation, but call 'recalcLocalAabb' after changing any sphere position/radius
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Does MultiSphereShape really support individual sphere scaling and repositioning?

Post by drleviathan »

Hrm... perhaps I am just wrong about support for asymmetric scaling of spheres to achieve ellipsoidal shapes. I haven't tried it yet. There is a possibility the wiki is correct. I'll have to test it and get back to you.
Post Reply