Hello,
First of all my hat off to you guys, your framework is amazing and I'm using it with love in my heart.
I have a terrain mesh which I need to raycast on to determine the walking height for my character.
My terrain mesh consists of 16 planes (tiles) that are merged together and is located at (0,0,0). Since every tile needs a different texture I simply create a plane, give it a texture, translate it, alter the vertices height using a perlin function and merge it with the terrain mesh (using GeometryUtils.merge() )
I added the mesh and my character, and then I do a raycast like this:
var ray = new THREE.Ray( player.position.clone().addSelf( new THREE.Vector3(0, 50, 0) ), new THREE.Vector3(0, -1, 0));
var intersects = ray.intersectObject(terrainMesh);
if ( intersects.length > 0 ) {
However, the distance returned from intersects is always 50, even though the vertices from the terrain are raised!
What am I doing wrong?
Thanks!
Ray.intersectObject()
-- without the 's' -- does not sort the returned array. #1837.EDIT: Hmm..., on second thought, they may not be the problem... but it's worth knowing, anyway...
Thanks for the links, that clarified some things.
Yeah I'm not sure either. I'm using the old CollisionUtils as a (temporary?) solution.
If you modify the geometry you need to call
geometry.computeCentroids();
geometry.computeFaceNormals();
before ray casting it.
Thank you, that did the trick!
I concur. Same problem, fixed!
Although, yeah ... beware the non-planar quads!
THREE.GeometryUtils.triangulateQuads( geometry );
If anyone else ever finds this - computeCentroids was dropped a long time ago.
Also make sure geometry.computeBoundingSphere()
is run after altering the vertices
Most helpful comment
If anyone else ever finds this - computeCentroids was dropped a long time ago.
Also make sure
geometry.computeBoundingSphere()
is run after altering the verticesAnswer from this StackOverflow question