invert texture origin

This commit is contained in:
j-hirose 2019-05-08 20:33:53 +09:00
parent c4937d5b1e
commit a5b4e907de
2 changed files with 15 additions and 6 deletions

View File

@ -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 },
}
};
}

View File

@ -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);
}
}
}