Hi,
the past days i’ve been working on getting the convex polyhedron collider working. Now everything is set in shape, position and rotation, verified with the cannon debugger.
The cube does collide, but enters the body, sticks in it, and slowly gets pushed out. I am also getting errors such as “.faceNormals[120] = Vec3(0.8228529875619893,-0.0739619522514679,-0.5634204384644383) looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.”
From all the sources i was able to find I assembled the code below:
let meshgeometry = new ConvexGeometry( vertex_positions);
material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
mesh = new THREE.Mesh( meshgeometry, material );
let geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', mesh.geometry.getAttribute('position'));
geometry.setAttribute('normal', mesh.geometry.getAttribute('normal'));
geometry = BufferGeometryUtils.mergeVertices(geometry, 1e-1);
for(var i = 0; i < position.length; i += 3) {
points.push(new CANNON.Vec3(position[i] - com.x, position[i + 1] - com.y, position[i + 2] - com.z));
}
for(var i = 0; i < geomFaces.length; i += 3)
faces.push([geomFaces[i], geomFaces[i+1], geomFaces[i+2]]);
let shape = new CANNON.ConvexPolyhedron({vertices: points, faces:faces})
const physicsBody = new CANNON.Body({ mass: 2, shape: shape ,
collisionFilterGroup: 2,
collisionFilterMask: 1 })
return physicsBody
The cube to collide is as follows
const cubeBody = new CANNON.Body({ mass: mass,
shape: cubeShape,
collisionFilterGroup: 1,
collisionFilterMask: 1|2})
Is it something with coplanar faces like described here?
https://github.com/schteppe/cannon.js/issues/164
But merging vertices should fix this, or how else to do it? Also this issue is from 2014…
Hope this can be helped!