BufferGeometry 的全船体形状

Full Hull Shape of BufferGeometry

我正在尝试使用 ammo.js 为我的 BufferGeometry 创建一个 "Ammo Shape"。我正在使用 "Ammo.btConvexHullShape",但该对象已关闭。你能帮帮我吗?

https://cotosystem.com.br/fechado.png "Original"

https://cotosystem.com.br/shape.png "Closed"

function criarConvexHullPhysicsShape(geometry) {
    var coords = geometry.attributes.position.array;
    var tempBtVec3_1 = new Ammo.btVector3(0, 0, 0);
    var shape = new Ammo.btConvexHullShape();
    for (var i = 0, il = coords.length; i < il; i+= 3) {
        tempBtVec3_1.setValue(coords[i], coords[i + 1], coords[i + 2]);
        var lastOne = (i >= (il - 3));
        shape.addPoint(tempBtVec3_1, lastOne);
    }
    return shape;
}

已编辑:我找到了这个解决方案我的朋友,谢谢 Mugen!

function createTriangleShapeByGeometry(geometry) {
    var mesh = new Ammo.btTriangleMesh(true, true);
    var vertices = geometry.vertices;
    for (var i = 0; i < geometry.faces.length; i++) {
        var face = geometry.faces[i];
        if (face instanceof THREE.Face3) {
            mesh.addTriangle(
                new Ammo.btVector3(vertices[face.a].x, vertices[face.a].y, vertices[face.a].z),
                new Ammo.btVector3(vertices[face.b].x, vertices[face.b].y, vertices[face.b].z),
                new Ammo.btVector3(vertices[face.c].x, vertices[face.c].y, vertices[face.c].z),
                false
            );
        } else if (face instanceof THREE.Face4) {
            mesh.addTriangle(
                new Ammo.btVector3(vertices[face.a].x, vertices[face.a].y, vertices[face.a].z),
                new Ammo.btVector3(vertices[face.b].x, vertices[face.b].y, vertices[face.b].z),
                new Ammo.btVector3(vertices[face.d].x, vertices[face.d].y, vertices[face.d].z),
                false
            );
            mesh.addTriangle(
                new Ammo.btVector3(vertices[face.b].x, vertices[face.b].y, vertices[face.b].z),
                new Ammo.btVector3(vertices[face.c].x, vertices[face.c].y, vertices[face.c].z),
                new Ammo.btVector3(vertices[face.d].x, vertices[face.d].y, vertices[face.d].z),
                false
            );
        }
    }
    var shape = new Ammo.btBvhTriangleMeshShape(mesh, true, true);
    return shape;
}

与任何其他包围体一样,凸包始终是封闭的。所以恐怕你要找的东西是不可能的。