/// <summary>
/// Creates a 3D texture.
/// </summary>
public static Texture3D CreateTexture3DFromResources(string texturePathFromResources, int slices)
{
Texture3D texture3D = null;
Texture2D texture2D = Resources.Load<Texture2D>(texturePathFromResources);
if (texture2D != null)
{
int height = texture2D.height;
int width = texture2D.width / slices;
Color[] pixels2D = texture2D.GetPixels();
Color[] pixels3D = new Color[pixels2D.Length];
for (int z = 0; z < slices; ++z)
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x)
pixels3D[x + (y * width) + (z * (width * height))] = pixels2D[x + (z * width) + (((width - y) - 1) * width * height)];
texture3D = new Texture3D(width, height, slices, TextureFormat.ARGB32, false);
texture3D.SetPixels(pixels3D);
texture3D.Apply();
texture3D.filterMode = FilterMode.Trilinear;
texture3D.wrapMode = TextureWrapMode.Clamp;
texture3D.anisoLevel = 1;
}
else
Debug.LogWarning(string.Format("Texture '{0}' not found in 'Resources/Textures' folder.", texturePathFromResources));
return texture3D;
}