From a5b4e907deae10a2f2dccace67b17ba23c714ff8 Mon Sep 17 00:00:00 2001 From: j-hirose Date: Wed, 8 May 2019 20:33:53 +0900 Subject: [PATCH] invert texture origin --- Assets/VRM/UniGLTF/Scripts/IO/MaterialExporter.cs | 8 ++++++-- Assets/VRM/UniGLTF/Scripts/IO/MaterialImporter.cs | 13 +++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Assets/VRM/UniGLTF/Scripts/IO/MaterialExporter.cs b/Assets/VRM/UniGLTF/Scripts/IO/MaterialExporter.cs index d210287e7..d6c943e38 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/MaterialExporter.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/MaterialExporter.cs @@ -182,12 +182,16 @@ namespace UniGLTF { if( textureInfo != null && m.HasProperty(propertyName)) { + var offset = m.GetTextureOffset(propertyName); + var scale = m.GetTextureScale(propertyName); + offset.y = (offset.y + scale.y - 1) * -1.0f; + textureInfo.extensions = new glTFTextureInfo_extensions { KHR_texture_transform = new glTF_KHR_texture_transform() { - offset = new float[] { m.GetTextureOffset(propertyName).x, m.GetTextureOffset(propertyName).y }, - scale = new float[] { m.GetTextureScale(propertyName).x, m.GetTextureScale(propertyName).y }, + offset = new float[] { offset.x, offset.y }, + scale = new float[] { scale.x, scale.y }, } }; } diff --git a/Assets/VRM/UniGLTF/Scripts/IO/MaterialImporter.cs b/Assets/VRM/UniGLTF/Scripts/IO/MaterialImporter.cs index b3b102405..f23c28112 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/MaterialImporter.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/MaterialImporter.cs @@ -293,16 +293,21 @@ namespace UniGLTF if (textureInfo.extensions != null && textureInfo.extensions.KHR_texture_transform != null) { var textureTransform = textureInfo.extensions.KHR_texture_transform; + Vector2 offset = new Vector2(0, 0); + Vector2 scale = new Vector2(1, 1); if (textureTransform.offset != null && textureTransform.offset.Length == 2) { - material.SetTextureOffset(propertyName, - new Vector2(textureTransform.offset[0], textureTransform.offset[1])); + offset = new Vector2(textureTransform.offset[0], textureTransform.offset[1]); } if (textureTransform.scale != null && textureTransform.scale.Length == 2) { - material.SetTextureScale(propertyName, - new Vector2(textureTransform.scale[0], textureTransform.scale[1])); + scale = new Vector2(textureTransform.scale[0], textureTransform.scale[1]); } + + offset.y = (offset.y + scale.y - 1.0f) * -1.0f; + + material.SetTextureOffset(propertyName, offset); + material.SetTextureScale(propertyName, scale); } } }