Пример #1
0
        public Texture2D saveTexture(Texture2D texture, int index = -1, string imageName = "")
        {
            string basename = GLTFUtils.cleanName(texture.name + (index >= 0 ? "_" + index.ToString() : "") + ".png"); // Extension will be overridden
            string fullPath = Path.Combine(_importTexturesDirectory, basename);

            // Write texture
            string newAssetPath = GLTFTextureUtils.writeTextureOnDisk(texture, fullPath, true);

            // Reload as asset
            string    projectPath = GLTFUtils.getPathProjectFromAbsolute(newAssetPath);
            Texture2D tex         = (Texture2D)AssetDatabase.LoadAssetAtPath(projectPath, typeof(Texture2D));

            _parsedImages.Add(tex);
            return(tex);
        }
Пример #2
0
        private static Texture2D SplitRoughnessTexture(Texture2D texture)
        {
            int             width     = texture.width;
            int             height    = texture.height;
            string          assetPath = AssetDatabase.GetAssetPath(texture);
            TextureImporter im        = AssetImporter.GetAtPath(assetPath) as TextureImporter;

            im.isReadable = true;
            im.SaveAndReimport();
            var iColor = texture.GetPixels();

            im.isReadable = false;
            im.SaveAndReimport();

            // Let's consider that the three textures have the same resolution
            Color[] colors = new Color[width * height];
            for (int i = 0; i < colors.Length; i += 1)
            {
                float a = 1 - iColor[i].a;

                colors[i] = new Color(a, a, a);
            }

            var res = new Texture2D(width, height);

            res.SetPixels(colors);

            string basename = Path.GetFileNameWithoutExtension(assetPath) + "_rg";
            string fullPath = Path.GetFullPath(Path.GetDirectoryName(assetPath)) + "/" + basename + ".png";

            string    newAssetPath = GLTFTextureUtils.writeTextureOnDisk(res, fullPath, true);
            string    projectPath  = GLTFUtils.getPathProjectFromAbsolute(newAssetPath);
            Texture2D tex          = (Texture2D)AssetDatabase.LoadAssetAtPath(projectPath, typeof(Texture2D));

            return(tex);
        }