BabylonJS/Babylon.js — pull request #176 by chrisbarmonde (2014-04-11 01:56:06+00:00)
Title: Fix collisions after a mesh has been repositioned

So bear with me here because 1) I am terrible at math and 3D math is way over my head, 2) it might just be that I'm dumb and there's some other way to fix this that I couldn't find in the docs, or 3) I might just be architecting my code the wrong way. But anyway.

I've been developing a small 2.5D platform puzzler where you move some boxes around (simple meshes generated with `BABYLON.Mesh.CreateBox`. What I found was that after your first collision with a mesh, if you reposition it, the position / trianglePlane caches cause the collision detection to break in the mesh's new location because they aren't regenerated.

This PR is kind of a stupidly naive way of forcing regeneration by keeping track of the number of times `_generatePointsArray` has been called and using that to 'version' the caches and invalidate any objects using an old version. But it still requires you to manually call `_resetPointsArrayCache` after you reposition a mesh. I'm don't think that there's an automated way to do that without forcing repositioning from some kind of `setPosition` function or something.

Any thoughts or better ways of solving the problem are appreciated!

(Also, apologies for some of the whitespace changes. I have my editor set to strip trailing whitespace on file save.)