public static Texture2D Convert(Texture2D texture, glTFTextureTypes textureType, ColorConversion colorConversion, Material convertMaterial) { var copyTexture = TextureItem.CopyTexture(texture, TextureIO.GetColorSpace(textureType), convertMaterial); if (colorConversion != null) { copyTexture.SetPixels32(copyTexture.GetPixels32().Select(x => colorConversion(x)).ToArray()); copyTexture.Apply(); } copyTexture.name = texture.name; return(copyTexture); }
public IEnumerator ProcessOnMainThreadCoroutine(glTF gltf) { using (m_textureLoader) { var textureType = TextureIO.GetglTFTextureType(gltf, m_textureIndex); var colorSpace = TextureIO.GetColorSpace(textureType); var isLinear = colorSpace == RenderTextureReadWrite.Linear; yield return(m_textureLoader.ProcessOnMainThread(isLinear)); TextureSamplerUtil.SetSampler(Texture, gltf.GetSamplerFromTextureIndex(m_textureIndex)); } }
static BytesWithMime GetBytesWithMime(Texture texture, glTFTextureTypes textureType) { #if UNITY_EDITOR var path = UnityPath.FromAsset(texture); if (path.IsUnderAssetsFolder) { if (path.Extension == ".png") { return(new BytesWithMime { Bytes = System.IO.File.ReadAllBytes(path.FullPath), Mime = "image/png", }); } } #endif return(new BytesWithMime { Bytes = TextureItem.CopyTexture(texture, TextureIO.GetColorSpace(textureType), null).EncodeToPNG(), Mime = "image/png", }); }