From 8c69119058e8237fcf88bd80c338bcfb51983586 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 25 Aug 2021 19:58:45 +0900 Subject: [PATCH] add VRM10AutoExpression for VRM10Viewer. move test_motion.txt --- .../UniHumanoid/Resources}/test_motion.txt | 0 .../Resources}/test_motion.txt.meta | 0 .../VRM10Viewer/VRM10AutoExpression.cs | 76 +++++ .../VRM10Viewer/VRM10AutoExpression.cs.meta | 11 + .../Samples/VRM10Viewer/VRM10Viewer.unity | 316 +++++++++++++++++- .../Samples/VRM10Viewer/VRM10ViewerUI.cs | 21 ++ 6 files changed, 423 insertions(+), 1 deletion(-) rename Assets/{VRM/Samples/SimpleViewer => UniGLTF/UniHumanoid/Resources}/test_motion.txt (100%) rename Assets/{VRM/Samples/SimpleViewer => UniGLTF/UniHumanoid/Resources}/test_motion.txt.meta (100%) create mode 100644 Assets/VRM10/Samples/VRM10Viewer/VRM10AutoExpression.cs create mode 100644 Assets/VRM10/Samples/VRM10Viewer/VRM10AutoExpression.cs.meta diff --git a/Assets/VRM/Samples/SimpleViewer/test_motion.txt b/Assets/UniGLTF/UniHumanoid/Resources/test_motion.txt similarity index 100% rename from Assets/VRM/Samples/SimpleViewer/test_motion.txt rename to Assets/UniGLTF/UniHumanoid/Resources/test_motion.txt diff --git a/Assets/VRM/Samples/SimpleViewer/test_motion.txt.meta b/Assets/UniGLTF/UniHumanoid/Resources/test_motion.txt.meta similarity index 100% rename from Assets/VRM/Samples/SimpleViewer/test_motion.txt.meta rename to Assets/UniGLTF/UniHumanoid/Resources/test_motion.txt.meta diff --git a/Assets/VRM10/Samples/VRM10Viewer/VRM10AutoExpression.cs b/Assets/VRM10/Samples/VRM10Viewer/VRM10AutoExpression.cs new file mode 100644 index 000000000..de1a565eb --- /dev/null +++ b/Assets/VRM10/Samples/VRM10Viewer/VRM10AutoExpression.cs @@ -0,0 +1,76 @@ +using System.Collections; +using UnityEngine; + + +namespace UniVRM10.VRM10Viewer +{ + /// + /// 喜怒哀楽驚を循環させる + /// + public class VRM10AutoExpression : MonoBehaviour + { + [SerializeField] + public VRM10Controller Controller; + private void Reset() + { + Controller = GetComponent(); + } + + Coroutine m_coroutine; + + [SerializeField] + float m_wait = 0.5f; + + private void Awake() + { + if (Controller == null) + { + Controller = GetComponent(); + } + } + + IEnumerator RoutineNest(ExpressionPreset preset, float velocity, float wait) + { + for (var value = 0.0f; value <= 1.0f; value += velocity) + { + Controller.Vrm.Expression.SetWeight(ExpressionKey.CreateFromPreset(preset), value); + yield return null; + } + Controller.Vrm.Expression.SetWeight(ExpressionKey.CreateFromPreset(preset), 1.0f); + yield return new WaitForSeconds(wait); + for (var value = 1.0f; value >= 0; value -= velocity) + { + Controller.Vrm.Expression.SetWeight(ExpressionKey.CreateFromPreset(preset), value); + yield return null; + } + Controller.Vrm.Expression.SetWeight(ExpressionKey.CreateFromPreset(preset), 0); + yield return new WaitForSeconds(wait * 2); + } + + IEnumerator Routine() + { + while (true) + { + yield return new WaitForSeconds(1.0f); + + var velocity = 0.1f; + + yield return RoutineNest(ExpressionPreset.happy, velocity, m_wait); + yield return RoutineNest(ExpressionPreset.angry, velocity, m_wait); + yield return RoutineNest(ExpressionPreset.sad, velocity, m_wait); + yield return RoutineNest(ExpressionPreset.relaxed, velocity, m_wait); + yield return RoutineNest(ExpressionPreset.surprised, velocity, m_wait); + } + } + + private void OnEnable() + { + m_coroutine = StartCoroutine(Routine()); + } + + private void OnDisable() + { + StopCoroutine(m_coroutine); + } + } +} diff --git a/Assets/VRM10/Samples/VRM10Viewer/VRM10AutoExpression.cs.meta b/Assets/VRM10/Samples/VRM10Viewer/VRM10AutoExpression.cs.meta new file mode 100644 index 000000000..c213d2c32 --- /dev/null +++ b/Assets/VRM10/Samples/VRM10Viewer/VRM10AutoExpression.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 422b056a168579c45bbb47dbb09ff8c7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Samples/VRM10Viewer/VRM10Viewer.unity b/Assets/VRM10/Samples/VRM10Viewer/VRM10Viewer.unity index 43be9ab9b..f56c24641 100644 --- a/Assets/VRM10/Samples/VRM10Viewer/VRM10Viewer.unity +++ b/Assets/VRM10/Samples/VRM10Viewer/VRM10Viewer.unity @@ -121,6 +121,81 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1 &62367394 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 62367395} + - component: {fileID: 62367397} + - component: {fileID: 62367396} + m_Layer: 5 + m_Name: Background + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &62367395 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 62367394} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 1189866557} + m_Father: {fileID: 1767738854} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 10, y: -10} + m_SizeDelta: {x: 20, y: 20} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &62367396 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 62367394} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &62367397 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 62367394} + m_CullTransparentMesh: 0 --- !u!1 &124675793 GameObject: m_ObjectHideFlags: 0 @@ -789,6 +864,7 @@ RectTransform: - {fileID: 597950322} - {fileID: 935566651} - {fileID: 634488421} + - {fileID: 1767738854} m_Father: {fileID: 124675794} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -2573,6 +2649,84 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1007924635} m_CullTransparentMesh: 0 +--- !u!1 &1037763548 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1037763549} + - component: {fileID: 1037763551} + - component: {fileID: 1037763550} + m_Layer: 5 + m_Name: Label + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1037763549 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1037763548} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1767738854} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 9, y: -0.5} + m_SizeDelta: {x: -28, y: -3} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1037763550 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1037763548} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} + m_RaycastTarget: 1 + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 14 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 10 + m_MaxSize: 40 + m_Alignment: 0 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: EnableAutoExpression +--- !u!222 &1037763551 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1037763548} + m_CullTransparentMesh: 0 --- !u!1 &1045380261 GameObject: m_ObjectHideFlags: 0 @@ -3273,6 +3427,80 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1181308131} m_CullTransparentMesh: 0 +--- !u!1 &1189866556 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1189866557} + - component: {fileID: 1189866559} + - component: {fileID: 1189866558} + m_Layer: 5 + m_Name: Checkmark + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1189866557 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1189866556} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 62367395} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 20, y: 20} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1189866558 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1189866556} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 10901, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &1189866559 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1189866556} + m_CullTransparentMesh: 0 --- !u!1 &1199975012 GameObject: m_ObjectHideFlags: 0 @@ -4518,6 +4746,91 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1767669910} m_CullTransparentMesh: 0 +--- !u!1 &1767738853 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1767738854} + - component: {fileID: 1767738855} + m_Layer: 5 + m_Name: EnableAutoExpression + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1767738854 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1767738853} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 62367395} + - {fileID: 1037763549} + m_Father: {fileID: 339774397} + m_RootOrder: 10 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 162, y: 20} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1767738855 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1767738853} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9085046f02f69544eb97fd06b6048fe2, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Highlighted + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 62367396} + toggleTransition: 1 + graphic: {fileID: 1189866558} + m_Group: {fileID: 0} + onValueChanged: + m_PersistentCalls: + m_Calls: [] + m_IsOn: 1 --- !u!1 &1787938562 GameObject: m_ObjectHideFlags: 0 @@ -4634,10 +4947,11 @@ MonoBehaviour: m_open: {fileID: 2009818433} m_enableLipSync: {fileID: 935566650} m_enableAutoBlink: {fileID: 634488422} + m_enableAutoExpression: {fileID: 1767738855} m_src: {fileID: 0} m_target: {fileID: 802105000} Root: {fileID: 0} - m_motion: {fileID: 0} + m_motion: {fileID: 4900000, guid: 7d2617171adc40b41ac50228f101e178, type: 3} m_texts: m_textModelTitle: {fileID: 1111491925} m_textModelVersion: {fileID: 1045380263} diff --git a/Assets/VRM10/Samples/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10/Samples/VRM10Viewer/VRM10ViewerUI.cs index eae6a6424..a9545b777 100644 --- a/Assets/VRM10/Samples/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10/Samples/VRM10Viewer/VRM10ViewerUI.cs @@ -23,6 +23,9 @@ namespace UniVRM10.VRM10Viewer [SerializeField] Toggle m_enableAutoBlink = default; + + [SerializeField] + Toggle m_enableAutoExpression = default; #endregion [SerializeField] @@ -166,6 +169,7 @@ namespace UniVRM10.VRM10Viewer var toggles = GameObject.FindObjectsOfType(); m_enableLipSync = toggles.First(x => x.name == "EnableLipSync"); m_enableAutoBlink = toggles.First(x => x.name == "EnableAutoBlink"); + m_enableAutoExpression = toggles.First(x => x.name == "EnableAutoExpression"); var texts = GameObject.FindObjectsOfType(); m_version = texts.First(x => x.name == "Version"); @@ -193,6 +197,21 @@ namespace UniVRM10.VRM10Viewer } } + VRM10AutoExpression m_autoExpression; + bool m_enableAutoExpressionValue; + bool EnableAutoExpressionValue + { + set + { + if (m_enableAutoExpressionValue == value) return; + m_enableAutoExpressionValue = value; + if (m_autoExpression != null) + { + m_autoExpression.enabled = m_enableAutoExpressionValue; + } + } + } + VRM10Blinker m_blink; bool m_enableBlinkValue; bool EnableBlinkValue @@ -241,6 +260,7 @@ namespace UniVRM10.VRM10Viewer { EnableLipSyncValue = m_enableLipSync.isOn; EnableBlinkValue = m_enableAutoBlink.isOn; + EnableAutoExpressionValue = m_enableAutoExpression.isOn; if (Input.GetKeyDown(KeyCode.Tab)) { @@ -406,6 +426,7 @@ namespace UniVRM10.VRM10Viewer m_lipSync = go.AddComponent(); m_blink = go.AddComponent(); + m_autoExpression = go.AddComponent(); m_controller.LookAtTargetType = VRM10ObjectLookAt.LookAtTargetTypes.CalcYawPitchToGaze; m_controller.Gaze = m_target.transform;