Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 beta is now available for download.
    Dismiss Notice

Is it possible to export terrain splat maps?

Discussion in 'Editor & General Support' started by MrTaiChi, Feb 18, 2009.

  1. MrTaiChi

    MrTaiChi

    Joined:
    Oct 24, 2008
    Posts:
    18
    Is it possible to export terrain splat maps to an image format that I can open up in Photoshop? If so, how can this be done?

    Thanks
     
  2. TowerOfBricks

    TowerOfBricks

    Joined:
    Oct 20, 2007
    Posts:
    933
    You can modify them through script. You need to drag them from the terrain asset to the script in the editor. Then you can save it, modify it or replace it.
     
  3. MrTaiChi

    MrTaiChi

    Joined:
    Oct 24, 2008
    Posts:
    18
    Can you be more specific? I see the terrain asset with the splat maps in them. Where do I drag them? What script are you talking about? Thanks.
     
  4. TowerOfBricks

    TowerOfBricks

    Joined:
    Oct 20, 2007
    Posts:
    933
    This code should save a png file to you projectfolder (parent of the assets folder).
    Then you can modify it in Photoshop. The script can also replace an existing texture. Probably used when you want to view the changes you have done to the texture in Photoshop.
    Drag the splatmap to the splat variable.
    Warning: This code is not tested and I don't know if it will compile correctly, but if not, it will probably be a small error.
    Code (csharp):
    1. var splat : Texture2D;
    2. function save (tex : Texture2D) {
    3.     var bytes = tex.EncodeToPNG();
    4.     File.WriteAllBytes(Application.dataPath + "/../splatmap.png", bytes);
    5. }
    6.  
    7. function Replace (tex : Texture2d, from : Texture2D) {
    8.     tex.Resize (from.width, from.height, from.format, true);
    9.     pixels = from.GetPixels (0);
    10.     tex.SetPixels (pixels);
    11.     tex.Apply;
    12. }
     
  5. MrTaiChi

    MrTaiChi

    Joined:
    Oct 24, 2008
    Posts:
    18
    Thanks man. I was able to save it out. This is my test code.



    Code (csharp):
    1.  
    2. function Awake() {
    3.    
    4.     try {
    5.      
    6.        var bw : BinaryWriter = new BinaryWriter(File.Open("splatmap.png", FileMode.Create));
    7.        var pngBytes = splat.EncodeToPNG();
    8.        bw.Write(pngBytes);
    9.      
    10.        bw.Close();
    11.        
    12.     }
    13.     catch (err) {
    14.          Debug.Log("Save Error");
    15.     }  
    16. }
    17.  
     
  6. KEMBL

    KEMBL

    Joined:
    Apr 16, 2009
    Posts:
    181
    One more code example for export terrain splat texture from Assets menu. Realy you can export ordinary textures also if needs.

    How to use:

    1) Place this script on Assets\Editor dir in your project dir, call it like Export_texture.js or what ever you prefer.

    2) Click on texture for export in Project tab

    3) Go Assets / Export Texture menu

    4) File with texture appear in Assets dir with name exported_texture.png, you can change it in script body.

    Code (csharp):
    1.  
    2. // For save splatmap as PNG file.
    3. import System.IO;
    4.  
    5. @MenuItem("Assets/Export Texture")
    6.  
    7. static function Apply () {
    8.    
    9.    var texture : Texture2D = Selection.activeObject as Texture2D;
    10.    if (texture == null)
    11.    {
    12.       EditorUtility.DisplayDialog("Select Texture", "You Must Select a Texture first!", "Ok");
    13.       return;
    14.    }
    15.    
    16.    var bytes = texture.EncodeToPNG();
    17.    File.WriteAllBytes(Application.dataPath + "/exported_texture.png", bytes);
    18. }
    19.  
     
    Arkade likes this.
  7. kr1stov

    kr1stov

    Joined:
    Aug 14, 2009
    Posts:
    4
    great. really helped me. thx
     
  8. RoelBartstra

    RoelBartstra

    Joined:
    Oct 13, 2009
    Posts:
    20
    I have exported the splats but when I open them in photoshop and save them, it breaks the file. Is there any solution for this? I think it's because of the alpha...
     
  9. ThreeDeeNut

    ThreeDeeNut

    Joined:
    Apr 18, 2013
    Posts:
    10
    KEMBL, I am stuck. I can't find where the splatmap is so I can't select it and therefore I can't use your script to export it. Can you please tell me where the default location is to find the splatmap in Unity 4.2? Thanks.
     
  10. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    959
    Hi,
    I just bought this, looks great.

    Dumb question:
    The main reason I bought it was to get rid of the ugly terrain tiling issue with some landscapes I bought from the asset store using default unity shader. I've run through the doc, converted the splat maps from existing terrain, and did the texture blending color and generated a new material.

    But...still getting ugly texture tiling artifacts.
    Can't see anything specific for this issue in the manual (maybe I missed it)

    Is there a simple process for doing this?

    I gather it's the Multi UV Mixing but playing with the settings doesn't seen to do anything.
    I have to recreate the material each time right?
     
    Last edited: Jun 5, 2015