From 2d708472ef2c9bc04a268b453be6a6197e026076 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 21 Sep 2018 16:42:13 +0900 Subject: [PATCH] BytesWithPath to BytesWithMime --- Core/Scripts/IO/TextureIO.cs | 43 ++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/Core/Scripts/IO/TextureIO.cs b/Core/Scripts/IO/TextureIO.cs index 519a3f7..b46fee5 100644 --- a/Core/Scripts/IO/TextureIO.cs +++ b/Core/Scripts/IO/TextureIO.cs @@ -109,38 +109,43 @@ public static IEnumerable GetTextures(Material m) } } - struct BytesWithPath + + struct BytesWithMime { public Byte[] Bytes; - //public string Path; public string Mime; + } - public BytesWithPath(Texture texture, glTFTextureTypes textureType) - { + static BytesWithMime GetBytesWithMime(Texture texture, glTFTextureTypes textureType) + { #if UNITY_EDITOR - var path = UnityPath.FromAsset(texture); - if (path.IsUnderAssetsFolder) + var path = UnityPath.FromAsset(texture); + if (path.IsUnderAssetsFolder) + { + if (path.Extension == ".png") { - if (path.Extension == ".png") + return new BytesWithMime { - Bytes = System.IO.File.ReadAllBytes(path.FullPath); - Mime = "image/png"; - return; - } - } -#endif - //Path = ""; - Bytes = TextureItem.CopyTexture(texture, TextureIO.GetColorSpace(textureType), null).EncodeToPNG(); - Mime = "image/png"; + 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", + }; } public static int ExportTexture(glTF gltf, int bufferIndex, Texture texture, glTFTextureTypes textureType) { - var bytesWithPath = new BytesWithPath(texture, textureType); ; + var bytesWithMime = GetBytesWithMime(texture, textureType); ; // add view - var view = gltf.buffers[bufferIndex].Append(bytesWithPath.Bytes, glBufferTarget.NONE); + var view = gltf.buffers[bufferIndex].Append(bytesWithMime.Bytes, glBufferTarget.NONE); var viewIndex = gltf.AddBufferView(view); // add image @@ -149,7 +154,7 @@ public static int ExportTexture(glTF gltf, int bufferIndex, Texture texture, glT { name = texture.name, bufferView = viewIndex, - mimeType = bytesWithPath.Mime, + mimeType = bytesWithMime.Mime, }); // add sampler