SoftBody collision inaccuracies

Post Reply
ivanisavich
Posts: 6
Joined: Sat Jun 10, 2017 7:54 pm

SoftBody collision inaccuracies

Post by ivanisavich »

I'm having trouble with SoftBody collisions.

I have a ground plane (btStaticPlane) and some cloths (btSoftBody, 10x10 vertex planes) that fall onto the ground plane.

When my simulation steps are .0333f (30 steps per second) the falling cloth objects easily penetrate the ground and don't collide with it. When I increase my steps 10x (.00333f) they'll collide with it, but some of them will land, settle for a moment, and then just fall through.

Even when I set my steps to 100x normal (.000333f) I get certain cloths that easily penetrate the ground. This is both with/without a large collision margin.

I tried enabled CCD on my cloth but setting sweep threshold/radius seemed to have no effect.

I've tried setting solver piterations very high (250!) and still get the same issues.

Am I missing something or are cloth collisions totally unreliable? The effects I'm seeing basically make SoftBodies completely useless in realistic offline simulations...
ivanisavich
Posts: 6
Joined: Sat Jun 10, 2017 7:54 pm

Re: SoftBody collision inaccuracies

Post by ivanisavich »

Here are two example videos showing the issue:

In this one, I spawn some single-triangle btSoftBody objects over a ground plane. You can see that some collide, some swing through partially, and one completely penetrates the plane. This is with 100 substeps per frame (3000 steps per second):

http://www.tysonibele.com/Junk/triangles_01.mp4

In this one, I spawn some 10x10 btSoftBody cloths over a ground plane. You can see that some collide, and some slide completely through the plane. This is with 10 substeps per frame (300 steps per second):

http://www.tysonibele.com/Junk/planes_01.mp4

Considering the number of substeps used to calculate the softbody motion here, surely this is indicative of a bug or larger problem with the softbody solver? Even with 300 steps per second, the cloth in the second example easily slides through the plane without any problem...
ivanisavich
Posts: 6
Joined: Sat Jun 10, 2017 7:54 pm

Re: SoftBody collision inaccuracies

Post by ivanisavich »

So I think I've tracked down part the problem to a pretty interesting bug. This doesn't fix all ground interpenetrations...but it fixes some of them, especially when contact point locations vary greatly (which will make sense when you read what the bug is).

There is some caching going on in btSoftBodyConcaveCollisionAlgorithm.cpp inside the processTriangle function. Specifically, m_shapeCache, which tries to grab cached convex hulls instead of generating new ones for each triangle or group of triangles or whatever (I think it's creating hulls and then using their AABB during broadphase collision detection....not entirely sure).

Anyways, the btStaticPlaneShape is an infinite plane, and so instead of providing two infinite triangles whenever its processAllTriangles function is called, it generates small triangles under query points inside its processAllTriangles function and passes those to the processTriangles function of the callback sent to it.

However....what's happening is the btStaticPlaneShape is creating some small triangles under query point A....and then processTriangle is caching those triangles....so that next time query point B is sent to processAllTriangles, processTriangles is just grabbing the cache of the previous procedural triangles for query point A instead of getting new ones for query point B! So that's why my shapes are going straight through the ground -- because the procedural triangles being generated underneath them are completely ignored in the collision algorithm!

A simple fix is to just skip caching convex hulls in the cache generated for btStaticPlaneShapes. There must be a more efficient alternative to this (why generate convex hulls for an infinite plane to begin with?...surely there must be some simpler math to achieve the same result)....maybe someone else could figure that out.

Here's the code to fix this, which I placed at line 177 of btSoftBodyConcaveCollisionAlgorithm.cpp:

Code: Select all

if (m_triBody->getCollisionShape()->getShapeType() == STATIC_PLANE_PROXYTYPE)
{
	delete tm;
}
else
{
	triIndex.m_childShape = tm;
	m_shapeCache.insert(triKey, triIndex);
}
As mentioned, this doesn't solve all ground interpenetations....but it's halfway there.
ivanisavich
Posts: 6
Joined: Sat Jun 10, 2017 7:54 pm

Re: SoftBody collision inaccuracies

Post by ivanisavich »

I've got everything working now I think.

Turns out the rest of the interpenetrations were caused by vertex bounding boxes jumping over the ground plane collision margins. I modified the bounding box generation code to expand AABBs to include the previous timestep vertex locations, as a way of faking CCD in the broadphase step. The downside is that vertices which move diagonally over large distances will trigger a lot of false positives, but the upside is I greatly reduce the number of interpenetations.

I also modified the narrow phase contact collision calculator to always return (0,1,0) as the depenetration normal when colliding with static planes, and return the y value of the vertex as the depenetration distance (since the ground plane is at y=0, the min-depenetration distance of a penetrating vert will always just be its y position).

Now I don't get any objects falling through the ground.
Post Reply