Unity3D创建Texture3D

创建Texture3D,本文以159张128*128图片转化Text3D为例

    public Texture2D[] sourceTextures;
    Texture3D texture3D;
    Texture3D CreateText3D(int width, int height, int deep)
    {
        List colorList = new List();
        texture3D = new Texture3D(width, height, deep, TextureFormat.RGBA32, true);
        for (int z = 0; z < deep; z++)
        {
            Color[] c = sourceTextures[z].GetPixels();
            for (int i = 0; i < c.Length; i++)
            {
                colorList.Add(c[i]);
            }
        }
        texture3D.SetPixels32(colorList.ToArray());
        texture3D.Apply();
        //保存到本地
        AssetDatabase.CreateAsset(texture3D, "Assets/texture3D_128_159.asset");
        return texture3D;
    }

调用方法,CreateText3D(128, 128, 159)

你可能感兴趣的:(Unity基础)