I start with a plane, subdivide it into many small tiles, raise the vertices to create a terrain. I also have a vertical gradient texture: the bottom edge of the texture is blue (sea), the top edge is white (snow), the middle levels are shades of green and brown. The terrain is assigned the texture.
The question is how to do the UV programmatically? I want a Python script that can assign each vertices' v equal to its normalized z.
Ideally, I can shape the terrain (move mesh vertices) in 3D view, and run the script anytime. Then the terrain will have a height-dependent texture.
It seems all I need is to do is:
Run through all vertices in the mesh to find zMin and zMax
Run through all vertices and set u=0.5, v=(z-zMin)/(zMax-zMin)
But I don't know how to do it in Blender with Python, Can anyone please help?