• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by FutchProductionsSyndicate · Mar 02, 2012 at 05:32 AM · mapnormal

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
     }
 }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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! :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Normal map is not showing for some reason... 1 Answer

Should I use a material for each sprite? 0 Answers

Lightmapping and normal map issue 0 Answers

Stopping overlapping textures from flickering? 7 Answers

Normal map appears to be wrong when generated 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges