I got the ExportToPng.js script from the Unify Wiki. The code doesnt seem to work for the unity 3.5 build, and i’m not fluent in Editor scripts So i cant seem to figure out what the problem is. Heres the wiki: http://www.unifycommunity.com/wiki/index.php?title=ExportNormalmap
The errors i get are :
Unsupported image format - the texture needs to be ARGB32 or RGB24
UnityEngine.Texture2D:EncodeToPNG()
ExportNormalMap:ExportNormalmap() (at Assets/Editor/ExportNormalMap.js:17)
and
NullReferenceException: Object reference not set to an instance of an object
System.IO.File.WriteAllBytes (System.String path, System.Byte[] bytes)
ExportNormalMap.ExportNormalmap () (at Assets/Editor/ExportNormalMap.js:20)
Here’s the script (I fixed one small error from the one on the wiki: AssetDatabase.Refresh(); instead of AssetDatabase.RefreshDelayed()![]()
@MenuItem ("Assets/Export Normalmap...")
static function ExportNormalmap () {
var tex = Selection.activeObject as Texture2D;
if (tex == null) {
EditorUtility.DisplayDialog("No texture selected", "Please select a texture.", "Cancel");
return;
}
// Force the texture to be readable so that we can access its pixels
var texPath = AssetDatabase.GetAssetPath(tex);
var texImport : TextureImporter = AssetImporter.GetAtPath(texPath);
texImport.isReadable = true;
AssetDatabase.ImportAsset(texPath, ImportAssetOptions.ForceUpdate);
var bytes = tex.EncodeToPNG();
var path = EditorUtility.SaveFilePanel("Save Texture", "", tex.name+"_normal.png", "png");
if (path != "") {
System.IO.File.WriteAllBytes(path, bytes);
AssetDatabase.Refresh(); // In case it was saved to the Assets folder
}
}