duck

Unity code snippet to save terrain splatmap as texture asset

Apr 22nd, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1.         data = terrain.terrainData;
  2.         int w = data.alphamapWidth;
  3.        
  4.         float[,,] splatmapData = data.GetAlphamaps(0, 0, w, w);
  5.         Color[] mapColors = targetTexture.GetPixels();
  6.        
  7.         int numSplatMaps = splatmapData.GetLength(2);
  8.        
  9.         for (int z=0; z<numSplatMaps; ++z)
  10.         {
  11.             for (int y=0; y<w; ++y)
  12.             {
  13.                 for (int x=0; x<w; ++x)
  14.                 {
  15.                     mapColors[x*w + y][z] = splatmapData[x,y,z];
  16.                 }
  17.             }
  18.         }
  19.        
  20.         targetTexture.SetPixels( mapColors );
  21.         var bytes = targetTexture.EncodeToPNG();
  22.         File.WriteAllBytes(Application.dataPath + "/"+targetTexture.name+".png", bytes);
Advertisement
Add Comment
Please, Sign In to add comment