From 9ffebd5b87fbbf4b806f869c026b909c1749d886 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 7 Oct 2024 14:49:36 +0900 Subject: [PATCH 1/8] fix CurveMapper. zero inputMaxValue --- Assets/VRM/Runtime/LookAt/CurveMapper.cs | 10 ++++++++++ Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/Assets/VRM/Runtime/LookAt/CurveMapper.cs b/Assets/VRM/Runtime/LookAt/CurveMapper.cs index b5d0a8f3f..d64586a49 100644 --- a/Assets/VRM/Runtime/LookAt/CurveMapper.cs +++ b/Assets/VRM/Runtime/LookAt/CurveMapper.cs @@ -17,6 +17,9 @@ namespace VRM [Range(0, 90.0f)] public float CurveYRangeDegree; + // zero 除算などを回避する閾値 + public const float MIMIMUM_INPUT_MAX_VALUE = 1e-5f; + public CurveMapper(float xRange, float yRange) { CurveXRangeDegree = xRange; @@ -61,6 +64,13 @@ namespace VRM public float Map(float src) { + if (CurveXRangeDegree < MIMIMUM_INPUT_MAX_VALUE) + { + // https://github.com/vrm-c/UniVRM/issues/2452 + return 0; + // or CurveYRangeDegree ? + } + if (src < 0) { src = 0; diff --git a/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs b/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs index 55dcba9ff..f451c291e 100644 --- a/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs +++ b/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs @@ -17,6 +17,9 @@ namespace UniVRM10 [Range(0, 90.0f)] public float CurveYRangeDegree; + // zero 除算などを回避する閾値 + public const float MIMIMUM_INPUT_MAX_VALUE = 1e-5f; + public CurveMapper(float xRange, float yRange) { CurveXRangeDegree = xRange; @@ -33,6 +36,13 @@ namespace UniVRM10 public float Map(float src) { + if (CurveXRangeDegree < MIMIMUM_INPUT_MAX_VALUE) + { + // https://github.com/vrm-c/UniVRM/issues/2452 + return 0; + // or CurveYRangeDegree ? + } + if (src < 0) { src = 0; From e63c6ff2f5c0262f5d5e6547412634925773a57a Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 7 Oct 2024 15:13:05 +0900 Subject: [PATCH 2/8] 0 or CurveYRangeDegree --- Assets/VRM/Runtime/LookAt/CurveMapper.cs | 21 ++++++++++--------- .../Runtime/Components/LookAt/CurveMapper.cs | 21 ++++++++++--------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Assets/VRM/Runtime/LookAt/CurveMapper.cs b/Assets/VRM/Runtime/LookAt/CurveMapper.cs index d64586a49..49a38b30b 100644 --- a/Assets/VRM/Runtime/LookAt/CurveMapper.cs +++ b/Assets/VRM/Runtime/LookAt/CurveMapper.cs @@ -67,19 +67,20 @@ namespace VRM if (CurveXRangeDegree < MIMIMUM_INPUT_MAX_VALUE) { // https://github.com/vrm-c/UniVRM/issues/2452 - return 0; - // or CurveYRangeDegree ? + return src <= 0 ? 0 : CurveYRangeDegree; } - - if (src < 0) + else { - src = 0; + if (src < 0) + { + src = 0; + } + else if (src > CurveXRangeDegree) + { + src = CurveXRangeDegree; + } + return Curve.Evaluate(src / CurveXRangeDegree) * CurveYRangeDegree; } - else if (src > CurveXRangeDegree) - { - src = CurveXRangeDegree; - } - return Curve.Evaluate(src / CurveXRangeDegree) * CurveYRangeDegree; } public bool Equals(CurveMapper other) diff --git a/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs b/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs index f451c291e..174b3a02a 100644 --- a/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs +++ b/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs @@ -39,19 +39,20 @@ namespace UniVRM10 if (CurveXRangeDegree < MIMIMUM_INPUT_MAX_VALUE) { // https://github.com/vrm-c/UniVRM/issues/2452 - return 0; - // or CurveYRangeDegree ? + return src <= 0 ? 0 : CurveXRangeDegree; } - - if (src < 0) + else { - src = 0; + if (src < 0) + { + src = 0; + } + else if (src > CurveXRangeDegree) + { + src = CurveXRangeDegree; + } + return _curve.Evaluate(src / CurveXRangeDegree) * CurveYRangeDegree; } - else if (src > CurveXRangeDegree) - { - src = CurveXRangeDegree; - } - return _curve.Evaluate(src / CurveXRangeDegree) * CurveYRangeDegree; } } } From 27fc4324c8012f724abceebc5e3315c8f0e18f6c Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 7 Oct 2024 15:25:33 +0900 Subject: [PATCH 3/8] =?UTF-8?q?1.0=20=E3=81=A7=E3=81=AF=E6=9C=AA=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E3=81=AE=20AnimationCurve=20=E3=82=92=E9=99=A4?= =?UTF-8?q?=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs b/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs index 174b3a02a..7c884f50c 100644 --- a/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs +++ b/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; using UnityEngine; @@ -9,8 +7,6 @@ namespace UniVRM10 [Serializable] public class CurveMapper { - private AnimationCurve _curve = AnimationCurve.Linear(0, 0, 1.0f, 1.0f); - [Range(20.0f, 90.0f)] public float CurveXRangeDegree; @@ -51,8 +47,8 @@ namespace UniVRM10 { src = CurveXRangeDegree; } - return _curve.Evaluate(src / CurveXRangeDegree) * CurveYRangeDegree; + return src / CurveXRangeDegree * CurveYRangeDegree; } } } -} +} \ No newline at end of file From d688a1568e13ebb923b2005599983d899f9da7b2 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 7 Oct 2024 15:31:14 +0900 Subject: [PATCH 4/8] max --- Assets/VRM/Runtime/LookAt/CurveMapper.cs | 22 ++----------------- .../Runtime/Components/LookAt/CurveMapper.cs | 22 ++----------------- 2 files changed, 4 insertions(+), 40 deletions(-) diff --git a/Assets/VRM/Runtime/LookAt/CurveMapper.cs b/Assets/VRM/Runtime/LookAt/CurveMapper.cs index 49a38b30b..6f9b0490c 100644 --- a/Assets/VRM/Runtime/LookAt/CurveMapper.cs +++ b/Assets/VRM/Runtime/LookAt/CurveMapper.cs @@ -17,9 +17,6 @@ namespace VRM [Range(0, 90.0f)] public float CurveYRangeDegree; - // zero 除算などを回避する閾値 - public const float MIMIMUM_INPUT_MAX_VALUE = 1e-5f; - public CurveMapper(float xRange, float yRange) { CurveXRangeDegree = xRange; @@ -64,23 +61,8 @@ namespace VRM public float Map(float src) { - if (CurveXRangeDegree < MIMIMUM_INPUT_MAX_VALUE) - { - // https://github.com/vrm-c/UniVRM/issues/2452 - return src <= 0 ? 0 : CurveYRangeDegree; - } - else - { - if (src < 0) - { - src = 0; - } - else if (src > CurveXRangeDegree) - { - src = CurveXRangeDegree; - } - return Curve.Evaluate(src / CurveXRangeDegree) * CurveYRangeDegree; - } + // https://github.com/vrm-c/UniVRM/issues/2452 + return Curve.Evaluate(Mathf.Clamp(src, 0, 1) / MathF.Max(CurveXRangeDegree, 0.001f)) * CurveYRangeDegree; } public bool Equals(CurveMapper other) diff --git a/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs b/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs index 7c884f50c..8beaf22c6 100644 --- a/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs +++ b/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs @@ -13,9 +13,6 @@ namespace UniVRM10 [Range(0, 90.0f)] public float CurveYRangeDegree; - // zero 除算などを回避する閾値 - public const float MIMIMUM_INPUT_MAX_VALUE = 1e-5f; - public CurveMapper(float xRange, float yRange) { CurveXRangeDegree = xRange; @@ -32,23 +29,8 @@ namespace UniVRM10 public float Map(float src) { - if (CurveXRangeDegree < MIMIMUM_INPUT_MAX_VALUE) - { - // https://github.com/vrm-c/UniVRM/issues/2452 - return src <= 0 ? 0 : CurveXRangeDegree; - } - else - { - if (src < 0) - { - src = 0; - } - else if (src > CurveXRangeDegree) - { - src = CurveXRangeDegree; - } - return src / CurveXRangeDegree * CurveYRangeDegree; - } + // https://github.com/vrm-c/UniVRM/issues/2452 + return Mathf.Clamp(src, 0, CurveXRangeDegree) / Mathf.Max(0.001f, CurveXRangeDegree) * CurveYRangeDegree; } } } \ No newline at end of file From a17aa977c71cd3b4f52ecba640bb1f78aaca72f0 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 7 Oct 2024 15:36:24 +0900 Subject: [PATCH 5/8] Clamp01 --- Assets/VRM/Runtime/LookAt/CurveMapper.cs | 3 ++- Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Assets/VRM/Runtime/LookAt/CurveMapper.cs b/Assets/VRM/Runtime/LookAt/CurveMapper.cs index 6f9b0490c..15069c1de 100644 --- a/Assets/VRM/Runtime/LookAt/CurveMapper.cs +++ b/Assets/VRM/Runtime/LookAt/CurveMapper.cs @@ -62,7 +62,8 @@ namespace VRM public float Map(float src) { // https://github.com/vrm-c/UniVRM/issues/2452 - return Curve.Evaluate(Mathf.Clamp(src, 0, 1) / MathF.Max(CurveXRangeDegree, 0.001f)) * CurveYRangeDegree; + var t = Mathf.Clamp01(Mathf.Clamp(src, 0, 1) / MathF.Max(CurveXRangeDegree, 0.001f)); + return Curve.Evaluate(t) * CurveYRangeDegree; } public bool Equals(CurveMapper other) diff --git a/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs b/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs index 8beaf22c6..a2be36e4e 100644 --- a/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs +++ b/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs @@ -30,7 +30,8 @@ namespace UniVRM10 public float Map(float src) { // https://github.com/vrm-c/UniVRM/issues/2452 - return Mathf.Clamp(src, 0, CurveXRangeDegree) / Mathf.Max(0.001f, CurveXRangeDegree) * CurveYRangeDegree; + var t = Mathf.Clamp01(Mathf.Clamp(src, 0, CurveXRangeDegree) / Mathf.Max(0.001f, CurveXRangeDegree)); + return t * CurveYRangeDegree; } } } \ No newline at end of file From 6a02614d35c7a5f0079688fbde3662b781d8abed Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 7 Oct 2024 16:14:02 +0900 Subject: [PATCH 6/8] fix Clamp --- Assets/VRM/Runtime/LookAt/CurveMapper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/VRM/Runtime/LookAt/CurveMapper.cs b/Assets/VRM/Runtime/LookAt/CurveMapper.cs index 15069c1de..f962608bb 100644 --- a/Assets/VRM/Runtime/LookAt/CurveMapper.cs +++ b/Assets/VRM/Runtime/LookAt/CurveMapper.cs @@ -62,7 +62,7 @@ namespace VRM public float Map(float src) { // https://github.com/vrm-c/UniVRM/issues/2452 - var t = Mathf.Clamp01(Mathf.Clamp(src, 0, 1) / MathF.Max(CurveXRangeDegree, 0.001f)); + var t = Mathf.Clamp01(Mathf.Clamp(src, 0, CurveXRangeDegree) / MathF.Max(CurveXRangeDegree, 0.001f)); return Curve.Evaluate(t) * CurveYRangeDegree; } From a335e375ec0055c456d5fd32b921475af0122eac Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 11 Oct 2024 16:10:49 +0900 Subject: [PATCH 7/8] Update Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs Co-authored-by: 0b5vr <0b5vr@0b5vr.com> --- Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs b/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs index a2be36e4e..1e7109d2a 100644 --- a/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs +++ b/Assets/VRM10/Runtime/Components/LookAt/CurveMapper.cs @@ -30,7 +30,7 @@ namespace UniVRM10 public float Map(float src) { // https://github.com/vrm-c/UniVRM/issues/2452 - var t = Mathf.Clamp01(Mathf.Clamp(src, 0, CurveXRangeDegree) / Mathf.Max(0.001f, CurveXRangeDegree)); + var t = Mathf.Clamp01(src / Mathf.Max(0.001f, CurveXRangeDegree)); return t * CurveYRangeDegree; } } From 66402c74d60a70fd6423697538bcf82a48a4caaa Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 11 Oct 2024 16:13:36 +0900 Subject: [PATCH 8/8] Update Assets/VRM/Runtime/LookAt/CurveMapper.cs Co-authored-by: 0b5vr <0b5vr@0b5vr.com> --- Assets/VRM/Runtime/LookAt/CurveMapper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/VRM/Runtime/LookAt/CurveMapper.cs b/Assets/VRM/Runtime/LookAt/CurveMapper.cs index f962608bb..6dd1978d8 100644 --- a/Assets/VRM/Runtime/LookAt/CurveMapper.cs +++ b/Assets/VRM/Runtime/LookAt/CurveMapper.cs @@ -62,7 +62,7 @@ namespace VRM public float Map(float src) { // https://github.com/vrm-c/UniVRM/issues/2452 - var t = Mathf.Clamp01(Mathf.Clamp(src, 0, CurveXRangeDegree) / MathF.Max(CurveXRangeDegree, 0.001f)); + var t = Mathf.Clamp01(src / MathF.Max(CurveXRangeDegree, 0.001f)); return Curve.Evaluate(t) * CurveYRangeDegree; }