schteppe / cannon.js

A lightweight 3D physics engine written in JavaScript.
http://schteppe.github.com/cannon.js
MIT License
4.72k stars 711 forks source link

"HeightField vs. Sphere"-Collision Error Messages #201

Open jppresents opened 9 years ago

jppresents commented 9 years ago

Hi,

I am experimenting with threejs + cannon + blender.

I made a distorted plane in blender for which I calculate the height map and then use cannon to collide balls on this heightmap. (Currently looks like this: http://imgur.com/GokspYg )

I have tried using: the prebuild file from master branch, a self build (grunt) file from master branch and a self build (grunt) file from dev branch, all get these errors when colliding spheres against the heightfield (in the latest chrome):

I get many errors like this in the console log:

.vertices[5] = Vec3(-0.25,0.75,0.4393504052508578)
.vertices[4] = Vec3(0.75,-0.25,0.4393504052508578)
.vertices[3] = Vec3(-0.25,-0.25,0.4393504052508578)
.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.
  ConvexPolyhedron.computeNormals   
  Heightfield.getConvexTrianglePillar   
  Narrowphase.(anonymous function).Narrowphase.sphereHeightfield    
  Narrowphase.getContacts   
  World.internalStep    
  World.step    
  updatePhysics 
  render    

Since this spams the console it results in major framerate drops (even if the console is not opened).

Test it here: http://jppresents.net/static/github/cannonHeightfield/index.html code here: http://jppresents.net/static/github/cannonHeightfield/testarea.js (this is really just testing code, so excuse the style and other dirty stuff :) )

(the currently used cannon.js is grunt-build from dev branch)

schteppe commented 9 years ago

Can you try making all height values positive?

jppresents commented 9 years ago

Thanks schteppe, that is the solution. I would suggest that the heightfield on construction checks for this and rejects the matrix, if it has negative values.

(I really couldn't make heads or tails of the error I posted here - if it had just said "only positive values" it would have been resolved quickly and without your help.)

You can mark this as resolved (or not - if you want to keep it open until you include the negative value check and error/warning message).

schteppe commented 9 years ago

Actually the Heightfield should be able to handle any number input. This is a bug and you confirmed it :) Let's keep it open until resolved.

Thanks! If you find other odd things, don't be afraid to file more issues.