Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConvexPolyhedron: Tetrahedron working vs. not working #170

Open
bizzybora opened this issue Dec 29, 2022 · 3 comments
Open

ConvexPolyhedron: Tetrahedron working vs. not working #170

bizzybora opened this issue Dec 29, 2022 · 3 comments

Comments

@bizzybora
Copy link

bizzybora commented Dec 29, 2022

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

@vegolasse
Copy link

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)

@DakotaLarson
Copy link

Hey @vegolasse @bizzybora Did either of you find a resolution to this one?

@bizzybora
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants