Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Preprocess texture to a cubemap

Discussion in 'Unity 5 Pre-order Beta' started by kurai, Feb 19, 2015.

  1. kurai

    kurai

    Joined:
    Jan 9, 2012
    Posts:
    118
    Hey there!
    I need to make a small scripts to preprocess textures and turn them in a cubemap when added to a certain editor folder.

    Right now my script looks like this:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4. class MakeCubeMap  : AssetPostprocessor {
    5.     void OnPreprocessTexture () {
    6.  
    7.         if (assetPath.Contains("360Photos")) {
    8.             Debug.Log ("Importing new 360 Photo!");
    9.             TextureImporter myTextureImporter  = (TextureImporter)assetImporter;
    10.             myTextureImporter.textureType = TextureImporterType.Cubemap;
    11.  
    12.             myTextureImporter.textureFormat = TextureImporterFormat.AutomaticTruecolor;
    13.             myTextureImporter.maxTextureSize = 2048;
    14.             myTextureImporter.ClearPlatformTextureSettings("Web");
    15.             myTextureImporter.ClearPlatformTextureSettings("Standalone");
    16.             myTextureImporter.ClearPlatformTextureSettings("iPhone");
    17.         }
    18.     }
    19. }
    Now, it *almost* works. What I need now is to set a couple options in the texture cube map settings. I'd like to set the Mapping option to "Auto" and to enable the "Fix edge seams" option.
    Only, I don't know how to do it via script. Where should I look? Thanks!
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,918
    You should probably fill a bug, those properties should be exposed via API, in the mean time, you could do something like this:

    Code (csharp):
    1.  
    2.  
    3.         SerializedObject o = new SerializedObject(myTextureImporter);
    4.         SerializedProperty mapping = o.FindProperty("m_GenerateCubemap");
    5.         SerializedProperty seamless = o.FindProperty("m_SeamlessCubemap");
    6.  
    7.         mapping.intValue = 6;
    8.         seamless.boolValue = false;
    9.         o.ApplyModifiedProperties();
    10.  
     
    fffMalzbier likes this.
  3. kurai

    kurai

    Joined:
    Jan 9, 2012
    Posts:
    118
    Ok, thanks! I'll file a bug report asap :)