Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. import System;
  2.  
  3. import System.IO;
  4.  
  5. class SaveCubeMapToPngWizard extends ScriptableWizard {
  6.  
  7. var cubemap : Cubemap;
  8.  
  9. function OnWizardUpdate () {
  10. helpString = "Select cubemap to save to individual png";
  11. isValid = (cubemap != null);
  12. }
  13.  
  14. function OnWizardCreate ()
  15. {
  16. var width = cubemap.width;
  17. var height = cubemap.height;
  18.  
  19. Debug.Log(Application.dataPath + "/" +cubemap.name +"_PositiveX.png");
  20. var tex = new Texture2D (width, height, TextureFormat.RGB24, false);
  21. // Read screen contents into the texture
  22. tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveX));
  23. // Encode texture into PNG
  24. var bytes = tex.EncodeToPNG();
  25. File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_PositiveX.png", bytes);
  26.  
  27. tex.SetPixels(cubemap.GetPixels(CubemapFace.NegativeX));
  28. bytes = tex.EncodeToPNG();
  29. File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_NegativeX.png", bytes);
  30.  
  31. tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveY));
  32. bytes = tex.EncodeToPNG();
  33. File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_PositiveY.png", bytes);
  34.  
  35. tex.SetPixels(cubemap.GetPixels(CubemapFace.NegativeY));
  36. bytes = tex.EncodeToPNG();
  37. File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_NegativeY.png", bytes);
  38.  
  39. tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveZ));
  40. bytes = tex.EncodeToPNG();
  41. File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_PositiveZ.png", bytes);
  42.  
  43. tex.SetPixels(cubemap.GetPixels(CubemapFace.NegativeZ));
  44. bytes = tex.EncodeToPNG();
  45. File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_NegativeZ.png", bytes);
  46.  
  47.  
  48. DestroyImmediate(tex);
  49. }
  50.  
  51. @MenuItem("GameObject/Save CubeMap To Png ")
  52. static function SaveCubeMapToPng ()
  53. {
  54. ScriptableWizard.DisplayWizard(
  55. "Save CubeMap To Png", SaveCubeMapToPngWizard , "Save");
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement