Advertisement
RealDevMashup

PopulateTerrainMap

May 24th, 2024
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. void PopulateTerrainMap () {
  2.         NoiseCube noise = new NoiseCube();
  3.         // The data points for terrain are stored at the corners of our "cubes", so the terrainMap needs to be 1 larger
  4.         // than the width/height of our mesh.
  5.         for (int x = 0; x < width + 1; x++) {
  6.             for (int z = 0; z < width + 1; z++) {
  7.                 for (int y = 0; y < height + 1; y++) {
  8.  
  9.                     // Get a terrain height using regular old Perlin noise.
  10.                     float thisHeight = noise.Noise(x * scale, y * scale, z * scale);
  11.  
  12.                
  13.                     // Set the value of this point in the terrainMap.
  14.                     terrainMap[x, y, z] = thisHeight > threshold ? 1.0f : 0.0f;
  15.  
  16.                 }
  17.             }
  18.         }
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement