ConvexPolyhedron: Tetrahedron working vs. not working
Hello,
can someone explain or verify why this is working:
var c1 = new CANNON.Vec3(0,0,0)
var c2 = new CANNON.Vec3(1,0,0)
var c3 = new CANNON.Vec3(1,1,0)
var c4 = new CANNON.Vec3(0.5,0.5,-1)
var convexShape = new CANNON.ConvexPolyhedron({
vertices: [c1, c2, c3, c4],
faces: [[0,1,2],[1,0,3],[2,1,3],[0,2,3]]
})
vs. this throwing error:
var c1 = new CANNON.Vec3(0,0,0.1)
var c2 = new CANNON.Vec3(1,0,0.1)
var c3 = new CANNON.Vec3(1,1,0.1)
var c4 = new CANNON.Vec3(0.5,0.5,-1)
var convexShape = new CANNON.ConvexPolyhedron({
vertices: [c1, c2, c3, c4],
faces: [[0,1,2],[1,0,3],[2,1,3],[0,2,3]]
})
?
I only changed the z-coordinates by 0.1. The error thrown is "faceNormals[1] = Vec3(0,-0.9103664774626048,-0.413802944301184) looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule."
I am thinking about this since two days it it happens also with other geometries (e.g. cubes), but this is the simplest case.
Thank you in advance
I've been scratching my head over the same error message, but for a different structure, which indeed also caused problems when colliding with some surfaces. My own visual physics debugger showed all normals looking alright. Turns out the check to see if the normal is correct does a dot product between the normal of the surface and it's first point. My conclusion from that is that 0,0,0 must be inside the ConvexPolyhedron for it to work properly. In your first example it's just inside and in your other it might not be.
I'm not sure it helps, creating the shape around 0,0,0 solved my problem (basically just averaged all my vertices to get a middle and moved them there, then used that as an offset when adding it to the body)
Hey @vegolasse @bizzybora Did either of you find a resolution to this one?
I never tested vegolasse's proposed solution because I used heightfield instead. But give it a try, I would like to know, whether it works or not.