1

Similar questions here and here but no answers or wrong language.

I've created a btBvhTriangleMeshShape from a GLB object I created in Blender. But my objects just fall straight through it. I've nicked Enable3D's DebugDrawer and looking at the wireframe it doesn't look good, perhaps that's the issue? TBH I found the "Mesh to btBvhTriangleMeshShape" code online after much Googling, and don't fully understand it, so perhaps there's something wrong there? They are however using btConvexTriangleMeshShape but as you can see here they have a commented line using btConvexTriangleMeshShape so I assumed I could just switch them out?

createConcaveShapeFromObj (obj) {
    // New ammo triangles
    const triangleMesh = new Ammo.btTriangleMesh();

    // Declare triangles position vectors
    const vectA = new Ammo.btVector3(0, 0, 0);
    const vectB = new Ammo.btVector3(0, 0, 0);
    const vectC = new Ammo.btVector3(0, 0, 0);

    // Retrieve vertices positions from object
    const verticesPos = obj.geometry.getAttribute('position').array;
    const triangles = [];

    for (let i = 0; i < verticesPos.length; i += 3) {
        triangles.push({
                x: verticesPos[i],
                y: verticesPos[i + 1],
                z: verticesPos[i + 2]
        })
    }

    // Use triangles data to draw ammo shape
    for (let i = 0; i < triangles.length - 3; i += 3) {
        vectA.setX(triangles[i].x);
        vectA.setY(triangles[i].y);
        vectA.setZ(triangles[i].z);

        vectB.setX(triangles[i + 1].x);
        vectB.setY(triangles[i + 1].y);
        vectB.setZ(triangles[i + 1].z);

        vectC.setX(triangles[i + 2].x);
        vectC.setY(triangles[i + 2].y);
        vectC.setZ(triangles[i + 2].z);

        triangleMesh.addTriangle(vectA, vectB, vectC, true);
    }

    var shape = new Ammo.btConvexTriangleMeshShape(triangleMesh, true); // Note that btConvexTriangleMeshShape works, but collision is done on the bounding box instead which doesn't work either.

    shape.setMargin(0.05);

    return shape;
}

You can view the full project here.

powerbuoy
  • 12,460
  • 7
  • 48
  • 78
  • Hello good sir, did you find a solution to your problem? I have the same problem, my ball with mass 1 just falls straight through my complex blender imported mesh :( – fy data Nov 01 '22 at 14:48
  • Not really :/ and haven't really touched this code in a while. But you can see what I have here https://sleekwp.dev/fun/io8/lib/sleek-entity.js – powerbuoy Nov 02 '22 at 18:21
  • 1
    simply replacing the btConvexTriangleMeshShape line with btBvhTriangleMeshShape fixed this issue for me :) I already wrote similar code to yours but yours is cleaner so thnx! – fy data Nov 03 '22 at 19:35
  • Oh so that actually worked for you? It never did for me. Will need to revisit this then! Oh and if anyone else is interested it's in the file above in the createConvexShapeFromObj static method. – powerbuoy Nov 03 '22 at 19:55

0 Answers0