- Home /
Export Normal Map to *png
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
}
}
Answer by Nest · Apr 20, 2012 at 05:03 PM
it work but export in gray scale and when you want import and use again it says "This texture is not marked as a normal map" when click fix it change color to blue scale
so before save open your texture changed to normal map check "Override for Standalone" and change max size to what you want and format to "Truecolor"
BUT! is alternative program work on MAC it call NMG - Normal Map Generator
Answer by dvochin2 · Mar 05, 2013 at 05:31 AM
Hi, trying this script on a normal map created from grayscale and saved with this tool, it fails at line 'var bytes = tex.EncodeToPNG()' with an error 'Unsupported texture format - needs to be ARGB32, RGBA32, RGB25 or Alpha8'
(Checking with the debugger, the file format is DXT5 (and Unity GUI shows DXTnm)
Is there a way to overcome this?
Many thanks! :)
Answer by TarAlacrin · Apr 15, 2014 at 04:32 AM
Here's the real solution; go to the texture's import settings change the texture type to "Advanced"; then at the bottom where it says format; change that to RGBA 32 bit
Your answer
![](https://koobas.hobune.stream/wayback/20220613064654im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Normal map on Terrain ? 1 Answer
Best way to create normal maps for unity? 0 Answers
Decreasing a Normalmap's strenght 1 Answer
Assigning UV Map to model at runtime 0 Answers