btBvhTriangleMeshShape tunneling

Post Reply
avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

btBvhTriangleMeshShape tunneling

Post by avithohol » Tue Apr 03, 2018 9:53 pm

There seems to be significant differences between collision shapes regarding collision accuracy.

The same dynamic bodies penetrate much deeper into a static btBvhTriangleMeshShape body,
than they do into the same sized static btBoxShape body.

For test, one big 10x10x10 box is created, then 9 dynamic boxes are dropped on top of each other, similarly what MultipleBoxes example do.

Test #1 - The big white box, the ground is a btBvhTriangleMeshShape.
https://youtu.be/DW_K707RAhw

1-2 dynamic boxes are even tunneling, and pass through the static body.

Test #2 - The big white box, the ground is a btBoxShape.
https://youtu.be/idsYQVISD7I

There is some penetration here too (no idea why), but at least no tunneling and passing through dynamic bodies.



In my example, I don't think i have problem with simulation step.
The loop is independent from the rendering, and deterministic (repeating the tests gives exactly the same results always, and boxes land on the same spots).
Physics simulation is stepped like this:

Code: Select all

mDynamicsWorld->stepSimulation((btScalar)mPhysicsTimer.getElapsedMilliseconds() / 1000.0f, 7, 1.0f/60.0f);
Increasing the simulation resolution (fixedTimeStep) to 1/120, or 1/200 mitigate the problem, but obviously is not the root cause as 1/60 should be more than enough in this example.
CCD could be solution too, but the bodies are not even fast, only gravity affected, so I would keep CCD only for bullets, and missles not slow moving boxes.


Does anybody experienced similar issues with BT, like:
1. Different shapes have different collision accuracy.
2. Inaccurate collision, slight tunneling, as seen even in Test#2, and Test#3.

Thank you!





Dynamic box properties:
  • Dimensions: 0.5 x 0.5 x 0.5
  • Mass: 1
  • Friction: 0.9
  • Restitution: 0
  • Inertia: 0 0 0 (calculated by calculateLocalInertia on creation)
  • Restitution: 1 1 1


Static ground, the big white box properties:
  • Dimensions: 10 x 10 x 10
  • Mass: 0
  • Friction: 1.0
  • Restitution: 0
  • Inertia: 0 0 0
  • Restitution: 0 0 0


P.S.: The btBvhTriangleMeshShape is created like this:
I use this to load entire maps, and complex shapes without any issue, except for the tunneling artifact.

Code: Select all

	btIndexedMesh indexedMesh;
	indexedMesh.m_numTriangles = mVertexIndexes.size() / 3;
	indexedMesh.m_triangleIndexBase = (unsigned char*)&mVertexIndexes[0];
	indexedMesh.m_triangleIndexStride = 3 * sizeof(vUshort);
	indexedMesh.m_numVertices = mVertexPositions.size();
	indexedMesh.m_vertexBase = (unsigned char*)&mVertexPositions[0];
	indexedMesh.m_vertexStride = sizeof(glm::vec3);

	mTriangleIndexVertexArray = new btTriangleIndexVertexArray();
	mTriangleIndexVertexArray->addIndexedMesh(indexedMesh, PHY_SHORT);

mCollisionShape = new btBvhTriangleMeshShape( mTriangleIndexVertexArray, true, true);
Last edited by avithohol on Thu Apr 05, 2018 3:58 pm, edited 1 time in total.

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

Re: btBvhTriangleMeshShape tunneling

Post by drleviathan » Wed Apr 04, 2018 3:35 pm

Yes, tunneling is a known fundamental problem for physics simulations and you've already listed the known solutions. In summary:

(1) Only use convex shapes. Use convex decomposition and btCompoundShape for concave things.
(2) Use smaller substeps
(3) Enable continuous collision detection (CCD)

avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Re: btBvhTriangleMeshShape tunneling

Post by avithohol » Wed Apr 04, 2018 10:59 pm

drleviathan wrote:
Wed Apr 04, 2018 3:35 pm
Yes, tunneling is a known fundamental problem for physics simulations and you've already listed the known solutions. In summary:

(1) Only use convex shapes. Use convex decomposition and btCompoundShape for concave things.
(2) Use smaller substeps
(3) Enable continuous collision detection (CCD)
Thanks for the reply.
I think 1/60 timestep should work stable already, be it btBoxShape or btBvhTriangleMeshShape.

Is it really nothing else? Those 3 below are checked.

(1) Only use convex shapes. Use convex decomposition and btCompoundShape for concave things.
Boxes are convex in the example.

(2) Use smaller substeps
Works, but very cpu intense. With 1/60 i can drop hundreds of boxes, but with 1/240 (which appear to hide this inaccuracy) only few dozens.

(3) Enable continuous collision detection (CCD)
I would save CCD for small and fast moving objects like bullets. Not a meter wide gravity affected box.

hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: btBvhTriangleMeshShape tunneling

Post by hyyou » Thu Apr 05, 2018 2:08 am

(I will avoid to repeat what drleviathan already mentioned.)

Hmm... I feel that the dropping boxs move quite fast.
I am curious. How much are their max speed?

