void EqualTextureColor(Texture2D texture, VrmLib.ImageTexture imageTexture, bool isLinear) { var srcColor = texture.GetPixel(0, 0); var dstTexture = new Texture2D(2, 2, TextureFormat.ARGB32, mipChain: false, linear: isLinear); dstTexture.LoadImage(imageTexture.Image.Bytes.ToArray()); var dstColor = dstTexture.GetPixel(0, 0); Debug.LogFormat("src:{0}, dst{1}", srcColor, dstColor); EqualColor(srcColor, dstColor); }
/// <summary> /// 画像のバイト列からテクスチャを作成する /// <summary> public static Texture2D CreateTexture(VrmLib.ImageTexture imageTexture) { Texture2D dstTexture = null; UnityEngine.Material convertMaterial = null; var texture = new Texture2D(2, 2, TextureFormat.ARGB32, false, imageTexture.ColorSpace == VrmLib.Texture.ColorSpaceTypes.Linear); texture.LoadImage(imageTexture.Image.Bytes.ToArray()); // Convert Texture Gltf to Unity if (imageTexture.TextureType == VrmLib.Texture.TextureTypes.NormalMap) { convertMaterial = TextureConvertMaterial.GetNormalMapConvertGltfToUnity(); dstTexture = UnityTextureUtil.CopyTexture( texture, GetRenderTextureReadWrite(imageTexture.ColorSpace), convertMaterial); } else if (imageTexture.TextureType == VrmLib.Texture.TextureTypes.MetallicRoughness) { var metallicRoughnessImage = imageTexture as VrmLib.MetallicRoughnessImageTexture; convertMaterial = TextureConvertMaterial.GetMetallicRoughnessGltfToUnity(metallicRoughnessImage.RoughnessFactor); dstTexture = UnityTextureUtil.CopyTexture( texture, GetRenderTextureReadWrite(imageTexture.ColorSpace), convertMaterial); } else if (imageTexture.TextureType == VrmLib.Texture.TextureTypes.Occlusion) { convertMaterial = TextureConvertMaterial.GetOcclusionGltfToUnity(); dstTexture = UnityTextureUtil.CopyTexture( texture, GetRenderTextureReadWrite(imageTexture.ColorSpace), convertMaterial); } if (dstTexture != null) { if (texture != null) { UnityEngine.Object.DestroyImmediate(texture); } texture = dstTexture; } if (convertMaterial != null) { UnityEngine.Object.DestroyImmediate(convertMaterial); } return(texture); }