Unity 输出360图片

    技术2022-07-10  134

    Unity 输出360图片

    这里需要创建两个RendreTextures

    using System.Collections; using System.Collections.Generic; using UnityEngine; public class AllenCreact360_001 : MonoBehaviour { public Camera targetCamera; public RenderTexture cubeMapLeft; public RenderTexture equirectRT; // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) Capture(); } public void Capture() { targetCamera.RenderToCubemap(cubeMapLeft); cubeMapLeft.ConvertToEquirect(equirectRT); Save(equirectRT); print("👴来了"); } public void Save(RenderTexture rt) { Texture2D tex = new Texture2D(rt.width, rt.height); RenderTexture.active = rt; tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); RenderTexture.active = null; byte[] bytes = tex.EncodeToJPG(); string path = Application.dataPath + "/Panorama" + ".jpg"; System.IO.File.WriteAllBytes(path,bytes); ; } }

    参考连接:https://www.youtube.com/watch?v=nodjrfARFA0

     

     

    这里插播另一篇笔记的链接,在这里,我遇到了一个问题,没有MonoBehaviour的高亮,和代码提示。

    解决方案在此篇连接中,第二个问题中有解释和参考链接。

    https://blog.csdn.net/Allen7474/article/details/106870098

    Processed: 0.010, SQL: 9