I’m not familiar with working with mesh verticies at runtime, so assistance would be greatly appreciated. Since the terrain engine can’t handle cliffs (for texturing purposes) and overhangs, I’m creating these aspects of the terrain as models. However, I am writing a script to procedurally place vegetation across the entire terrain (the actual terrain object as well as the modeled terrain). I can handle placement on the terrain object. However, with the cliffs, plateaus, mesas, etc.(the terrain models), in order to place vegetation, I need to first figure out how to determine the slope at any given point on the objects? Does anyone have any idea how I would accomplish this? Or maybe there is another way to randomly place vegetation on the terrain models such that it isn’t growing on the cliff faces?
You can get vertex normals from Mesh.normals; they tell you what direction is ‘away from’ the vertex. Mesh.triangles is an array of indices into Mesh.verteices, where every three values identify the three vertices that make up that triangle. So, you can calculate the normal of a face (triangle) using a tri-linear interpolation between the three vertex normals (i.e. average the normals, basically). Use the dot product of the face normal with the up-axis (Vector3.Dot(Vector3.up, normal)) to calculate the slope.