Exemple #1
0
        public void GetOrCreateTexture(bool isLinear)
        {
#if UNITY_EDITOR
            if (IsAsset)
            {
                //
                // texture from assets
                //
                m_assetPath.ImportAsset();
                TextureImporter importer = m_assetPath.GetImporter <TextureImporter>();
                importer.sRGBTexture = !isLinear;
                importer.SaveAndReimport();
                m_texture = m_assetPath.LoadAsset <Texture2D>();
            }
            else
#endif
            {
                //
                // texture from image(png etc) bytes
                //
                m_texture = new Texture2D(2, 2, TextureFormat.ARGB32, false, isLinear);
                if (m_imageBytes != null)
                {
                    m_texture.LoadImage(m_imageBytes);
                }
            }
            m_texture.name = m_textureName;
        }
Exemple #2
0
        public static Task <Texture2D> LoadTaskAsync(UnityPath m_assetPath,
                                                     glTF gltf, int textureIndex)
        {
            var textureType = TextureIO.GetglTFTextureType(gltf, textureIndex);
            var colorSpace  = TextureIO.GetColorSpace(textureType);
            var isLinear    = colorSpace == RenderTextureReadWrite.Linear;
            var sampler     = gltf.GetSamplerFromTextureIndex(textureIndex);

            //
            // texture from assets
            //
            m_assetPath.ImportAsset();
            var importer = m_assetPath.GetImporter <UnityEditor.TextureImporter>();

            if (importer == null)
            {
                Debug.LogWarningFormat("fail to get TextureImporter: {0}", m_assetPath);
            }
            else
            {
                importer.maxTextureSize = 8192;
                importer.sRGBTexture    = !isLinear;
                importer.SaveAndReimport();
            }

            var Texture = m_assetPath.LoadAsset <Texture2D>();

            if (Texture == null)
            {
                Debug.LogWarningFormat("fail to Load Texture2D: {0}", m_assetPath);
            }

            else
            {
                var maxSize = Mathf.Max(Texture.width, Texture.height);

                importer.maxTextureSize
                    = maxSize > 4096 ? 8192 :
                      maxSize > 2048 ? 4096 :
                      maxSize > 1024 ? 2048 :
                      maxSize > 512 ? 1024 :
                      512;

                importer.SaveAndReimport();
            }

            if (sampler != null)
            {
                TextureSamplerUtil.SetSampler(Texture, sampler);
            }

            return(Task.FromResult(Texture));
        }
        public IEnumerator ProcessOnMainThread(bool isLinear, glTFTextureSampler sampler)
        {
            //
            // texture from assets
            //
            m_assetPath.ImportAsset();
            var importer = m_assetPath.GetImporter <TextureImporter>();

            if (importer == null)
            {
                Debug.LogWarningFormat("fail to get TextureImporter: {0}", m_assetPath);
            }
            importer.maxTextureSize = 8192;
            importer.sRGBTexture    = !isLinear;

            importer.SaveAndReimport();

            Texture = m_assetPath.LoadAsset <Texture2D>();

            //Texture.name = m_textureName;
            if (Texture == null)
            {
                Debug.LogWarningFormat("fail to Load Texture2D: {0}", m_assetPath);
            }

            else
            {
                var maxSize = Mathf.Max(Texture.width, Texture.height);

                importer.maxTextureSize
                    = maxSize > 4096 ? 8192 :
                      maxSize > 2048 ? 4096 :
                      maxSize > 1024 ? 2048 :
                      maxSize > 512 ? 1024 :
                      512;

                importer.SaveAndReimport();
            }

            if (sampler != null)
            {
                TextureSamplerUtil.SetSampler(Texture, sampler);
            }

            yield break;
        }
Exemple #4
0
        public static Task <Texture2D> LoadTaskAsync(UnityPath m_assetPath,
                                                     bool isLinear, glTFTextureSampler sampler)
        {
            //
            // texture from assets
            //
            m_assetPath.ImportAsset();
            var importer = m_assetPath.GetImporter <UnityEditor.TextureImporter>();

            if (importer == null)
            {
                Debug.LogWarningFormat("fail to get TextureImporter: {0}", m_assetPath);
            }
            importer.maxTextureSize = 8192;
            importer.sRGBTexture    = !isLinear;

            importer.SaveAndReimport();

            var Texture = m_assetPath.LoadAsset <Texture2D>();

            if (Texture == null)
            {
                Debug.LogWarningFormat("fail to Load Texture2D: {0}", m_assetPath);
            }

            else
            {
                var maxSize = Mathf.Max(Texture.width, Texture.height);

                importer.maxTextureSize
                    = maxSize > 4096 ? 8192 :
                      maxSize > 2048 ? 4096 :
                      maxSize > 1024 ? 2048 :
                      maxSize > 512 ? 1024 :
                      512;

                importer.SaveAndReimport();
            }

            if (sampler != null)
            {
                TextureSamplerUtil.SetSampler(Texture, sampler);
            }

            return(Task.FromResult(Texture));
        }
Exemple #5
0
        public IEnumerator ProcessOnMainThread(bool isLinear)
        {
            //
            // texture from assets
            //
            m_assetPath.ImportAsset();
            var importer = m_assetPath.GetImporter <TextureImporter>();

            if (importer == null)
            {
                Debug.LogWarningFormat("fail to get TextureImporter: {0}", m_assetPath);
            }
            importer.sRGBTexture = !isLinear;
            importer.SaveAndReimport();

            Texture = m_assetPath.LoadAsset <Texture2D>();
            //Texture.name = m_textureName;
            if (Texture == null)
            {
                Debug.LogWarningFormat("fail to Load Texture2D: {0}", m_assetPath);
            }

            yield break;
        }