Someone asked if i could add a the ability to separate or extract the images from a LightShape cube map. I decided I would just write up a quick and dirty utility separately.
Instructions:
- Put this in a folder called Editor in your assets
- drag the cubemap you want to separate into the SplitCube spot
- set the resolution to the resolution of the cube map you are splitting.(too lazy to auto detect)
- wait for unity to update the project to reveal the new .png files.
here you go! feel free to make it better.
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Collections;
using System.Collections.Generic;
public class CubeSplitter : EditorWindow
{
Cubemap splitCube;
Color[] CubeMapColors;
int splitSize;
[MenuItem ("Window/CubeSplitter")]
static void Init ()
{
CubeSplitter window = (CubeSplitter)EditorWindow.GetWindow (typeof (CubeSplitter), false);
window.maxSize = new Vector2(512, 155);
window.minSize = window.maxSize;
window.title = ("Cube Splitter!");
window.Show();
}
void OnGUI ()
{
GUILayout.Label("Choose the Cube Map you want to save as 6 images and click EXPORT!", EditorStyles.boldLabel);
splitCube = EditorGUILayout.ObjectField("My Cubemap:", splitCube, typeof(Cubemap), false) as Cubemap;
GUILayout.Label("Make sure to set the Size to the same as the Cubemap you are using", EditorStyles.boldLabel);
splitSize = EditorGUILayout.IntField("CubeMap Size: ", splitSize);
if(GUILayout.Button("EXPORT!"))
{
if(splitCube)
{
Export();
}
if(!splitCube)
{
Debug.Log ("Forget Something?");
}
}
}
void Export()
{
var filePath = AssetDatabase.GetAssetPath(splitCube);
Texture2D tex = new Texture2D (splitSize, splitSize, TextureFormat.RGB24, false);
CubeMapColors = splitCube.GetPixels(CubemapFace.PositiveY);
tex.SetPixels(CubeMapColors, 0);
tex.Apply ();
byte[] bytes = tex.EncodeToPNG();
File.WriteAllBytes(filePath + "_Bot.png", bytes);
CubeMapColors = splitCube.GetPixels(CubemapFace.NegativeY);
tex.SetPixels(CubeMapColors, 0);
tex.Apply ();
bytes = tex.EncodeToPNG();
File.WriteAllBytes(filePath + "_Top.png", bytes);
CubeMapColors = splitCube.GetPixels(CubemapFace.PositiveX);
tex.SetPixels(CubeMapColors, 0);
tex.Apply ();
bytes = tex.EncodeToPNG();
File.WriteAllBytes(filePath + "_Lef.png", bytes);
CubeMapColors = splitCube.GetPixels(CubemapFace.NegativeX);
tex.SetPixels(CubeMapColors, 0);
tex.Apply ();
bytes = tex.EncodeToPNG();
File.WriteAllBytes(filePath + "_Rig.png", bytes);
CubeMapColors = splitCube.GetPixels(CubemapFace.PositiveZ);
tex.SetPixels(CubeMapColors, 0);
tex.Apply ();
bytes = tex.EncodeToPNG();
File.WriteAllBytes(filePath + "_Fro.png", bytes);
CubeMapColors = splitCube.GetPixels(CubemapFace.NegativeZ);
tex.SetPixels(CubeMapColors, 0);
tex.Apply ();
bytes = tex.EncodeToPNG();
File.WriteAllBytes(filePath + "_Bak.png", bytes);
this.Close();
}
}
Haha, after I wrote this i was able to also find this…at least I learned something new!
http://answers.unity3d.com/questions/9189/how-can-i-extract-the-individual-faces-from-a-gene.html