我正在尝试使用ammo.js为我的BufferGeometry创建一个“ Ammo Shape”。我正在使用“ Ammo.btConvexHullShape”,但对象已关闭。你能帮我吗?
https://cotosystem.com.br/fechado.png“原始”
https://cotosystem.com.br/shape.png“关闭”
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;
}
答案 0 :(得分:0)
与其他任何边界体积一样,凸包始终是封闭的。因此,恐怕您找不到想要的东西。