There is a rumor that the middle parameter of stepSimulation() should be 1. (https://stackoverflow.com/a/21273467)
I didn't verify it, but I think it worth trying to manipulate "timeStep", i.e. first parameter, instead.
Restitution: 0
Inertia: 0 0 0
Restitution: 1 1 1
What does it mean? It conflicts with itself.
Did you set small object's inertia = (0,0,0)?

avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Re: btBvhTriangleMeshShape tunneling

Post by avithohol » Thu Apr 05, 2018 11:04 am

hyyou wrote:
Thu Apr 05, 2018 2:08 am
(I will avoid to repeat what drleviathan already mentioned.)

Hmm... I feel that the dropping boxs move quite fast.
I am curious. How much are their max speed?

There is a rumor that the middle parameter of stepSimulation() should be 1. (https://stackoverflow.com/a/21273467)
I didn't verify it, but I think it worth trying to manipulate "timeStep", i.e. first parameter, instead.
Restitution: 0
Inertia: 0 0 0
Restitution: 1 1 1
What does it mean? It conflicts with itself.
Did you set small object's inertia = (0,0,0)?

Inertia for the dynamic boxes are calculated with calculateLocalInertia, so they are not a 0 0 0, sorry.

Regarding max speed:
Good idea!
I made the dynamic bodies print out their velocity's Y component in the the physics tick callback, using getLinearVelocity().GetY().
The falling boxes reach -20.45 value on inpact.
They start to fall from height of 20 unit, and gravity is set to 0,-10,0.

If i start to drop them from height of 150 unit, then i get -50 unit of velocity on impact.

200 unit of height, gives -70 unit of negative acceleration on impact.

Are these values too much?


Regarding the stepSimulation parameter:
They should be fine as is.
Implemented this http://www.bulletphysics.org/mediawiki- ... _Game_Loop and
http://www.bulletphysics.org/mediawiki- ... _The_World.
and i am within range of the values listed there.
For first parameter you need to give the elapsed seconds, and nothing else, unless you want to do slow motion, or accelerate simulation. The second parameter indicates how much iteration BT can do to catch up if it's left behind.
I do fullfill this formula:
timeStep < maxSubSteps * fixedTimeStep

hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: btBvhTriangleMeshShape tunneling

Post by hyyou » Fri Apr 06, 2018 2:12 am

I believe it is very fast, but not sure if it is too fast.

I just noticed that, at some time-steps, it looks like stack of box simulation.
Try to enable "SOLVER_RANDMIZE_ORDER". (http://bulletphysics.org/mediawiki-1.5. ... SolverInfo)

I am curious if it helps.

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

Re: btBvhTriangleMeshShape tunneling

Post by drleviathan » Fri Apr 06, 2018 2:43 pm

Suppose you had a 10m cubic box and your substep period was 1/60 sec. What is the lowest speed at which tunneling through a thin triangle would be possible? If the box were to hit the triangle face-on and manage to tunnel 50%+ through, then Bullet's penetration resolution algorithm will conclude that the box should be pushed out the bottom rather the top. This means the box need only travel half its height (5m) within 1/60 sec.

distance = speed * time
speed = distance / time
speed = 5 / (1/60) = 300 m/sec

That is very fast! The boxes in the video weren't moving as quick so why would they tunnel?

Because: the bottom box is being pushed down from the stack of other boxes above. When it is penetrating an infinitely thin plane below and a convex box above... it may tunnel through before all the collision constraints and penetrations higher up above are satisfactorily resolved.

In short: if you're throwing around 10m cubes one at a time you shouldn't need to worry about tunneling through a mesh, but if you're throwing stacks then you do.

avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Re: btBvhTriangleMeshShape tunneling

Post by avithohol » Sat Apr 07, 2018 9:23 pm

hyyou wrote:
Fri Apr 06, 2018 2:12 am
I believe it is very fast, but not sure if it is too fast.

I just noticed that, at some time-steps, it looks like stack of box simulation.
Try to enable "SOLVER_RANDMIZE_ORDER". (http://bulletphysics.org/mediawiki-1.5. ... SolverInfo)

I am curious if it helps.
Interesting. Never used them before.

I have enabled them but no noticeable change in the simulation.

avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Re: btBvhTriangleMeshShape tunneling

Post by avithohol » Sat Apr 07, 2018 9:30 pm

drleviathan wrote:
Fri Apr 06, 2018 2:43 pm
Suppose you had a 10m cubic box and your substep period was 1/60 sec. What is the lowest speed at which tunneling through a thin triangle would be possible? If the box were to hit the triangle face-on and manage to tunnel 50%+ through, then Bullet's penetration resolution algorithm will conclude that the box should be pushed out the bottom rather the top. This means the box need only travel half its height (5m) within 1/60 sec.

distance = speed * time
speed = distance / time
speed = 5 / (1/60) = 300 m/sec

That is very fast! The boxes in the video weren't moving as quick so why would they tunnel?

Because: the bottom box is being pushed down from the stack of other boxes above. When it is penetrating an infinitely thin plane below and a convex box above... it may tunnel through before all the collision constraints and penetrations higher up above are satisfactorily resolved.

In short: if you're throwing around 10m cubes one at a time you shouldn't need to worry about tunneling through a mesh, but if you're throwing stacks then you do.
Forget about the stacked boxes.
Single falling box does penetrate into the 10x10x10 static box below.
It certainly not falling through, but do penetrate for about 0.1, 0.15.
So more than 1/5th of the cube disappears, than pushed back to the surface.

Let me know if you need video of that.

Meanwhile, II try to put together a workable minimal example with SDL+GLM, and make it available for download.

avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Re: btBvhTriangleMeshShape tunneling

Post by avithohol » Sun Apr 08, 2018 11:02 pm

I have post it to a new, and more question with a full example, you can follow:
https://pybullet.org/Bullet/phpBB3/view ... =9&t=12051

This thread won't have anymore answers specifically on btBvhTriangleMeshShape vs btBoxShape, which is there, but not that significant.

Post Reply