Objects falling through of sloped triangle mesh (Bullet)

Hello,

I’ve tried to find a solution to a long-term issue I’ve had with Bullet collisions. The problem is that whenever there’s a sloped triangle mesh, other physics objects are sucked to the other side of the sloped triangle.

I’ve produced a small test application to demonstrate this issue. There are two objects: a dynamic box falling, and a ground triangle mesh consisting of 2 triangles.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import Point3, Vec3
from panda3d.bullet import *

class BulletCollisionDebugDemo(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        self.win.setClearColor((0, 0, 0, 1))
        
        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81)) 
        
        self.debugNode = BulletDebugNode('Debug')
        self.debugNode.showWireframe(True)
        self.debugNode.showBoundingBoxes(True)
        self.debugNP = render.attachNewNode(self.debugNode)
        self.world.setDebugNode(self.debugNode)   

        self.test_floor = BulletRigidBodyNode("The floor")
        p0 = Point3(2, -2, 0)
        p1 = Point3(-6, -2, 0)
        p2 = Point3(-6, 6, 1) # The sloped triangle
        p3 = Point3(2, 6, 0)
        mesh = BulletTriangleMesh()
        mesh.addTriangle(p0, p1, p3) # The flat triangle
        mesh.addTriangle(p1, p2, p3) # The sloped triangle
        self.test_floor.addShape(BulletTriangleMeshShape(mesh, dynamic=False))
        self.world.attachRigidBody(self.test_floor)
        
        self.test_box = BulletRigidBodyNode("The box")
        self.test_box.setMass(1.0)
        self.test_box.setFriction(1.0)
        shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
        self.test_box.addShape(shape)
        np = render.attachNewNode(self.test_box)
        np.setPos(-3,3,15)
        self.world.attachRigidBody(self.test_box)
        
        self.debugNP.show() 
        
        taskMgr.add(self.process, "main_process", appendTask=True)

    def process(self, task):
        self.dt = globalClock.getDt()
        self.world.doPhysics(self.dt) 
        return task.cont

demo = BulletCollisionDebugDemo()
demo.run()

If you execute this code, (and zoom out fast enough :confused: ), you should see the cube falling through the triangle mesh with no intention of stopping.

In my main project, I have a player model instead of a box. What is not apparent in this demo, is that if an object moves slower, the Bullet physics immediately attempts to push the object through the triangle to the other side. And the other side of the triangle does have proper collision.

One might think that there is something wrong with the bullet setup, so as a sanity check, I’m going to set p2 = Point3(-6, 6, 0). This makes both triangles flat. The cube bounces from the ground and stops on the platform:

Any ideas why the cube ignores the sloped triangle? Running pre-built Panda3D 1.9.4 on Windows 7 64bit.

I tried your sample code and it works perfectly for me :stuck_out_tongue: The box slides down the slope and stops resting on the ground… I guess that doesn’t help much!

Huh. Well, good to know nonetheless. Care to share your Panda version etc. ?

1.9.4 on Linux

It does sound similar to something I’ve seen before where the triangle normals were the wrong way around… so the engine considered the object to be “inside” the other… that wasn’t with Panda3d or bullet though. Maybe you can try flipping the mesh normals or reversing the order of the vertices of the triangles…?

or is there any bullet option to ensure collisions happen from both sides

Hi! I’ve seen this in the past in my current project, so I share what I experienced.

I observed different behaviors on several platforms, with the same code. Physics was stable on Panda3D 1.9.4 on Linux, which was using Bullet 2.81, and was unstable (i.e. the same code produced a behavior similar to yours) on Panda3D 1.9.4 on Windows and OSX, which were using Bullet 2.82.

There are several attempts you may do. As instance, you can tune do_physics’s arguments (see here) or integrating CCD.

In my case, these solutions didn’t work, so I ended up modifying the triangle mesh shape. Specifically, I found these hints, there are a lot of suggestions about Bullet and this case. It talks about set_margin (which may be another attempt), and explains how triangles should be defined.

From my experience, it’s not your fault, the fault is in the specific Bullet version vs. specific triangle’s definition.

Thanks for the tips! I found some discussion, which might be related to this exact issue:
github.com/bulletphysics/bullet3/issues/182

It does indeed seem that the normal of the triangle is somehow interpreted incorrectly, which explains why the engine pushes my player physics to the wrong side.

Messing with doPhysics and margins did not fully solve the issue. By setting margins of the player model and geometry to 0, shallow slopes stabilized. But if I set for example p2 = Point3(-6, 6, 4), both the box and player model go through the triangle again. I’ll report back if I can find a more permanent solution.