public static string GetUnityObjectName(TextureImportTypes type, string gltfName, string uri) { if (type == TextureImportTypes.StandardMap) { // metallic, smooth, occlusion return($"{gltfName}{STANDARD_SUFFIX}"); } else if (type == TextureImportTypes.NormalMap) { return($"{gltfName}{NORMAL_SUFFIX}"); } else if (type == TextureImportTypes.Linear) { return($"{gltfName}{LINEAR_SUFFIX}"); } else { if (!string.IsNullOrEmpty(uri) && !uri.StartsWith("data:", StringComparison.Ordinal)) { // external image return(Path.GetFileNameWithoutExtension(uri)); } else { // texture name return(gltfName); } } }
public TextureImportName(TextureImportTypes textureType, string gltfName, string ext, string uri) { GltfName = gltfName; ConvertedName = TextureImportName.Convert(gltfName, textureType); Ext = ext; Uri = uri; ExtractKey = GetExtractKey(textureType, gltfName, ConvertedName, uri); }
public static string Convert(string name, TextureImportTypes textureType) { switch (textureType) { case TextureImportTypes.StandardMap: return($"{name}{STANDARD_SUFFIX}"); case TextureImportTypes.NormalMap: return($"{name}{NORMAL_SUFFIX}"); default: return(name); } }
public static Texture2D Convert(Texture texture, TextureImportTypes textureType, ColorConversion colorConversion, Material convertMaterial) { var copyTexture = CopyTexture(texture, textureType, convertMaterial); if (colorConversion != null) { copyTexture.SetPixels32(copyTexture.GetPixels32().Select(x => colorConversion(x)).ToArray()); copyTexture.Apply(); } copyTexture.name = texture.name; return(copyTexture); }
public static RenderTextureReadWrite GetColorSpace(this TextureImportTypes textureType) { switch (textureType) { case TextureImportTypes.sRGB: return(RenderTextureReadWrite.sRGB); case TextureImportTypes.Linear: case TextureImportTypes.StandardMap: case TextureImportTypes.NormalMap: return(RenderTextureReadWrite.Linear); default: throw new NotImplementedException(); } }
public TextureImportParam(TextureImportName name, SamplerParam sampler, TextureImportTypes textureType, float metallicFactor, float roughnessFactor, GetTextureBytesAsync i0, GetTextureBytesAsync i1, GetTextureBytesAsync i2, GetTextureBytesAsync i3, GetTextureBytesAsync i4, GetTextureBytesAsync i5) { Name = name; Sampler = sampler; TextureType = textureType; MetallicFactor = metallicFactor; RoughnessFactor = roughnessFactor; Index0 = i0; Index1 = i1; Index2 = i2; Index3 = i3; Index4 = i4; Index5 = i5; }
public static Texture2D CopyTexture(Texture src, TextureImportTypes textureType, Material material) { Texture2D dst = null; RenderTextureReadWrite colorSpace = textureType.GetColorSpace(); var renderTexture = new RenderTexture(src.width, src.height, 0, RenderTextureFormat.ARGB32, colorSpace); using (var scope = new ColorSpaceScope(colorSpace)) { if (material != null) { Graphics.Blit(src, renderTexture, material); } else { Graphics.Blit(src, renderTexture); } } dst = new Texture2D(src.width, src.height, TextureFormat.ARGB32, false, colorSpace == RenderTextureReadWrite.Linear); dst.ReadPixels(new Rect(0, 0, src.width, src.height), 0, 0); dst.name = src.name; dst.anisoLevel = src.anisoLevel; dst.filterMode = src.filterMode; dst.mipMapBias = src.mipMapBias; dst.wrapMode = src.wrapMode; dst.wrapModeU = src.wrapModeU; dst.wrapModeV = src.wrapModeV; dst.wrapModeW = src.wrapModeW; dst.Apply(); RenderTexture.active = null; if (Application.isEditor) { GameObject.DestroyImmediate(renderTexture); } else { GameObject.Destroy(renderTexture); } return(dst); }
public static string GetExtractKey(TextureImportTypes type, string gltfName, string convertedName, string uri) { if (type == TextureImportTypes.StandardMap) { // metallic, smooth, occlusion return(convertedName); } else { if (!string.IsNullOrEmpty(uri)) { // external image return(Path.GetFileNameWithoutExtension(uri)); } else { // texture name return(gltfName); } } }
public TextureDescriptor(string name, Vector2 offset, Vector2 scale, SamplerParam sampler, TextureImportTypes textureType, float metallicFactor, float roughnessFactor, GetTextureBytesAsync i0, GetTextureBytesAsync i1, GetTextureBytesAsync i2, GetTextureBytesAsync i3, GetTextureBytesAsync i4, GetTextureBytesAsync i5) { UnityObjectName = name; Offset = offset; Scale = scale; Sampler = sampler; TextureType = textureType; MetallicFactor = metallicFactor; RoughnessFactor = roughnessFactor; Index0 = i0; Index1 = i1; Index2 = i2; Index3 = i3; Index4 = i4; Index5 = i5; }
public static Texture2D CopyTexture(Texture src, TextureImportTypes textureType, Material material) { return(CopyTexture(src, textureType.GetColorSpace(), material)); }