-
Notifications
You must be signed in to change notification settings - Fork 741
Description
Hello,
I give a try to CANNON.Heightfield but I meet an issue during step(). I can see the javascript console log below in red, I suspect this message below is important. Issue seen on Cannon.js 0.6.0 (git extract from a couple of days).
.faceNormals[1] = Vec3(0,0,-1) looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule. (23:54:00:901 | error)
at ConvexPolyhedron.computeNormals (www/js/libs/cannon.js:7125:21)
at Heightfield.getConvexTrianglePillar (www/js/libs/cannon.js:8437:12)
at Narrowphase.(anonymous function).Narrowphase.convexHeightfield (www/js/libs/cannon.js:10590:21)
at Narrowphase.(anonymous function).Narrowphase.boxHeightfield (www/js/libs/cannon.js:10525:10)
at Narrowphase.getContacts (www/js/libs/cannon.js:9439:34)
at World.internalStep (www/js/libs/cannon.js:11243:22)
at World.step (www/js/libs/cannon.js:11088:14)
at xxx (www/js/main.js:178:17)
.vertices[5] = Vec3(-0.25,0.75,5.5) (23:54:00:902 | warning)
at www/js/libs/cannon.js:7127
.vertices[4] = Vec3(0.75,-0.25,5.5) (23:54:00:903 | warning)
at www/js/libs/cannon.js:7127
.vertices[3] = Vec3(-0.25,-0.25,5.5) (23:54:00:903 | warning)
at www/js/libs/cannon.js:7127
Right, it seems (-0.25,0.75,5.5) (0.75,-0.25,5.5) (-0.25,-0.25,5.5) are not in CCW order (right handed). Please find my (simplified) code below:
var grid_size = 10;
var matrix = new Array(2*grid_size);
for( var i=0; i<2*grid_size; i++)
{
matrix[i] = new Array(2*grid_size);
for( var j=0; j<2*grid_size; j++ )
{
matrix[i][j] = i - j;
}
}
var hfShape = new CANNON.Heightfield(matrix, { elementSize:1 });
var hfBody = new CANNON.Body({mass: 0});
hfBody.addShape(hfShape);
The issue disappears if I guarantee Y heights are smaller (fix code: matrix[i][j] = i - j - 10;)