Possible to retrieve reference to vertices of Terrain?

Heyas,
My goal is to take a mountain I sculpted with the terrain editor, and create another mesh (actually a layer) that sits on top, to simulate a sort of avalanche. I’d like to know if it’s possible to obtain the location of the vertices of the mountain/terrain, so that I can generate the corresponding ‘overlay mesh’. If it’s not, is there a different way to do this?

Thanks,
Ryan

You can get the heights as floats from Terrain.terrainData. To convert those to Vector3 values you have to use those height values with some maths, depending on the resolution, size, and location of your terrain.

You can’t get the terrain vertices as such, since the terrain meshes are dynamic and depend on the camera’s viewpoint.

Or you could just use TerrainData.GetInterpolatedHeight.

–Eric

I assumed he meant at design time, not runtime.

Perhaps I’m totally on crack though and it’s not possible at design time either. If so, then you could do a discrete raycast approach to build your secondary mesh, i.e. loop through the X,Y dimensions of your terrain at whatever course step value you want and raycast down to find the Vector3.

The answer is still TerrainData.GetInterpolatedHeight. :wink: If you have a terrain then you have TerrainData, runtime or not. Actually, Terrain.SampleHeight works too and may be easier to use (since it takes a world-space Vector3).

–Eric

Awesome!

Thanks guys…
I change my technique by not relying on terrain data. Instead, I grab a RaycastHit from camera to the terrain, and then interpolate that towards other points along the RaycastHit.normal.

I did try terrainData.GetIterpolatedHeight() and it did work as expected.

Ryan