노말맵 G 체널 인버터 클래스.

맥스나 마야 또는 기타 다른 엔진의 경우 노말맵의 Green channel 이 아래쪽으로 되어 있는 것을 보셨죠?
유니티와 연동해서 작업 할 때 매번 포토샵에서 노말맵을 반전 시켜서 따로 저장 하고 하던 거 엄청 지겹죠.

간단하게 에디터 클래스를 만들었습니다.

AssetPostprocessor 를 상속받아서 작성 해야 하고요...

SetPixels 은 32비트나 24비트만을 지원 하기 때문에 원본을 유지 하고 사용하기에는 DXT 등의 압축은 사용 할 수 없어요.

뭐 만약 꼭 해야 한다면 좀 더 복잡 해 지겠죠. 그리고 원본을 그대로 쓰진 못하고 tmp 데이터로 생성시킨 후 프로세싱을 거쳐 원본에 겹쳐 쓰기 해 줘야 할 겁니다.

아직까지 그건 못했고. ㅋㅌ;

using UnityEngine; using UnityEditor; using System.Collections;   public class Green_channel_flip : AssetPostprocessor {       // Use this for initialization     void OnPostprocessTexture(Texture2D texture)     {                  string lowerCaseAssetPath = assetPath.ToLower();         if (lowerCaseAssetPath.IndexOf("/inverted/") == -1) return; //프로세스 처리 될 폴더 패스.          for (int m = 0; m < texture.mipmapCount; m++)
        {

            
            Color[] c = texture.GetPixels(m);
            for (int i = 0; i < c.Length; i++)
            {
                c[i].r = c[i].r;
                c[i].g = 1 - c[i].g;
                c[i].b = c[i].b;
            }
            texture.SetPixels(c, m);
            TextureOptions();
        }
 
 }

    void TextureOptions()
    {
        string lowerCaseAssetPath = assetPath.ToLower();
        TextureImporter textureImporter = AssetImporter.GetAtPath(lowerCaseAssetPath) as TextureImporter;
        
        textureImporter.textureType = TextureImporterType.Advanced;
        textureImporter.mipmapEnabled = true;
        textureImporter.anisoLevel = 3;
        textureImporter.isReadable = true;
        textureImporter.npotScale = TextureImporterNPOTScale.None;
        textureImporter.filterMode = FilterMode.Trilinear;
        textureImporter.textureFormat = TextureImporterFormat.RGB24;

    }

}
 Game Developer Leegoon copyright all right reserved since 2010.

Comments