mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-12 13:59:21 -05:00
TextureTransform.VerticalFlipScaleOffset
This commit is contained in:
@@ -206,7 +206,7 @@ namespace UniGLTF
|
||||
{
|
||||
var offset = m.GetTextureOffset(propertyName);
|
||||
var scale = m.GetTextureScale(propertyName);
|
||||
offset.y = 1.0f - offset.y - scale.y;
|
||||
(scale, offset) = TextureTransform.VerticalFlipScaleOffset(scale, offset);
|
||||
|
||||
glTF_KHR_texture_transform.Serialize(textureInfo, (offset.x, offset.y), (scale.x, scale.y));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF
|
||||
{
|
||||
public static class TextureTransform
|
||||
{
|
||||
/// <summary>
|
||||
// UV Coordinate Conversion: glTF(top-left origin) to Unity(bottom-left origin)
|
||||
/// https://github.com/vrm-c/UniVRM/issues/930
|
||||
/// offset.y = 1.0f - offset.y - scale.y;
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
/// <param name="o"></param>
|
||||
/// <returns></returns>
|
||||
public static (Vector2, Vector2) VerticalFlipScaleOffset(Vector2 s, Vector2 o)
|
||||
{
|
||||
return (new Vector2(s.x, s.y), new Vector2(o.x, 1.0f - o.y - s.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a652f0fdb4236434a9a64aa35a3cb44f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -118,9 +118,7 @@ namespace UniGLTF
|
||||
scale = new Vector2(textureTransform.scale[0], textureTransform.scale[1]);
|
||||
}
|
||||
|
||||
// UV Coordinate Conversion: glTF(top-left origin) to Unity(bottom-left origin)
|
||||
// Formula: https://github.com/vrm-c/UniVRM/issues/930
|
||||
offset.y = 1.0f - offset.y - scale.y;
|
||||
(scale, offset) = TextureTransform.VerticalFlipScaleOffset(scale, offset);
|
||||
}
|
||||
|
||||
return (offset, scale);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniGLTF.Samples
|
||||
{
|
||||
@@ -34,23 +32,17 @@ namespace UniGLTF.Samples
|
||||
|
||||
const string PROP_NAME = "_MainTex";
|
||||
|
||||
/// <summary>
|
||||
/// https://github.com/vrm-c/UniVRM/issues/930
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
/// <param name="o"></param>
|
||||
/// <returns></returns>
|
||||
public static (Vector2, Vector2) ConvScaleOffset(Vector2 s, Vector2 o)
|
||||
{
|
||||
return (new Vector2(s.x, s.y), new Vector2(o.x, 1 - o.y - s.y));
|
||||
}
|
||||
|
||||
void Execute()
|
||||
{
|
||||
if (Unity == null || Gltf == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Unity.SetTextureScale(PROP_NAME, Scale);
|
||||
Unity.SetTextureOffset(PROP_NAME, Offset);
|
||||
|
||||
var (s, o) = ConvScaleOffset(Scale, Offset);
|
||||
var (s, o) = TextureTransform.VerticalFlipScaleOffset(Scale, Offset);
|
||||
|
||||
Gltf.SetTextureScale(PROP_NAME, s);
|
||||
Gltf.SetTextureOffset(PROP_NAME, o);
|
||||
|
||||
Reference in New Issue
Block a user