Unity, Save the cube image to one environment

I have a cubemap. I need to save it in a circular image, for example, in PNG. Many hours of searching the Internet in that I have failed. How am i doing this? Is it possible?

I have an image: joxi.ru/zANd66wSl6Kdkm

I need to save in png: joxi.ru/12MW55wT40LYjr the part code that will help you:

tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveZ)); bytes = tex.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_PositiveZ.png", bytes); 
+4
source share
1 answer

You can create a class that inherits from the ScriptableWizard class, which displays a cube file from a specific transformation. Here is my code:

 using UnityEngine; using UnityEditor; using System.Collections; using System.IO; public class RenderCubemapWizard : ScriptableWizard { public Transform renderFromPosition; public Cubemap cubemap; void OnWizardUpdate() { string helpString = "Select transform to render from and cubemap to render into"; bool isValid = (renderFromPosition != null) && (cubemap != null); } void OnWizardCreate() { // create temporary camera for rendering GameObject go = new GameObject("CubemapCamera"); go.AddComponent<Camera>(); // place it on the object go.transform.position = renderFromPosition.position; go.transform.rotation = Quaternion.identity; // render into cubemap go.GetComponent<Camera>().RenderToCubemap(cubemap); // destroy temporary camera DestroyImmediate(go); ConvertToPng(); } [MenuItem("GameObject/Render into Cubemap")] static void RenderCubemap() { ScriptableWizard.DisplayWizard<RenderCubemapWizard>( "Render cubemap", "Render!"); } void ConvertToPng() { Debug.Log(Application.dataPath + "/" +cubemap.name +"_PositiveX.png"); var tex = new Texture2D (cubemap.width, cubemap.height, TextureFormat.RGB24, false); // Read screen contents into the texture tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveX)); // Encode texture into PNG var bytes = tex.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_PositiveX.png", bytes); tex.SetPixels(cubemap.GetPixels(CubemapFace.NegativeX)); bytes = tex.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_NegativeX.png", bytes); tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveY)); bytes = tex.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_PositiveY.png", bytes); tex.SetPixels(cubemap.GetPixels(CubemapFace.NegativeY)); bytes = tex.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_NegativeY.png", bytes); tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveZ)); bytes = tex.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_PositiveZ.png", bytes); tex.SetPixels(cubemap.GetPixels(CubemapFace.NegativeZ)); bytes = tex.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/" + cubemap.name +"_NegativeZ.png", bytes); DestroyImmediate(tex); } } 

Basically, a new cube file is created from the given position, which you specify from the wizard (to use the wizard, go to GameObject in the upper menu, and at the bottom of the list you will see "Render to Cubemap"). He then grabs six cubemap positions and converts them to a PNG file using the ConvertToPng () function. This works for me, and it should work for you, since it essentially only needs a conversion position. Sorry how long he has been trying to simplify it, but it is simplified, how could I do it.

Here are the links that helped me reach this conclusion:

How to convert face to png

Unity script wizard for cubemap rendering

+2
source

Source: https://habr.com/ru/post/1239171/


All Articles