How do I reliably interpolate Z elevation across a distorted mesh?

0 favourites
  • 2 posts
From the Asset Store
mesh 3D objects "hemisphere, oval, tunnel and other various shapes."
  • Hi

    I have been playing with using meshes to create uneven ground for a 3D game. So a tiled background has a mesh set on it and then the Z elevation of each mesh point is randomised.

    I then obviously want the player and NPCs to adjust their Z elevation depending on where they are on the mesh.

    So I thought that Bilinear Interpolation would be the solution, however I'm finding there are a number of cases where it falls down. Namely when there is a diagonal 'fold line', either a 'ridge' or 'valley', across that section of the mesh.

    Here is an example of what I mean. The numbers represent the Z elevation of each of the surrounding 4 mesh points. The dotted line is a 'ridge' that passes diagonally across this section of the mesh.

    If I want to find the Z elevation of the centre of this section of the mesh Bilinear Interpolation will return the value 1.5 but the correct answer is clearly 2.

    I also gave Cubic Interpolation a try (though I'm not completely sure I'm doing it right) and that returned 1.75. Better but still not correct.

    Open to any assistance or suggestions of how to do this correctly.

    Thanks!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • So I solved this issue and, in case it helps anyone else, the answer is to work out which of the two triangles your point of interest is in and then interpolate using the three mesh points of that triangle. Points on the diagonal line are essentially in both triangles so it doesn't matter which one you use to solve those.

    What I was trying to do previously didn't work because the two triangles are two different planes so you can't interpolate using the four values all at once as that only works for single planes.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)