The source code is here and here.

I mostly stole the code from a three.js example, since I thought it looked good.

Fast heightfield lookup

The source code is here.

I first thought I had to do bilinear interpolation, so I implemented that, but of course, it was just triangles in the mesh, no bilinear interpolation needed. So it’s just finding the correct position in the heightfield and then interpolating the triangles, using math from here.