Example #1
0
        void OnGUI()
        {
            // If this is the first iteration since the window is opened, do the needed initializzations
            if (firstCycle)
            {
                Start();
                firstCycle = false;
            }

            packer.DrawGUI();

            if (GUILayout.Button("Save Packed Texture"))
            {
                string path = TSFunctions.GetSelectedPathOrFallback();
                path = EditorUtility.SaveFilePanel("Save Texture", path, "Packed", "png");
                if (path.Length != 0)
                {
                    packer.PackTexture(path);
                }
            }
        }
Example #2
0
 /// <summary>
 /// Regenerated the MSOT texture
 /// </summary>
 public void RegenerateMSOT(bool saveToFile)
 {
     foreach (Material mat in _RampOn.targets)
     {
         if (mat.GetTexture("_MetallicMap") != null || mat.GetTexture("_GlossinessMap") != null || mat.GetTexture("_OcclusionMap") != null || mat.GetTexture("_ThicknessMap") != null)
         {
             packer.resolution = TexturePacker.Resolution.XS_128x128;
             packer.rTexture   = (Texture2D)mat.GetTexture("_MetallicMap");
             if (packer.rTexture != null)
             {
                 while (packer.rTexture.width > (float)packer.resolution || packer.rTexture.height > (float)packer.resolution)
                 {
                     if (!packer.RiseResolutionByOneLevel())
                     {
                         break;
                     }
                 }
             }
             packer.gTexture = (Texture2D)mat.GetTexture("_GlossinessMap");
             if (packer.gTexture != null)
             {
                 while (packer.gTexture.width > (float)packer.resolution || packer.gTexture.height > (float)packer.resolution)
                 {
                     if (!packer.RiseResolutionByOneLevel())
                     {
                         break;
                     }
                 }
             }
             packer.bTexture = (Texture2D)mat.GetTexture("_OcclusionMap");
             if (packer.bTexture != null)
             {
                 while (packer.bTexture.width > (float)packer.resolution || packer.bTexture.height > (float)packer.resolution)
                 {
                     if (!packer.RiseResolutionByOneLevel())
                     {
                         break;
                     }
                 }
             }
             packer.aTexture = (Texture2D)mat.GetTexture("_ThicknessMap");
             if (packer.aTexture != null)
             {
                 while (packer.aTexture.width > (float)packer.resolution || packer.aTexture.height > (float)packer.resolution)
                 {
                     if (!packer.RiseResolutionByOneLevel())
                     {
                         break;
                     }
                 }
             }
             if (saveToFile)
             {
                 string path = GetTextureDestinationPath(mat, "MSOT.png");
                 packer.PackTexture(path);
             }
             else
             {
                 packer.GenerateTexture();
             }
             mat.SetTexture("_MSOT", packer.resultTex);
         }
         else
         {
             mat.SetTexture("_MSOT", null);
         }
         needsMSOTRefresh = true;
     }
 }