Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TerrainData terrainData = terrain.terrainData;
- Texture2D holesMap = TexToTex2D(terrainData.holesTexture as RenderTexture, TextureFormat.R8);
- byte[] pngholesData = holesMap.EncodeToPNG();
- if (pngholesData != null)
- {
- File.WriteAllBytes(path + "/" + holesMap.name + ".png", pngholesData);
- }
- private Texture2D TexToTex2D(RenderTexture texture, TextureFormat format)
- {
- Texture2D texture2D = new Texture2D(texture.width, texture.height, format, false)
- {
- name = texture.name
- };
- RenderTexture currentRT = RenderTexture.active;
- RenderTexture renderTexture = new RenderTexture(texture.width, texture.height, 0, GraphicsFormat.R8_UNorm);
- RenderTexture.active = renderTexture;
- Graphics.Blit(texture, renderTexture);
- texture2D.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
- texture2D.Apply();
- RenderTexture.active = currentRT;
- renderTexture.Release();
- return texture2D;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement