bullet3
bullet3 copied to clipboard
Invalid collision / contact from performCollisionDetection & getContactPoints after many createMultiBody / removeBody calls
I'm using pybullet
to find collisions / contacts of huge scenes with many thousand bodies ( build from convex OBJ meshes ).
I'm not interested in dynamics, I just want to query the "static" scene as-is and find bodies
that are in collision in this static state of the scene.
A scene is build by
- adding initial static bodies
- loop
- adding additional static bodies
- performing collision detection
- removing the additional static bodies afterwards
In general this seems to work as expected, but sometimes false collisions / contacts are found between body A & B, i.e. a collision of actually two distinct bodies A & B that are not even touching.
If I try to double check those false collisions by re-building the scene from scratch incl. bodies A & B ( i.e. only adding those bodies that were in the scene when the collision check was done ), I can't find those false collisions anymore, i.e. I get the expected results.
My environment is
- MacOS Ventura 13.4, M1 arm
- Python 3.10.6
- pybullet==3.2.5
Pseudo code of my application:
physics_client = bullet.connect(bullet.DIRECT)
# add many "static" bodies
for i in my_static_bodies:
collision_shape_id = bullet.createCollisionShape(....)
bullet.createMultiBody(baseCollisionShapeIndex=collision_shape_id,....)
while keep_going:
# add intermediate "static" bodies
for i in my_additional_static_bodies:
collision_shape_id = bullet.createCollisionShape(....)
bullet.createMultiBody(baseCollisionShapeIndex=collision_shape_id,....)
bullet.performCollisionDetection(physics_client)
for contact in bullet.getContactPoints(physicsClientId=physics_client):
# Handle the colliding bodies doing business logic. Not modifying the bodies in any way.
#
# Sometimes false collisions are reported, i.e. reporting bodies in collision that are actually distinct, not even touching.
# Even the contact points are away from any of the two bodies that are supposedly in collision.
# remove intermediate "static" bodies
for i in my_additional_static_bodies:
bullet.removeBody(....)
Any help / idea appreciated - maybe I'm using pybullet
in a way that is wrong or not supported ?