C# 统一,将立方体贴图保存为一个圆形图像

C# 统一,将立方体贴图保存为一个圆形图像,c#,unity3d,C#,Unity3d,我有立体地图。我需要将其保存在一个圆形图像中,例如PNG。我在网上花了好几个小时搜索我失败的东西。我怎么做?可能吗 我有图像:joxi.ru/zANd66wSl6Kdkm 我需要保存在png:joxi.ru/12MW55wT40LYjr部件代码中,它可以帮助您: tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveZ)); bytes = tex.EncodeToPNG(); File.WriteAllBytes(Application.d

我有立体地图。我需要将其保存在一个圆形图像中,例如PNG。我在网上花了好几个小时搜索我失败的东西。我怎么做?可能吗

我有图像:joxi.ru/zANd66wSl6Kdkm

我需要保存在png:joxi.ru/12MW55wT40LYjr部件代码中,它可以帮助您:

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

您可以创建一个继承ScriptableWizard类的类,该类将从特定转换中呈现立方体映射。这是我的密码:

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);

    }
}
使用UnityEngine;
使用UnityEditor;
使用系统集合;
使用System.IO;
公共类RenderCubemapWizard:ScriptableWizard
{
公共转换渲染器位置;
公共立方体地图立方体地图;
void OnWizardUpdate()
{
string helpString=“选择要从中渲染的变换和要渲染到中的立方体贴图”;
bool isValid=(renderFromPosition!=null)&(cubemap!=null);
}
void OnWizardCreate()
{
//创建用于渲染的临时摄影机
GameObject go=新游戏对象(“CubemapCamera”);
go.AddComponent();
//把它放在物体上
go.transform.position=renderFromPosition.position;
go.transform.rotation=Quaternion.identity;
//渲染成立方体贴图
go.GetComponent().RenderToCubemap(cubemap);
//销毁临时摄像机
立即(go);
ConvertToPng();
}
[MenuItem(“游戏对象/渲染成立方体贴图”)]
静态void rendercutubemap()
{
ScriptableWizard.DisplayWizard(
“渲染立方体贴图”、“渲染!”);
}
void ConvertToPng()
{
Log(Application.dataPath+“/”+cubemap.name+“_PositiveX.png”);
var tex=新纹理2d(cubemap.width,cubemap.height,TextureFormat.RGB24,false);
//将屏幕内容读入纹理
tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveX));
//将纹理编码为PNG
var bytes=tex.EncodeToPNG();
File.writealBytes(Application.dataPath+“/”+cubemap.name+“\u PositiveX.png”,字节);
tex.SetPixels(cubemap.GetPixels(CubemapFace.NegativeX));
字节=tex.EncodeToPNG();
File.writealBytes(Application.dataPath+“/”+cubemap.name+“\u NegativeX.png”,字节);
tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveY));
字节=tex.EncodeToPNG();
File.writealBytes(Application.dataPath+“/”+cubemap.name+“\u PositiveY.png”,字节);
tex.SetPixels(cubemap.GetPixels(CubemapFace.NegativeY));
字节=tex.EncodeToPNG();
File.writealBytes(Application.dataPath+“/”+cubemap.name+“\u NegativeY.png”,字节);
tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveZ));
字节=tex.EncodeToPNG();
File.writealBytes(Application.dataPath+“/”+cubemap.name+“_PositiveZ.png”,字节);
tex.SetPixels(cubemap.GetPixels(CubemapFace.NegativeZ));
字节=tex.EncodeToPNG();
File.writealBytes(Application.dataPath+“/”+cubemap.name+“\u NegativeZ.png”,字节);
(tex);
}
}
这基本上是从您在向导中指定的给定位置创建一个新的立方体贴图(要使用向导,请转到顶部菜单中的GameObject,在列表底部,您将看到“渲染为立方体贴图”)。然后,它将获取立方体贴图的六个位置,并在ConvertToPng()函数中将其从中转换为PNG文件。这对我有用,对你也应该有用,因为它本质上只需要一个变换位置。 很抱歉,我尝试了这么长时间来简化它,但是我尽可能地简化了它

以下是帮助我得出这一结论的链接:


这是一个让任何人都能帮助你的问题。您需要将立方体贴图保存为圆形图像吗?你在用什么软件。。。您试图编写的代码是什么?这段代码有哪些错误?需要具体帮助。我有cubemap:我需要保存在png:Part代码中,它可以帮助您:tex.SetPixels(cubemap.GetPixels(CubemapFace.PositiveZ));字节=tex.EncodeToPNG();File.writealBytes(Application.dataPath+“/”+cubemap.name+“_PositiveZ.png”,字节);好的,大卫博士,塔克斯。我是英语初学者。但是你能帮我吗?如何在纹理中保存立方体贴图?我使用UNITY3D,用c#编码。对不起,我不太了解Unity,但现在的问题是,你应该希望很快能有人来帮助你。祝你好运。谢谢,祝你也好运。希望原力与您同在)P.S.这将把.png文件保存到您项目的资产文件夹中。Unity可能需要一点时间才能显示在资产面板中。谢谢您的帮助,但是。。。我也做了类似的事情:6张截图我也能收到。我需要得到填充立方体贴图的一个“圆形”纹理。一个典型的例子:joxi.ru/12MW55wT40LYjr。看起来他们截取了立方体贴图检查员的屏幕快照,然后裁剪出立方体贴图的圆形预览部分。例如,我刚刚被剪切。我不需要这些面,我想从渲染立方体贴图中获取纹理,并将其编码为png或任何其他格式。你只是需要它更自动化,还是只是裁剪它有什么问题?