Penetration depth for STL files

Post Reply
blabla
Posts: 1
Joined: Tue Mar 01, 2016 7:52 am

Penetration depth for STL files

Post by blabla »

Hi!

I have been developing a simple simulation software, where I want to load few STL files, and determine the penetration depth if collision occurs.
I managed to load STL file into btTriangleIndexVertexArray format, so converted to btGImpactMeshShape format, which was easy to handle as a btCollisionObject. I can now easily detect collisions, but if I want to determine the minimum translation vector that brings the objects into contact, the calculated solution I get is wrong. In short, I first perform a discrete collision detection, iterate on the manifolds/contact points, and display the contact points (getPositionWorldOnA() / getPositionWorldOnB()) with the deepest penetration depth found.

The interesting thing is, if I insert a sphere instead of an STL model, the calculated penetration depth/vector is correct. As you can see in the attached image (green one is the STL model, red points are the contact points correspond to the deepest penetration, white one is the sphere), if I translate the STL model along the penetration vector (vector which connects the two red points), we can imagine the two objects exactly come into contact.
The point is, with two complex 3D model, this penetration calculation method does not work (it provides two very very close contact points instead), but changing one of them to a sphere "solves" the problem (so it calculates correct/deepest contact points).
So my question would be, is it possible to calculate accurately the penetration depth for two complex btGImpactMeshShape with Bullet library?
I'm quite new to Bullet Library, so sorry if I'm asking something obvious.

Thanks,
Blabla
stlVSstl.JPG
stlVSstl.JPG (21.14 KiB) Viewed 11564 times
sphereVSstl.JPG
sphereVSstl.JPG (17.08 KiB) Viewed 11564 times
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Penetration depth for STL files

Post by Erwin Coumans »

Global penetration depth for general concave triangle meshes (that you get from an STL file) is a very (NP) hard problem.

Bullet only implements local penetration depth (between for two triangles) between two btGimpactShapes,
and this has issues when the penetration is larger than the features involved (triangles).

You can avoid this, by using convex decomposiion, and making sure the penetration depth is less than the size of the convex parts.
You can get a pretty good approximate convex decomposition using HACD:
https://github.com/kmammou/v-hacd
There is an older pull request updating to HACD that I haven't processed (yet) here:
https://github.com/bulletphysics/bullet3/pull/477

Another promising method is using signed distance fields (SDF). This is not implemented in Bullet yet. Some users integrated SDF into Bullet, but didn't contribute the code back.
It is useful for robotics, so I likely implement it for Bullet at some stage.

One other solution would be to avoid penetration at all cost, using continuous collision detection (CCD).
Getting CCD for triangles meshes needs some work in Bullet, and you may run into performance issues.

So either use btCompoundShape and convex decomposition (HACD) or be look for another solution, be prepare to do more work and/or open a can of worms...
mobeen
Posts: 122
Joined: Thu May 05, 2011 11:47 am

Re: Penetration depth for STL files

Post by mobeen »

Erwin I think probably this is the paper you are talking about. It does detail a bit about how they integrated sdf in bullet

http://elib.dlr.de/102551/1/Sagardia_VP ... R_2014.pdf
Post Reply