summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/VRM/VRM/UniVRM/Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-11 20:00:58 +0800
committerchai <chaifix@163.com>2020-10-11 20:00:58 +0800
commit8b384dffa0d9c63c7a657c6e567c2ddefbf046cd (patch)
tree3f4d669b73b6622aa49627c4ccb3c78d51a82bde /Assets/ThirdParty/VRM/VRM/UniVRM/Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs
parentcd3aee8d640f6abcc82802ca7abbcdfa031c20d3 (diff)
+Saionji show off scene
Diffstat (limited to 'Assets/ThirdParty/VRM/VRM/UniVRM/Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs')
-rw-r--r--Assets/ThirdParty/VRM/VRM/UniVRM/Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs90
1 files changed, 90 insertions, 0 deletions
diff --git a/Assets/ThirdParty/VRM/VRM/UniVRM/Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs b/Assets/ThirdParty/VRM/VRM/UniVRM/Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs
new file mode 100644
index 00000000..252fd935
--- /dev/null
+++ b/Assets/ThirdParty/VRM/VRM/UniVRM/Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs
@@ -0,0 +1,90 @@
+#pragma warning disable 0414, 0649
+using UnityEngine;
+
+
+namespace VRM
+{
+ public class VRMLookAtBlendShapeApplyer : MonoBehaviour, IVRMComponent
+ {
+ public bool DrawGizmo = true;
+
+ [SerializeField, Header("Degree Mapping")]
+ public CurveMapper Horizontal = new CurveMapper(90.0f, 1.0f);
+
+ [SerializeField]
+ public CurveMapper VerticalDown = new CurveMapper(90.0f, 1.0f);
+
+ [SerializeField]
+ public CurveMapper VerticalUp = new CurveMapper(90.0f, 1.0f);
+
+ /// <summary>
+ /// v0.56 からデフォルト値を true に変更
+ ///
+ /// true の場合: BlendShapeProxy.AccumulateValue を使う(推奨)
+ /// 別途 BlendShapeProxy.Apply を別の場所で呼び出す必要があります
+ /// false の場合: BlendShapeProxy.ImmediatelySetValueを使う
+ /// 目をテクスチャUVのOffset値の変更で表現するモデルの場合に、
+ /// Material.SetVector("_MainTex_ST", new Vector4(1, 1, 横の移動値, 0))
+ /// Material.SetVector("_MainTex_ST", new Vector4(1, 1, 0, 縦の移動値))
+ /// と連続で呼ばれることで、横の移動値が打ち消されてしまいます。
+ /// BlendShapeProxy.AccumulateValue はこの値を加算して new Vector4(1, 1, 横の移動値, 縦の移動値)
+ /// となるように扱えます。
+ /// </summary>
+ [SerializeField]
+ public bool m_notSetValueApply = true;
+
+ public void OnImported(VRMImporterContext context)
+ {
+ var gltfFirstPerson = context.GLTF.extensions.VRM.firstPerson;
+ Horizontal.Apply(gltfFirstPerson.lookAtHorizontalOuter);
+ VerticalDown.Apply(gltfFirstPerson.lookAtVerticalDown);
+ VerticalUp.Apply(gltfFirstPerson.lookAtVerticalUp);
+ }
+
+ VRMLookAtHead m_head;
+ VRMBlendShapeProxy m_proxy;
+
+ private void Start()
+ {
+ m_head = GetComponent<VRMLookAtHead>();
+ m_proxy = GetComponent<VRMBlendShapeProxy>();
+ if (m_head == null)
+ {
+ enabled = false;
+ return;
+ }
+ m_head.YawPitchChanged += ApplyRotations;
+ }
+
+ void ApplyRotations(float yaw, float pitch)
+ {
+#pragma warning disable 0618
+ if (yaw < 0)
+ {
+ // Left
+ m_proxy.SetValue(BlendShapePreset.LookRight, 0, !m_notSetValueApply); // clear first
+ m_proxy.SetValue(BlendShapePreset.LookLeft, Mathf.Clamp(Horizontal.Map(-yaw), 0, 1.0f), !m_notSetValueApply);
+ }
+ else
+ {
+ // Right
+ m_proxy.SetValue(BlendShapePreset.LookLeft, 0, !m_notSetValueApply); // clear first
+ m_proxy.SetValue(BlendShapePreset.LookRight, Mathf.Clamp(Horizontal.Map(yaw), 0, 1.0f), !m_notSetValueApply);
+ }
+
+ if (pitch < 0)
+ {
+ // Down
+ m_proxy.SetValue(BlendShapePreset.LookUp, 0, !m_notSetValueApply); // clear first
+ m_proxy.SetValue(BlendShapePreset.LookDown, Mathf.Clamp(VerticalDown.Map(-pitch), 0, 1.0f), !m_notSetValueApply);
+ }
+ else
+ {
+ // Up
+ m_proxy.SetValue(BlendShapePreset.LookDown, 0, !m_notSetValueApply); // clear first
+ m_proxy.SetValue(BlendShapePreset.LookUp, Mathf.Clamp(VerticalUp.Map(pitch), 0, 1.0f), !m_notSetValueApply);
+ }
+#pragma warning restore 0618
+ }
+ }
+}