I’ve imported your code in a fiddle to debug it: https://jsfiddle.net/0kqtrb3s/4/
The problem is that you recompute the position
attribute but you don’t recompute the bounding volumes of the geometry. That means the bounding volumes have a very large scale and thus won’t detect the intersections. Doing the following after recomputing position
should solve your issue:
terrainMesh.geometry.attributes.position = newPositionAttribute;
terrainMesh.geometry.computeBoundingBox(); // FIX
terrainMesh.geometry.computeBoundingSphere(); // FIX