[英]cannon-es crashes whenever there is a collision between Convex polyhedrons
我正在嘗試在 three.js 和 cannon-es 中實現一個骰子滾筒。 如果我只有一個骰子,它工作得很好。 它以合理的方式在地平面上滾動。
當我添加另一個骰子時,它在地平面上也能正常工作,但一旦兩個CANNON.ConvexPolyhedron
對象發生碰撞,它就會完全崩潰並使模擬崩潰。
碰撞后我收到垃圾郵件的錯誤是這個
cannon-es.js:920 Uncaught TypeError: Cannot read properties of undefined (reading 'x')
at Vec3.copy (cannon-es.js:920:21)
at ConvexPolyhedron.clipFaceAgainstHull (cannon-es.js:2662:24)
at ConvexPolyhedron.clipAgainstHull (cannon-es.js:2404:12)
at Narrowphase.convexConvex (cannon-es.js:10916:10)
at Narrowphase.getContacts (cannon-es.js:10608:33)
at World.internalStep (cannon-es.js:12649:22)
at World.step (cannon-es.js:12515:12)
at updatePhysics (rolling.svelte:154:11)
at animate (rolling.svelte:142:5)
我正在使用來自 three.js 的 STL 加載程序來加載一個 stl 文件的二十面骰子,然后我正在創建一個像這樣的炮身
function createConvexHull(mesh: THREE.Mesh) {
const position = mesh.geometry.attributes.position.array
const points: CANNON.Vec3[] = []
const faces: number[][] = []
for (let i = 0; i < position.length; i += 3) {
points.push(new CANNON.Vec3(position[i], position[i + 1], position[i + 2]))
}
for (let i = 0; i < position.length / 3; i += 3) {
faces.push([i, i + 1, i + 2])
}
const convexGeometry = new CANNON.ConvexPolyhedron({
vertices: points,
faces: faces
})
const body = new CANNON.Body({ mass: 1 })
body.addShape(convexGeometry)
return body
}
我幾乎不知道出了什么問題,因為錯誤消息並沒有說明太多,但我已經嘗試在 ThreeJS 網格上計算頂點法線,但什么也沒做。
我也嘗試過合並頂點,因為我讀到其他人對此有疑問(在創建大炮主體之前合並)
geometry = BufferGeometryUtils.mergeVertices(geometry, 0.01)
但同樣,它什么也沒做
我只是猜測,但您可以嘗試定義法線
new ConvexPolyhedron({ vertices, faces, normals });
我遇到了凸形碰撞的奇怪行為(不是錯誤,而是像將其中一個碰撞物體發射到空隙中),我可以通過重新計算法向量來解決
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.