-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1234 from ousttrue/fix10/convert_TextureTransform
[1.0] TextureTransformBind の Scale/Offset 変換
- Loading branch information
Showing
23 changed files
with
1,136 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/TextureTransform.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 Scale, Vector2 Offset) VerticalFlipScaleOffset(Vector2 s, Vector2 o) | ||
{ | ||
return (new Vector2(s.x, s.y), new Vector2(o.x, 1.0f - o.y - s.y)); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/TextureTransform.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using UnityEngine; | ||
|
||
namespace UniGLTF.Samples | ||
{ | ||
/// <summary> | ||
/// ScaleOffset の検証 | ||
/// </summary> | ||
public class ScaleOffset : MonoBehaviour | ||
{ | ||
[SerializeField] | ||
public Vector2 Scale = Vector2.one; | ||
|
||
[SerializeField] | ||
public Vector2 Offset = Vector2.zero; | ||
|
||
[SerializeField] | ||
Material Unity; | ||
|
||
[SerializeField] | ||
Material Gltf; | ||
|
||
void OnValidate() | ||
{ | ||
Execute(); | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
Execute(); | ||
} | ||
|
||
const string PROP_NAME = "_MainTex"; | ||
|
||
void Execute() | ||
{ | ||
if (Unity == null || Gltf == null) | ||
{ | ||
return; | ||
} | ||
|
||
Unity.SetTextureScale(PROP_NAME, Scale); | ||
Unity.SetTextureOffset(PROP_NAME, Offset); | ||
|
||
var (s, o) = TextureTransform.VerticalFlipScaleOffset(Scale, Offset); | ||
|
||
Gltf.SetTextureScale(PROP_NAME, s); | ||
Gltf.SetTextureOffset(PROP_NAME, o); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.