在unity内生成模型全景图

直接上代码

    [MenuItem("生成图片/CreatPic")]
    public static void CreatPic()
    {
        Camera cam = Camera.main;
        //可修改数值   new RenderTexture(4096, 4096, 32);
        RenderTexture cubemap = new RenderTexture(2048, 2048, 16);
        cubemap.dimension = TextureDimension.Cube;
        cam.RenderToCubemap(cubemap, 63, Camera.MonoOrStereoscopicEye.Mono);
        //可修改数值 new RenderTexture(4096, 4096, 32);
        RenderTexture equirect = new RenderTexture(1920, 1080, 8);
        cubemap.ConvertToEquirect(equirect, Camera.MonoOrStereoscopicEye.Mono);

        RenderTexture.active = equirect;
        Texture2D tex = new Texture2D(equirect.width, equirect.height, TextureFormat.ARGB32, false, true);
        tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
        RenderTexture.active = null;
        GL.Clear(true, true, Color.black);
        tex.Apply();
        byte[] bytes = tex.EncodeToTGA();
        CreateDirectroryOfFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\全景图\\)");
        System.IO.File.WriteAllBytes(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop)
            + "\\全景图\\" + System.DateTime.Now.Ticks + ".tga", bytes);

    }

    public static void CreateDirectroryOfFile(string filePath)
    {
        Debug.Log($"CreateDirectrory {filePath}[folder_path],");
        if (!string.IsNullOrEmpty(filePath))
        {
            string dir_name = Path.GetDirectoryName(filePath);
            if (!Directory.Exists(dir_name))
            {
                Debug.Log($"No Exists {dir_name}[dir_name],");
                Directory.CreateDirectory(dir_name);
            }
            else
            {
                Debug.Log($"Exists {dir_name}[dir_name],");
            }
        }
    }

在桌面生成TGA格式的全景图,如果想要别的格式用格式工厂轻松搞定

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

育婴房扛把子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值