From 27b284bdb671f493a55ec8b7d5f1ad83d078729a Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 16 Aug 2023 13:12:59 +0900 Subject: [PATCH 1/4] move Retarget to API --- .../Components/Vrm10Runtime/Vrm10Runtime.cs | 24 +- .../VrmAnimationInstance/IVrmAnimation.cs | 12 + .../IVrmAnimation.cs.meta} | 2 +- .../VrmAnimationInstance.cs | 261 +++++++------ .../ControlRig}/VRM10Retarget.cs | 2 +- .../Runtime/ControlRig/VRM10Retarget.cs.meta | 11 + .../Samples~/VRM10Viewer/Motions/IMotion.cs | 14 - Assets/VRM10_Samples/SimpleVrma.meta | 8 + Assets/VRM10_Samples/SimpleVrma/SimpleVrma.cs | 64 ++++ .../SimpleVrma/SimpleVrma.cs.meta | 11 + .../VRM10_Samples/SimpleVrma/SimpleVrma.unity | 349 ++++++++++++++++++ .../SimpleVrma/SimpleVrma.unity.meta | 7 + .../VRM10Viewer/Motions/BvhMotion.cs | 8 +- .../VRM10Viewer/Motions/IMotion.cs | 14 - .../VRM10Viewer/Motions/VrmAnimation.cs | 13 +- .../VRM10Viewer/VRM10ViewerUI.cs | 13 +- 16 files changed, 644 insertions(+), 169 deletions(-) create mode 100644 Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrmAnimation.cs rename Assets/{VRM10_Samples/VRM10Viewer/Motions/IMotion.cs.meta => VRM10/Runtime/Components/VrmAnimationInstance/IVrmAnimation.cs.meta} (83%) rename Assets/VRM10/{Samples~/VRM10Viewer => Runtime/ControlRig}/VRM10Retarget.cs (97%) create mode 100644 Assets/VRM10/Runtime/ControlRig/VRM10Retarget.cs.meta delete mode 100644 Assets/VRM10/Samples~/VRM10Viewer/Motions/IMotion.cs create mode 100644 Assets/VRM10_Samples/SimpleVrma.meta create mode 100644 Assets/VRM10_Samples/SimpleVrma/SimpleVrma.cs create mode 100644 Assets/VRM10_Samples/SimpleVrma/SimpleVrma.cs.meta create mode 100644 Assets/VRM10_Samples/SimpleVrma/SimpleVrma.unity create mode 100644 Assets/VRM10_Samples/SimpleVrma/SimpleVrma.unity.meta delete mode 100644 Assets/VRM10_Samples/VRM10Viewer/Motions/IMotion.cs diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs index a1bfd10cc..c80330b20 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs @@ -39,6 +39,8 @@ namespace UniVRM10 public Vrm10RuntimeExpression Expression { get; } public Vrm10RuntimeLookAt LookAt { get; } + public IVrmAnimation VrmAnimation { get; set; } + public Vector3 ExternalForce { get => m_externalData.ExternalForce; @@ -178,7 +180,8 @@ namespace UniVRM10 /// /// 毎フレーム関連コンポーネントを解決する /// - /// * Contraint + /// * Update from VrmAnimation + /// * Constraint /// * Spring /// * LookAt /// * Expression @@ -186,6 +189,23 @@ namespace UniVRM10 /// public void Process() { + // 0. Update From VrmAnimation + if (VrmAnimation != null) + { + // copy pose + { + VRM10Retarget.Retarget(VrmAnimation.ControlRig, (ControlRig, ControlRig)); + } + + // update expressions + foreach (var (k, v) in VrmAnimation.ExpressionMap) + { + Expression.SetWeight(k, v()); + } + + // TODO: look at target + } + // 1. Control Rig ControlRig?.Process(); @@ -198,7 +218,7 @@ namespace UniVRM10 // 3. Gaze control LookAt.Process(m_target.LookAtTargetType, m_target.LookAtTarget); - // 4. Expression + // 4. Apply Expression Expression.Process(); } } diff --git a/Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrmAnimation.cs b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrmAnimation.cs new file mode 100644 index 000000000..e33985a8a --- /dev/null +++ b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrmAnimation.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; + +namespace UniVRM10 +{ + public interface IVrmAnimation : IDisposable + { + (INormalizedPoseProvider, ITPoseProvider) ControlRig { get; } + IReadOnlyDictionary> ExpressionMap { get; } + public void ShowBoxMan(bool enable); + } +} diff --git a/Assets/VRM10_Samples/VRM10Viewer/Motions/IMotion.cs.meta b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrmAnimation.cs.meta similarity index 83% rename from Assets/VRM10_Samples/VRM10Viewer/Motions/IMotion.cs.meta rename to Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrmAnimation.cs.meta index bdc7beafd..9b2379524 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/Motions/IMotion.cs.meta +++ b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrmAnimation.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: bd8db8a4bdc3e7f40a0a7a1bcd554137 +guid: 1b2654d5824889e418b2f9bdc9456680 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/VRM10/Runtime/Components/VrmAnimationInstance/VrmAnimationInstance.cs b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/VrmAnimationInstance.cs index 0f85ab72e..7c727c240 100644 --- a/Assets/VRM10/Runtime/Components/VrmAnimationInstance/VrmAnimationInstance.cs +++ b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/VrmAnimationInstance.cs @@ -5,11 +5,30 @@ using UnityEngine; namespace UniVRM10 { - public class VrmAnimationInstance : MonoBehaviour + public class VrmAnimationInstance : MonoBehaviour, IVrmAnimation { public SkinnedMeshRenderer BoxMan; - public (INormalizedPoseProvider, ITPoseProvider) ControlRig; - public Dictionary> ExpressionMap = new(); + + public void Dispose() + { + if (Application.isPlaying) + { + Destroy(this); + } + else + { + DestroyImmediate(this); + } + } + + public (INormalizedPoseProvider, ITPoseProvider) ControlRig { get; set; } + Dictionary> _ExpressionMap = new(); + public IReadOnlyDictionary> ExpressionMap => _ExpressionMap; + + public void ShowBoxMan(bool enable) + { + BoxMan.enabled = enable; + } public float preset_happy; public float preset_angry; @@ -163,137 +182,137 @@ namespace UniVRM10 { switch (key.Preset) { - case ExpressionPreset.happy: ExpressionMap.Add(key, () => preset_happy); break; - case ExpressionPreset.angry: ExpressionMap.Add(key, () => preset_angry); break; - case ExpressionPreset.sad: ExpressionMap.Add(key, () => preset_sad); break; - case ExpressionPreset.relaxed: ExpressionMap.Add(key, () => preset_relaxed); break; - case ExpressionPreset.surprised: ExpressionMap.Add(key, () => preset_surprised); break; - case ExpressionPreset.aa: ExpressionMap.Add(key, () => preset_aa); break; - case ExpressionPreset.ih: ExpressionMap.Add(key, () => preset_ih); break; - case ExpressionPreset.ou: ExpressionMap.Add(key, () => preset_ou); break; - case ExpressionPreset.ee: ExpressionMap.Add(key, () => preset_ee); break; - case ExpressionPreset.oh: ExpressionMap.Add(key, () => preset_oh); break; - case ExpressionPreset.blink: ExpressionMap.Add(key, () => preset_blink); break; - case ExpressionPreset.blinkLeft: ExpressionMap.Add(key, () => preset_blinkleft); break; - case ExpressionPreset.blinkRight: ExpressionMap.Add(key, () => preset_blinkright); break; - // case ExpressionPreset.lookUp: ExpressionMap.Add(key, () => preset_lookUp); break; - // case ExpressionPreset.lookDown: ExpressionMap.Add(key, () => preset_lookDown); break; - // case ExpressionPreset.lookLeft: ExpressionMap.Add(key, () => preset_lookLeft); break; - // case ExpressionPreset.lookRight: ExpressionMap.Add(key, () => preset_lookRight); break; - case ExpressionPreset.neutral: ExpressionMap.Add(key, () => preset_neutral); break; + case ExpressionPreset.happy: _ExpressionMap.Add(key, () => preset_happy); break; + case ExpressionPreset.angry: _ExpressionMap.Add(key, () => preset_angry); break; + case ExpressionPreset.sad: _ExpressionMap.Add(key, () => preset_sad); break; + case ExpressionPreset.relaxed: _ExpressionMap.Add(key, () => preset_relaxed); break; + case ExpressionPreset.surprised: _ExpressionMap.Add(key, () => preset_surprised); break; + case ExpressionPreset.aa: _ExpressionMap.Add(key, () => preset_aa); break; + case ExpressionPreset.ih: _ExpressionMap.Add(key, () => preset_ih); break; + case ExpressionPreset.ou: _ExpressionMap.Add(key, () => preset_ou); break; + case ExpressionPreset.ee: _ExpressionMap.Add(key, () => preset_ee); break; + case ExpressionPreset.oh: _ExpressionMap.Add(key, () => preset_oh); break; + case ExpressionPreset.blink: _ExpressionMap.Add(key, () => preset_blink); break; + case ExpressionPreset.blinkLeft: _ExpressionMap.Add(key, () => preset_blinkleft); break; + case ExpressionPreset.blinkRight: _ExpressionMap.Add(key, () => preset_blinkright); break; + // case ExpressionPreset.lookUp: _ExpressionMap.Add(key, () => preset_lookUp); break; + // case ExpressionPreset.lookDown: _ExpressionMap.Add(key, () => preset_lookDown); break; + // case ExpressionPreset.lookLeft: _ExpressionMap.Add(key, () => preset_lookLeft); break; + // case ExpressionPreset.lookRight: _ExpressionMap.Add(key, () => preset_lookRight); break; + case ExpressionPreset.neutral: _ExpressionMap.Add(key, () => preset_neutral); break; case ExpressionPreset.custom: { switch (customIndex++) { - case 00: ExpressionMap.Add(key, () => custom_00); break; - case 01: ExpressionMap.Add(key, () => custom_01); break; - case 02: ExpressionMap.Add(key, () => custom_02); break; - case 03: ExpressionMap.Add(key, () => custom_03); break; - case 04: ExpressionMap.Add(key, () => custom_04); break; - case 05: ExpressionMap.Add(key, () => custom_05); break; - case 06: ExpressionMap.Add(key, () => custom_06); break; - case 07: ExpressionMap.Add(key, () => custom_07); break; - case 08: ExpressionMap.Add(key, () => custom_08); break; - case 09: ExpressionMap.Add(key, () => custom_09); break; + case 00: _ExpressionMap.Add(key, () => custom_00); break; + case 01: _ExpressionMap.Add(key, () => custom_01); break; + case 02: _ExpressionMap.Add(key, () => custom_02); break; + case 03: _ExpressionMap.Add(key, () => custom_03); break; + case 04: _ExpressionMap.Add(key, () => custom_04); break; + case 05: _ExpressionMap.Add(key, () => custom_05); break; + case 06: _ExpressionMap.Add(key, () => custom_06); break; + case 07: _ExpressionMap.Add(key, () => custom_07); break; + case 08: _ExpressionMap.Add(key, () => custom_08); break; + case 09: _ExpressionMap.Add(key, () => custom_09); break; - case 10: ExpressionMap.Add(key, () => custom_10); break; - case 11: ExpressionMap.Add(key, () => custom_11); break; - case 12: ExpressionMap.Add(key, () => custom_12); break; - case 13: ExpressionMap.Add(key, () => custom_13); break; - case 14: ExpressionMap.Add(key, () => custom_14); break; - case 15: ExpressionMap.Add(key, () => custom_15); break; - case 16: ExpressionMap.Add(key, () => custom_16); break; - case 17: ExpressionMap.Add(key, () => custom_17); break; - case 18: ExpressionMap.Add(key, () => custom_18); break; - case 19: ExpressionMap.Add(key, () => custom_19); break; + case 10: _ExpressionMap.Add(key, () => custom_10); break; + case 11: _ExpressionMap.Add(key, () => custom_11); break; + case 12: _ExpressionMap.Add(key, () => custom_12); break; + case 13: _ExpressionMap.Add(key, () => custom_13); break; + case 14: _ExpressionMap.Add(key, () => custom_14); break; + case 15: _ExpressionMap.Add(key, () => custom_15); break; + case 16: _ExpressionMap.Add(key, () => custom_16); break; + case 17: _ExpressionMap.Add(key, () => custom_17); break; + case 18: _ExpressionMap.Add(key, () => custom_18); break; + case 19: _ExpressionMap.Add(key, () => custom_19); break; - case 20: ExpressionMap.Add(key, () => custom_20); break; - case 21: ExpressionMap.Add(key, () => custom_21); break; - case 22: ExpressionMap.Add(key, () => custom_22); break; - case 23: ExpressionMap.Add(key, () => custom_23); break; - case 24: ExpressionMap.Add(key, () => custom_24); break; - case 25: ExpressionMap.Add(key, () => custom_25); break; - case 26: ExpressionMap.Add(key, () => custom_26); break; - case 27: ExpressionMap.Add(key, () => custom_27); break; - case 28: ExpressionMap.Add(key, () => custom_28); break; - case 29: ExpressionMap.Add(key, () => custom_29); break; + case 20: _ExpressionMap.Add(key, () => custom_20); break; + case 21: _ExpressionMap.Add(key, () => custom_21); break; + case 22: _ExpressionMap.Add(key, () => custom_22); break; + case 23: _ExpressionMap.Add(key, () => custom_23); break; + case 24: _ExpressionMap.Add(key, () => custom_24); break; + case 25: _ExpressionMap.Add(key, () => custom_25); break; + case 26: _ExpressionMap.Add(key, () => custom_26); break; + case 27: _ExpressionMap.Add(key, () => custom_27); break; + case 28: _ExpressionMap.Add(key, () => custom_28); break; + case 29: _ExpressionMap.Add(key, () => custom_29); break; - case 30: ExpressionMap.Add(key, () => custom_30); break; - case 31: ExpressionMap.Add(key, () => custom_31); break; - case 32: ExpressionMap.Add(key, () => custom_32); break; - case 33: ExpressionMap.Add(key, () => custom_33); break; - case 34: ExpressionMap.Add(key, () => custom_34); break; - case 35: ExpressionMap.Add(key, () => custom_35); break; - case 36: ExpressionMap.Add(key, () => custom_36); break; - case 37: ExpressionMap.Add(key, () => custom_37); break; - case 38: ExpressionMap.Add(key, () => custom_38); break; - case 39: ExpressionMap.Add(key, () => custom_39); break; + case 30: _ExpressionMap.Add(key, () => custom_30); break; + case 31: _ExpressionMap.Add(key, () => custom_31); break; + case 32: _ExpressionMap.Add(key, () => custom_32); break; + case 33: _ExpressionMap.Add(key, () => custom_33); break; + case 34: _ExpressionMap.Add(key, () => custom_34); break; + case 35: _ExpressionMap.Add(key, () => custom_35); break; + case 36: _ExpressionMap.Add(key, () => custom_36); break; + case 37: _ExpressionMap.Add(key, () => custom_37); break; + case 38: _ExpressionMap.Add(key, () => custom_38); break; + case 39: _ExpressionMap.Add(key, () => custom_39); break; - case 40: ExpressionMap.Add(key, () => custom_40); break; - case 41: ExpressionMap.Add(key, () => custom_41); break; - case 42: ExpressionMap.Add(key, () => custom_42); break; - case 43: ExpressionMap.Add(key, () => custom_43); break; - case 44: ExpressionMap.Add(key, () => custom_44); break; - case 45: ExpressionMap.Add(key, () => custom_45); break; - case 46: ExpressionMap.Add(key, () => custom_46); break; - case 47: ExpressionMap.Add(key, () => custom_47); break; - case 48: ExpressionMap.Add(key, () => custom_48); break; - case 49: ExpressionMap.Add(key, () => custom_49); break; + case 40: _ExpressionMap.Add(key, () => custom_40); break; + case 41: _ExpressionMap.Add(key, () => custom_41); break; + case 42: _ExpressionMap.Add(key, () => custom_42); break; + case 43: _ExpressionMap.Add(key, () => custom_43); break; + case 44: _ExpressionMap.Add(key, () => custom_44); break; + case 45: _ExpressionMap.Add(key, () => custom_45); break; + case 46: _ExpressionMap.Add(key, () => custom_46); break; + case 47: _ExpressionMap.Add(key, () => custom_47); break; + case 48: _ExpressionMap.Add(key, () => custom_48); break; + case 49: _ExpressionMap.Add(key, () => custom_49); break; - case 50: ExpressionMap.Add(key, () => custom_50); break; - case 51: ExpressionMap.Add(key, () => custom_51); break; - case 52: ExpressionMap.Add(key, () => custom_52); break; - case 53: ExpressionMap.Add(key, () => custom_53); break; - case 54: ExpressionMap.Add(key, () => custom_54); break; - case 55: ExpressionMap.Add(key, () => custom_55); break; - case 56: ExpressionMap.Add(key, () => custom_56); break; - case 57: ExpressionMap.Add(key, () => custom_57); break; - case 58: ExpressionMap.Add(key, () => custom_58); break; - case 59: ExpressionMap.Add(key, () => custom_59); break; + case 50: _ExpressionMap.Add(key, () => custom_50); break; + case 51: _ExpressionMap.Add(key, () => custom_51); break; + case 52: _ExpressionMap.Add(key, () => custom_52); break; + case 53: _ExpressionMap.Add(key, () => custom_53); break; + case 54: _ExpressionMap.Add(key, () => custom_54); break; + case 55: _ExpressionMap.Add(key, () => custom_55); break; + case 56: _ExpressionMap.Add(key, () => custom_56); break; + case 57: _ExpressionMap.Add(key, () => custom_57); break; + case 58: _ExpressionMap.Add(key, () => custom_58); break; + case 59: _ExpressionMap.Add(key, () => custom_59); break; - case 60: ExpressionMap.Add(key, () => custom_60); break; - case 61: ExpressionMap.Add(key, () => custom_61); break; - case 62: ExpressionMap.Add(key, () => custom_62); break; - case 63: ExpressionMap.Add(key, () => custom_63); break; - case 64: ExpressionMap.Add(key, () => custom_64); break; - case 65: ExpressionMap.Add(key, () => custom_65); break; - case 66: ExpressionMap.Add(key, () => custom_66); break; - case 67: ExpressionMap.Add(key, () => custom_67); break; - case 68: ExpressionMap.Add(key, () => custom_68); break; - case 69: ExpressionMap.Add(key, () => custom_69); break; + case 60: _ExpressionMap.Add(key, () => custom_60); break; + case 61: _ExpressionMap.Add(key, () => custom_61); break; + case 62: _ExpressionMap.Add(key, () => custom_62); break; + case 63: _ExpressionMap.Add(key, () => custom_63); break; + case 64: _ExpressionMap.Add(key, () => custom_64); break; + case 65: _ExpressionMap.Add(key, () => custom_65); break; + case 66: _ExpressionMap.Add(key, () => custom_66); break; + case 67: _ExpressionMap.Add(key, () => custom_67); break; + case 68: _ExpressionMap.Add(key, () => custom_68); break; + case 69: _ExpressionMap.Add(key, () => custom_69); break; - case 70: ExpressionMap.Add(key, () => custom_70); break; - case 71: ExpressionMap.Add(key, () => custom_71); break; - case 72: ExpressionMap.Add(key, () => custom_72); break; - case 73: ExpressionMap.Add(key, () => custom_73); break; - case 74: ExpressionMap.Add(key, () => custom_74); break; - case 75: ExpressionMap.Add(key, () => custom_75); break; - case 76: ExpressionMap.Add(key, () => custom_76); break; - case 77: ExpressionMap.Add(key, () => custom_77); break; - case 78: ExpressionMap.Add(key, () => custom_78); break; - case 79: ExpressionMap.Add(key, () => custom_79); break; + case 70: _ExpressionMap.Add(key, () => custom_70); break; + case 71: _ExpressionMap.Add(key, () => custom_71); break; + case 72: _ExpressionMap.Add(key, () => custom_72); break; + case 73: _ExpressionMap.Add(key, () => custom_73); break; + case 74: _ExpressionMap.Add(key, () => custom_74); break; + case 75: _ExpressionMap.Add(key, () => custom_75); break; + case 76: _ExpressionMap.Add(key, () => custom_76); break; + case 77: _ExpressionMap.Add(key, () => custom_77); break; + case 78: _ExpressionMap.Add(key, () => custom_78); break; + case 79: _ExpressionMap.Add(key, () => custom_79); break; - case 80: ExpressionMap.Add(key, () => custom_80); break; - case 81: ExpressionMap.Add(key, () => custom_81); break; - case 82: ExpressionMap.Add(key, () => custom_82); break; - case 83: ExpressionMap.Add(key, () => custom_83); break; - case 84: ExpressionMap.Add(key, () => custom_84); break; - case 85: ExpressionMap.Add(key, () => custom_85); break; - case 86: ExpressionMap.Add(key, () => custom_86); break; - case 87: ExpressionMap.Add(key, () => custom_87); break; - case 88: ExpressionMap.Add(key, () => custom_88); break; - case 89: ExpressionMap.Add(key, () => custom_89); break; + case 80: _ExpressionMap.Add(key, () => custom_80); break; + case 81: _ExpressionMap.Add(key, () => custom_81); break; + case 82: _ExpressionMap.Add(key, () => custom_82); break; + case 83: _ExpressionMap.Add(key, () => custom_83); break; + case 84: _ExpressionMap.Add(key, () => custom_84); break; + case 85: _ExpressionMap.Add(key, () => custom_85); break; + case 86: _ExpressionMap.Add(key, () => custom_86); break; + case 87: _ExpressionMap.Add(key, () => custom_87); break; + case 88: _ExpressionMap.Add(key, () => custom_88); break; + case 89: _ExpressionMap.Add(key, () => custom_89); break; - case 90: ExpressionMap.Add(key, () => custom_90); break; - case 91: ExpressionMap.Add(key, () => custom_91); break; - case 92: ExpressionMap.Add(key, () => custom_92); break; - case 93: ExpressionMap.Add(key, () => custom_93); break; - case 94: ExpressionMap.Add(key, () => custom_94); break; - case 95: ExpressionMap.Add(key, () => custom_95); break; - case 96: ExpressionMap.Add(key, () => custom_96); break; - case 97: ExpressionMap.Add(key, () => custom_97); break; - case 98: ExpressionMap.Add(key, () => custom_98); break; - case 99: ExpressionMap.Add(key, () => custom_99); break; + case 90: _ExpressionMap.Add(key, () => custom_90); break; + case 91: _ExpressionMap.Add(key, () => custom_91); break; + case 92: _ExpressionMap.Add(key, () => custom_92); break; + case 93: _ExpressionMap.Add(key, () => custom_93); break; + case 94: _ExpressionMap.Add(key, () => custom_94); break; + case 95: _ExpressionMap.Add(key, () => custom_95); break; + case 96: _ExpressionMap.Add(key, () => custom_96); break; + case 97: _ExpressionMap.Add(key, () => custom_97); break; + case 98: _ExpressionMap.Add(key, () => custom_98); break; + case 99: _ExpressionMap.Add(key, () => custom_99); break; } break; } diff --git a/Assets/VRM10/Samples~/VRM10Viewer/VRM10Retarget.cs b/Assets/VRM10/Runtime/ControlRig/VRM10Retarget.cs similarity index 97% rename from Assets/VRM10/Samples~/VRM10Viewer/VRM10Retarget.cs rename to Assets/VRM10/Runtime/ControlRig/VRM10Retarget.cs index 2d91fb3e6..f1451b87d 100644 --- a/Assets/VRM10/Samples~/VRM10Viewer/VRM10Retarget.cs +++ b/Assets/VRM10/Runtime/ControlRig/VRM10Retarget.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace UniVRM10.VRM10Viewer +namespace UniVRM10 { public static class VRM10Retarget { diff --git a/Assets/VRM10/Runtime/ControlRig/VRM10Retarget.cs.meta b/Assets/VRM10/Runtime/ControlRig/VRM10Retarget.cs.meta new file mode 100644 index 000000000..5ed531706 --- /dev/null +++ b/Assets/VRM10/Runtime/ControlRig/VRM10Retarget.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e44301f13c6a1e74ba0e5322262db259 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Samples~/VRM10Viewer/Motions/IMotion.cs b/Assets/VRM10/Samples~/VRM10Viewer/Motions/IMotion.cs deleted file mode 100644 index 656548b24..000000000 --- a/Assets/VRM10/Samples~/VRM10Viewer/Motions/IMotion.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace UniVRM10.VRM10Viewer -{ - public interface IMotion : IDisposable - { - (INormalizedPoseProvider, ITPoseProvider) ControlRig { get; } - IDictionary ExpressionMap { get; } - - void ShowBoxMan(bool enable); - } -} diff --git a/Assets/VRM10_Samples/SimpleVrma.meta b/Assets/VRM10_Samples/SimpleVrma.meta new file mode 100644 index 000000000..ba2573e96 --- /dev/null +++ b/Assets/VRM10_Samples/SimpleVrma.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 59ba601fea149ed498a9ca37af1d3c55 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.cs b/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.cs new file mode 100644 index 000000000..60dfd567f --- /dev/null +++ b/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.cs @@ -0,0 +1,64 @@ +using UniGLTF; +using UnityEditor; +using UnityEngine; +using UniVRM10; +using UniVRM10.VRM10Viewer; +using VRMShaders; + +public class SimpleVrma : MonoBehaviour +{ + public Vrm10Instance Vrm; + + public VrmAnimationInstance Vrma; + + bool m_boxman = true; + + void OnGUI() + { + if (GUILayout.Button("open vrm")) + { + var path = EditorUtility.OpenFilePanel("open vrm", "", "vrm"); + Debug.Log(path); + LoadVrm(path); + } + + if (GUILayout.Button("open vrma")) + { + var path = EditorUtility.OpenFilePanel("open vrma", "", "vrma"); + Debug.Log(path); + LoadVrma(path); + } + + m_boxman = GUILayout.Toggle(m_boxman, "BoxMan"); + if (Vrma != null) + { + Vrma.BoxMan.enabled = m_boxman; + } + } + + async void LoadVrm(string path) + { + Vrm = await Vrm10.LoadPathAsync(path, + canLoadVrm0X: true, + showMeshes: false, + awaitCaller: new ImmediateCaller()); + + var instance = Vrm.GetComponent(); + instance.ShowMeshes(); + } + + async void LoadVrma(string path) + { + // load vrma + using GltfData data = new AutoGltfFileParser(path).Parse(); + using var loader = new VrmAnimationImporter(data); + var instance = await loader.LoadAsync(new ImmediateCaller()); + + Vrma = instance.GetComponent(); + Vrm.Runtime.VrmAnimation = Vrma; + Debug.Log(Vrma); + + var animation = Vrma.GetComponent(); + animation.Play(); + } +} diff --git a/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.cs.meta b/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.cs.meta new file mode 100644 index 000000000..b0cba8bd7 --- /dev/null +++ b/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e941e78669b3e784fa684c23441459fb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.unity b/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.unity new file mode 100644 index 000000000..cd21b85b5 --- /dev/null +++ b/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.unity @@ -0,0 +1,349 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!29 &1 +OcclusionCullingSettings: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_OcclusionBakeSettings: + smallestOccluder: 5 + smallestHole: 0.25 + backfaceThreshold: 100 + m_SceneGUID: 00000000000000000000000000000000 + m_OcclusionCullingData: {fileID: 0} +--- !u!104 &2 +RenderSettings: + m_ObjectHideFlags: 0 + serializedVersion: 9 + m_Fog: 0 + m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} + m_FogMode: 3 + m_FogDensity: 0.01 + m_LinearFogStart: 0 + m_LinearFogEnd: 300 + m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} + m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} + m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} + m_AmbientIntensity: 1 + m_AmbientMode: 0 + m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} + m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} + m_HaloStrength: 0.5 + m_FlareStrength: 1 + m_FlareFadeSpeed: 3 + m_HaloTexture: {fileID: 0} + m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} + m_DefaultReflectionMode: 0 + m_DefaultReflectionResolution: 128 + m_ReflectionBounces: 1 + m_ReflectionIntensity: 1 + m_CustomReflection: {fileID: 0} + m_Sun: {fileID: 0} + m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1} + m_UseRadianceAmbientProbe: 0 +--- !u!157 &3 +LightmapSettings: + m_ObjectHideFlags: 0 + serializedVersion: 12 + m_GIWorkflowMode: 1 + m_GISettings: + serializedVersion: 2 + m_BounceScale: 1 + m_IndirectOutputScale: 1 + m_AlbedoBoost: 1 + m_EnvironmentLightingMode: 0 + m_EnableBakedLightmaps: 1 + m_EnableRealtimeLightmaps: 0 + m_LightmapEditorSettings: + serializedVersion: 12 + m_Resolution: 2 + m_BakeResolution: 40 + m_AtlasSize: 1024 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_ExtractAmbientOcclusion: 0 + m_Padding: 2 + m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 + m_TextureCompression: 1 + m_FinalGather: 0 + m_FinalGatherFiltering: 1 + m_FinalGatherRayCount: 256 + m_ReflectionCompression: 2 + m_MixedBakeMode: 2 + m_BakeBackend: 1 + m_PVRSampling: 1 + m_PVRDirectSampleCount: 32 + m_PVRSampleCount: 512 + m_PVRBounces: 2 + m_PVREnvironmentSampleCount: 256 + m_PVREnvironmentReferencePointCount: 2048 + m_PVRFilteringMode: 1 + m_PVRDenoiserTypeDirect: 1 + m_PVRDenoiserTypeIndirect: 1 + m_PVRDenoiserTypeAO: 1 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 + m_PVREnvironmentMIS: 1 + m_PVRCulling: 1 + m_PVRFilteringGaussRadiusDirect: 1 + m_PVRFilteringGaussRadiusIndirect: 5 + m_PVRFilteringGaussRadiusAO: 2 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 + m_ExportTrainingData: 0 + m_TrainingDataDestination: TrainingData + m_LightProbeSampleCountMultiplier: 4 + m_LightingDataAsset: {fileID: 0} + m_LightingSettings: {fileID: 0} +--- !u!196 &4 +NavMeshSettings: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_BuildSettings: + serializedVersion: 2 + agentTypeID: 0 + agentRadius: 0.5 + agentHeight: 2 + agentSlope: 45 + agentClimb: 0.4 + ledgeDropHeight: 0 + maxJumpAcrossDistance: 0 + minRegionArea: 2 + manualCellSize: 0 + cellSize: 0.16666667 + manualTileSize: 0 + tileSize: 256 + accuratePlacement: 0 + maxJobWorkers: 0 + preserveTilesOutsideBounds: 0 + debug: + m_Flags: 0 + m_NavMeshData: {fileID: 0} +--- !u!1 &45959732 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 45959734} + - component: {fileID: 45959733} + m_Layer: 0 + m_Name: Directional Light + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!108 &45959733 +Light: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 45959732} + m_Enabled: 1 + serializedVersion: 10 + m_Type: 1 + m_Shape: 0 + m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} + m_Intensity: 1 + m_Range: 10 + m_SpotAngle: 30 + m_InnerSpotAngle: 21.80208 + m_CookieSize: 10 + m_Shadows: + m_Type: 2 + m_Resolution: -1 + m_CustomResolution: -1 + m_Strength: 1 + m_Bias: 0.05 + m_NormalBias: 0.4 + m_NearPlane: 0.2 + m_CullingMatrixOverride: + e00: 1 + e01: 0 + e02: 0 + e03: 0 + e10: 0 + e11: 1 + e12: 0 + e13: 0 + e20: 0 + e21: 0 + e22: 1 + e23: 0 + e30: 0 + e31: 0 + e32: 0 + e33: 1 + m_UseCullingMatrixOverride: 0 + m_Cookie: {fileID: 0} + m_DrawHalo: 0 + m_Flare: {fileID: 0} + m_RenderMode: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingLayerMask: 1 + m_Lightmapping: 4 + m_LightShadowCasterMode: 0 + m_AreaSize: {x: 1, y: 1} + m_BounceIntensity: 1 + m_ColorTemperature: 6570 + m_UseColorTemperature: 0 + m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} + m_UseBoundingSphereOverride: 0 + m_UseViewFrustumForShadowCasterCull: 1 + m_ShadowRadius: 0 + m_ShadowAngle: 0 +--- !u!4 &45959734 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 45959732} + m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} + m_LocalPosition: {x: 0, y: 3, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} +--- !u!1 &231202275 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 231202278} + - component: {fileID: 231202277} + - component: {fileID: 231202276} + m_Layer: 0 + m_Name: Main Camera + m_TagString: MainCamera + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!81 &231202276 +AudioListener: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 231202275} + m_Enabled: 1 +--- !u!20 &231202277 +Camera: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 231202275} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_projectionMatrixMode: 1 + m_GateFitMode: 2 + m_FOVAxisMode: 0 + m_SensorSize: {x: 36, y: 24} + m_LensShift: {x: 0, y: 0} + m_FocalLength: 50 + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 0 + orthographic size: 5 + m_Depth: -1 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 1 + m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 +--- !u!4 &231202278 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 231202275} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 1, z: -10} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &2069542080 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2069542081} + - component: {fileID: 2069542082} + m_Layer: 0 + m_Name: vrma + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2069542081 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2069542080} + 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_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &2069542082 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2069542080} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e941e78669b3e784fa684c23441459fb, type: 3} + m_Name: + m_EditorClassIdentifier: + Vrm: {fileID: 0} + Vrma: {fileID: 0} diff --git a/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.unity.meta b/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.unity.meta new file mode 100644 index 000000000..df659705b --- /dev/null +++ b/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.unity.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 7ceefca1729da714e8f1163c8f391445 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10_Samples/VRM10Viewer/Motions/BvhMotion.cs b/Assets/VRM10_Samples/VRM10Viewer/Motions/BvhMotion.cs index e3993d08c..68e5a5a2a 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/Motions/BvhMotion.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/Motions/BvhMotion.cs @@ -6,15 +6,17 @@ using UnityEngine; namespace UniVRM10.VRM10Viewer { - public class BvhMotion : IMotion + public class BvhMotion : IVrmAnimation { UniHumanoid.BvhImporterContext m_context; public Transform Root => m_context?.Root.transform; public SkinnedMeshRenderer m_boxMan; public SkinnedMeshRenderer BoxMan => m_boxMan; (INormalizedPoseProvider, ITPoseProvider) m_controlRig; - (INormalizedPoseProvider, ITPoseProvider) IMotion.ControlRig => m_controlRig; - public IDictionary> ExpressionMap { get; } = new Dictionary>(); + (INormalizedPoseProvider, ITPoseProvider) IVrmAnimation.ControlRig => m_controlRig; + IDictionary> _ExpressionMap = new Dictionary>(); + public IReadOnlyDictionary> ExpressionMap => (IReadOnlyDictionary>)_ExpressionMap; + public BvhMotion(UniHumanoid.BvhImporterContext context) { m_context = context; diff --git a/Assets/VRM10_Samples/VRM10Viewer/Motions/IMotion.cs b/Assets/VRM10_Samples/VRM10Viewer/Motions/IMotion.cs deleted file mode 100644 index 5c74619ed..000000000 --- a/Assets/VRM10_Samples/VRM10Viewer/Motions/IMotion.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace UniVRM10.VRM10Viewer -{ - public interface IMotion : IDisposable - { - (INormalizedPoseProvider, ITPoseProvider) ControlRig { get; } - IDictionary> ExpressionMap { get; } - - void ShowBoxMan(bool enable); - } -} diff --git a/Assets/VRM10_Samples/VRM10Viewer/Motions/VrmAnimation.cs b/Assets/VRM10_Samples/VRM10Viewer/Motions/VrmAnimation.cs index 0d801c0a1..354a11b99 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/Motions/VrmAnimation.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/Motions/VrmAnimation.cs @@ -8,12 +8,12 @@ using VRMShaders; namespace UniVRM10.VRM10Viewer { - public class VrmAnimation : IMotion + public class VrmAnimation : IVrmAnimation { private readonly VrmAnimationInstance m_instance; - (INormalizedPoseProvider, ITPoseProvider) IMotion.ControlRig => m_instance.ControlRig; - IDictionary> IMotion.ExpressionMap => m_instance.ExpressionMap; + (INormalizedPoseProvider, ITPoseProvider) IVrmAnimation.ControlRig => m_instance.ControlRig; + IReadOnlyDictionary> IVrmAnimation.ExpressionMap => m_instance.ExpressionMap; public VrmAnimation(VrmAnimationInstance instance, Vector3 hips = default, Dictionary map = null) @@ -58,13 +58,6 @@ namespace UniVRM10.VRM10Viewer } } - public static async Task LoadVrmAnimationFromPathAsync(string path) - { - using GltfData data = new AutoGltfFileParser(path).Parse(); - using var loader = new VrmAnimationImporter(data); - var instance = await loader.LoadAsync(new ImmediateCaller()); - return new VrmAnimation(instance.GetComponent()); - } static Vector3 ToVec3(JsonNode j) { diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs index 2b7410322..e6d57609b 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs @@ -1,11 +1,14 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading; +using System.Threading.Tasks; using UniGLTF; using UnityEngine; using UnityEngine.UI; using VRMShaders; +using UniJSON; namespace UniVRM10.VRM10Viewer { @@ -50,8 +53,8 @@ namespace UniVRM10.VRM10Viewer GameObject Root = default; - IMotion m_src = default; - public IMotion Motion + IVrmAnimation m_src = default; + public IVrmAnimation Motion { get { return m_src; } set @@ -431,7 +434,11 @@ namespace UniVRM10.VRM10Viewer } // gltf, glb etc... - Motion = await VrmAnimation.LoadVrmAnimationFromPathAsync(path); + using GltfData data = new AutoGltfFileParser(path).Parse(); + using var loader = new VrmAnimationImporter(data); + var instance = await loader.LoadAsync(new ImmediateCaller()); + Motion = instance.GetComponent(); + instance.GetComponent().Play(); } async void OnPastePoseClicked() From 01fe012fbf832d0abe335f5e8e98d871043e8882 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 16 Aug 2023 14:49:21 +0900 Subject: [PATCH 2/4] 1 origin --- .../Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs index c80330b20..6c075d77b 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs @@ -189,7 +189,7 @@ namespace UniVRM10 /// public void Process() { - // 0. Update From VrmAnimation + // 1. Update From VrmAnimation if (VrmAnimation != null) { // copy pose @@ -206,19 +206,19 @@ namespace UniVRM10 // TODO: look at target } - // 1. Control Rig + // 2. Control Rig ControlRig?.Process(); - // 2. Constraints + // 3. Constraints foreach (var constraint in Constraints) { constraint.Process(); } - // 3. Gaze control + // 4. Gaze control LookAt.Process(m_target.LookAtTargetType, m_target.LookAtTarget); - // 4. Apply Expression + // 5. Apply Expression Expression.Process(); } } From 00641d47208915ff5e9b787bbc4f3214b7576b57 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 16 Aug 2023 14:58:40 +0900 Subject: [PATCH 3/4] naming --- .../Components/Vrm10Runtime/Vrm10Runtime.cs | 4 +-- .../{IVrmAnimation.cs => IVrm10Animation.cs} | 2 +- ...mation.cs.meta => IVrm10Animation.cs.meta} | 0 ...nInstance.cs => Vrm10AnimationInstance.cs} | 2 +- ...cs.meta => Vrm10AnimationInstance.cs.meta} | 0 .../VRM10/Runtime/ControlRig/VRM10Retarget.cs | 2 +- .../VRM10/Runtime/IO/VrmAnimationImporter.cs | 32 +++++++++---------- Assets/VRM10_Samples/SimpleVrma/SimpleVrma.cs | 4 +-- .../VRM10Viewer/Motions/BvhMotion.cs | 4 +-- .../VRM10Viewer/Motions/VrmAnimation.cs | 12 +++---- .../VRM10Viewer/VRM10ViewerUI.cs | 6 ++-- 11 files changed, 34 insertions(+), 34 deletions(-) rename Assets/VRM10/Runtime/Components/VrmAnimationInstance/{IVrmAnimation.cs => IVrm10Animation.cs} (84%) rename Assets/VRM10/Runtime/Components/VrmAnimationInstance/{IVrmAnimation.cs.meta => IVrm10Animation.cs.meta} (100%) rename Assets/VRM10/Runtime/Components/VrmAnimationInstance/{VrmAnimationInstance.cs => Vrm10AnimationInstance.cs} (99%) rename Assets/VRM10/Runtime/Components/VrmAnimationInstance/{VrmAnimationInstance.cs.meta => Vrm10AnimationInstance.cs.meta} (100%) diff --git a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs index 6c075d77b..7af7e4362 100644 --- a/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs +++ b/Assets/VRM10/Runtime/Components/Vrm10Runtime/Vrm10Runtime.cs @@ -39,7 +39,7 @@ namespace UniVRM10 public Vrm10RuntimeExpression Expression { get; } public Vrm10RuntimeLookAt LookAt { get; } - public IVrmAnimation VrmAnimation { get; set; } + public IVrm10Animation VrmAnimation { get; set; } public Vector3 ExternalForce { @@ -194,7 +194,7 @@ namespace UniVRM10 { // copy pose { - VRM10Retarget.Retarget(VrmAnimation.ControlRig, (ControlRig, ControlRig)); + Vrm10Retarget.Retarget(VrmAnimation.ControlRig, (ControlRig, ControlRig)); } // update expressions diff --git a/Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrmAnimation.cs b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrm10Animation.cs similarity index 84% rename from Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrmAnimation.cs rename to Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrm10Animation.cs index e33985a8a..7242e5b1f 100644 --- a/Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrmAnimation.cs +++ b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrm10Animation.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace UniVRM10 { - public interface IVrmAnimation : IDisposable + public interface IVrm10Animation : IDisposable { (INormalizedPoseProvider, ITPoseProvider) ControlRig { get; } IReadOnlyDictionary> ExpressionMap { get; } diff --git a/Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrmAnimation.cs.meta b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrm10Animation.cs.meta similarity index 100% rename from Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrmAnimation.cs.meta rename to Assets/VRM10/Runtime/Components/VrmAnimationInstance/IVrm10Animation.cs.meta diff --git a/Assets/VRM10/Runtime/Components/VrmAnimationInstance/VrmAnimationInstance.cs b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/Vrm10AnimationInstance.cs similarity index 99% rename from Assets/VRM10/Runtime/Components/VrmAnimationInstance/VrmAnimationInstance.cs rename to Assets/VRM10/Runtime/Components/VrmAnimationInstance/Vrm10AnimationInstance.cs index 7c727c240..7012be45c 100644 --- a/Assets/VRM10/Runtime/Components/VrmAnimationInstance/VrmAnimationInstance.cs +++ b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/Vrm10AnimationInstance.cs @@ -5,7 +5,7 @@ using UnityEngine; namespace UniVRM10 { - public class VrmAnimationInstance : MonoBehaviour, IVrmAnimation + public class Vrm10AnimationInstance : MonoBehaviour, IVrm10Animation { public SkinnedMeshRenderer BoxMan; diff --git a/Assets/VRM10/Runtime/Components/VrmAnimationInstance/VrmAnimationInstance.cs.meta b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/Vrm10AnimationInstance.cs.meta similarity index 100% rename from Assets/VRM10/Runtime/Components/VrmAnimationInstance/VrmAnimationInstance.cs.meta rename to Assets/VRM10/Runtime/Components/VrmAnimationInstance/Vrm10AnimationInstance.cs.meta diff --git a/Assets/VRM10/Runtime/ControlRig/VRM10Retarget.cs b/Assets/VRM10/Runtime/ControlRig/VRM10Retarget.cs index f1451b87d..045be6766 100644 --- a/Assets/VRM10/Runtime/ControlRig/VRM10Retarget.cs +++ b/Assets/VRM10/Runtime/ControlRig/VRM10Retarget.cs @@ -2,7 +2,7 @@ using UnityEngine; namespace UniVRM10 { - public static class VRM10Retarget + public static class Vrm10Retarget { public static void Retarget((INormalizedPoseProvider Pose, ITPoseProvider TPose) source, (INormalizedPoseApplicable Pose, ITPoseProvider TPose) sink) { diff --git a/Assets/VRM10/Runtime/IO/VrmAnimationImporter.cs b/Assets/VRM10/Runtime/IO/VrmAnimationImporter.cs index 502e82beb..33b1d44c7 100644 --- a/Assets/VRM10/Runtime/IO/VrmAnimationImporter.cs +++ b/Assets/VRM10/Runtime/IO/VrmAnimationImporter.cs @@ -161,24 +161,24 @@ namespace UniVRM10 var gltfAnimation = Data.GLTF.animations[0]; if (animation.Expressions.Preset is Preset preset) { - { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.happy), nameof(VrmAnimationInstance.preset_happy), preset.Happy) is ExpressionInfo info) yield return info; } - { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.angry), nameof(VrmAnimationInstance.preset_angry), preset.Angry) is ExpressionInfo info) yield return info; } - { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.sad), nameof(VrmAnimationInstance.preset_sad), preset.Sad) is ExpressionInfo info) yield return info; } - { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.relaxed), nameof(VrmAnimationInstance.preset_relaxed), preset.Relaxed) is ExpressionInfo info) yield return info; } - { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.surprised), nameof(VrmAnimationInstance.preset_surprised), preset.Surprised) is ExpressionInfo info) yield return info; } - { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.aa), nameof(VrmAnimationInstance.preset_aa), preset.Aa) is ExpressionInfo info) yield return info; } - { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.ih), nameof(VrmAnimationInstance.preset_ih), preset.Ih) is ExpressionInfo info) yield return info; } - { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.ou), nameof(VrmAnimationInstance.preset_ou), preset.Ou) is ExpressionInfo info) yield return info; } - { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.ee), nameof(VrmAnimationInstance.preset_ee), preset.Ee) is ExpressionInfo info) yield return info; } - { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.oh), nameof(VrmAnimationInstance.preset_oh), preset.Oh) is ExpressionInfo info) yield return info; } - { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.blink), nameof(VrmAnimationInstance.preset_blink), preset.Blink) is ExpressionInfo info) yield return info; } - { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.blinkLeft), nameof(VrmAnimationInstance.preset_blinkleft), preset.BlinkLeft) is ExpressionInfo info) yield return info; } - { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.blinkRight), nameof(VrmAnimationInstance.preset_blinkright), preset.BlinkRight) is ExpressionInfo info) yield return info; } + { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.happy), nameof(Vrm10AnimationInstance.preset_happy), preset.Happy) is ExpressionInfo info) yield return info; } + { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.angry), nameof(Vrm10AnimationInstance.preset_angry), preset.Angry) is ExpressionInfo info) yield return info; } + { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.sad), nameof(Vrm10AnimationInstance.preset_sad), preset.Sad) is ExpressionInfo info) yield return info; } + { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.relaxed), nameof(Vrm10AnimationInstance.preset_relaxed), preset.Relaxed) is ExpressionInfo info) yield return info; } + { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.surprised), nameof(Vrm10AnimationInstance.preset_surprised), preset.Surprised) is ExpressionInfo info) yield return info; } + { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.aa), nameof(Vrm10AnimationInstance.preset_aa), preset.Aa) is ExpressionInfo info) yield return info; } + { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.ih), nameof(Vrm10AnimationInstance.preset_ih), preset.Ih) is ExpressionInfo info) yield return info; } + { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.ou), nameof(Vrm10AnimationInstance.preset_ou), preset.Ou) is ExpressionInfo info) yield return info; } + { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.ee), nameof(Vrm10AnimationInstance.preset_ee), preset.Ee) is ExpressionInfo info) yield return info; } + { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.oh), nameof(Vrm10AnimationInstance.preset_oh), preset.Oh) is ExpressionInfo info) yield return info; } + { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.blink), nameof(Vrm10AnimationInstance.preset_blink), preset.Blink) is ExpressionInfo info) yield return info; } + { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.blinkLeft), nameof(Vrm10AnimationInstance.preset_blinkleft), preset.BlinkLeft) is ExpressionInfo info) yield return info; } + { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.blinkRight), nameof(Vrm10AnimationInstance.preset_blinkright), preset.BlinkRight) is ExpressionInfo info) yield return info; } { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.lookUp), "preset_lookup", preset.LookUp) is ExpressionInfo info) yield return info; } { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.lookDown), "preset_lookdown", preset.LookDown) is ExpressionInfo info) yield return info; } { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.lookLeft), "preset_lookleft", preset.LookLeft) is ExpressionInfo info) yield return info; } { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.lookRight), "preset_lookright", preset.LookRight) is ExpressionInfo info) yield return info; } - { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.neutral), nameof(VrmAnimationInstance.preset_neutral), preset.Neutral) is ExpressionInfo info) yield return info; } + { if (GetExpression(gltfAnimation, ExpressionKey.CreateFromPreset(ExpressionPreset.neutral), nameof(Vrm10AnimationInstance.preset_neutral), preset.Neutral) is ExpressionInfo info) yield return info; } } if (animation.Expressions.Custom != null) { @@ -278,12 +278,12 @@ namespace UniVRM10 var curve = CreateCurve( input.ToArray(), output.ToArray()); - clip.SetCurve("", typeof(VrmAnimationInstance), expression.PropertyName, curve); + clip.SetCurve("", typeof(Vrm10AnimationInstance), expression.PropertyName, curve); } } // VRMA-animation solver - var animationInstance = instance.gameObject.AddComponent(); + var animationInstance = instance.gameObject.AddComponent(); animationInstance.Initialize(expressions.Select(x => x.Key)); return instance; diff --git a/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.cs b/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.cs index 60dfd567f..40f12753a 100644 --- a/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.cs +++ b/Assets/VRM10_Samples/SimpleVrma/SimpleVrma.cs @@ -9,7 +9,7 @@ public class SimpleVrma : MonoBehaviour { public Vrm10Instance Vrm; - public VrmAnimationInstance Vrma; + public Vrm10AnimationInstance Vrma; bool m_boxman = true; @@ -54,7 +54,7 @@ public class SimpleVrma : MonoBehaviour using var loader = new VrmAnimationImporter(data); var instance = await loader.LoadAsync(new ImmediateCaller()); - Vrma = instance.GetComponent(); + Vrma = instance.GetComponent(); Vrm.Runtime.VrmAnimation = Vrma; Debug.Log(Vrma); diff --git a/Assets/VRM10_Samples/VRM10Viewer/Motions/BvhMotion.cs b/Assets/VRM10_Samples/VRM10Viewer/Motions/BvhMotion.cs index 68e5a5a2a..ffebf9cab 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/Motions/BvhMotion.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/Motions/BvhMotion.cs @@ -6,14 +6,14 @@ using UnityEngine; namespace UniVRM10.VRM10Viewer { - public class BvhMotion : IVrmAnimation + public class BvhMotion : IVrm10Animation { UniHumanoid.BvhImporterContext m_context; public Transform Root => m_context?.Root.transform; public SkinnedMeshRenderer m_boxMan; public SkinnedMeshRenderer BoxMan => m_boxMan; (INormalizedPoseProvider, ITPoseProvider) m_controlRig; - (INormalizedPoseProvider, ITPoseProvider) IVrmAnimation.ControlRig => m_controlRig; + (INormalizedPoseProvider, ITPoseProvider) IVrm10Animation.ControlRig => m_controlRig; IDictionary> _ExpressionMap = new Dictionary>(); public IReadOnlyDictionary> ExpressionMap => (IReadOnlyDictionary>)_ExpressionMap; diff --git a/Assets/VRM10_Samples/VRM10Viewer/Motions/VrmAnimation.cs b/Assets/VRM10_Samples/VRM10Viewer/Motions/VrmAnimation.cs index 354a11b99..773149edd 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/Motions/VrmAnimation.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/Motions/VrmAnimation.cs @@ -8,14 +8,14 @@ using VRMShaders; namespace UniVRM10.VRM10Viewer { - public class VrmAnimation : IVrmAnimation + public class VrmAnimation : IVrm10Animation { - private readonly VrmAnimationInstance m_instance; + private readonly Vrm10AnimationInstance m_instance; - (INormalizedPoseProvider, ITPoseProvider) IVrmAnimation.ControlRig => m_instance.ControlRig; - IReadOnlyDictionary> IVrmAnimation.ExpressionMap => m_instance.ExpressionMap; + (INormalizedPoseProvider, ITPoseProvider) IVrm10Animation.ControlRig => m_instance.ControlRig; + IReadOnlyDictionary> IVrm10Animation.ExpressionMap => m_instance.ExpressionMap; - public VrmAnimation(VrmAnimationInstance instance, + public VrmAnimation(Vrm10AnimationInstance instance, Vector3 hips = default, Dictionary map = null) { m_instance = instance; @@ -171,7 +171,7 @@ namespace UniVRM10.VRM10Viewer if (pose.TryGet("humanoid", out var humanoid)) { var (root, map) = GetPose(humanoid); - return new VrmAnimation(instance.GetComponent(), root, map); + return new VrmAnimation(instance.GetComponent(), root, map); } } } diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs index e6d57609b..2baeb5bc2 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs @@ -53,8 +53,8 @@ namespace UniVRM10.VRM10Viewer GameObject Root = default; - IVrmAnimation m_src = default; - public IVrmAnimation Motion + IVrm10Animation m_src = default; + public IVrm10Animation Motion { get { return m_src; } set @@ -437,7 +437,7 @@ namespace UniVRM10.VRM10Viewer using GltfData data = new AutoGltfFileParser(path).Parse(); using var loader = new VrmAnimationImporter(data); var instance = await loader.LoadAsync(new ImmediateCaller()); - Motion = instance.GetComponent(); + Motion = instance.GetComponent(); instance.GetComponent().Play(); } From 5bd34669f5af265be8bb632157eb26e29ea2e6bb Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 16 Aug 2023 15:05:02 +0900 Subject: [PATCH 4/4] rename --- .../Runtime/ControlRig/{VRM10Retarget.cs => Vrm10Retarget.cs} | 0 .../ControlRig/{VRM10Retarget.cs.meta => Vrm10Retarget.cs.meta} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Assets/VRM10/Runtime/ControlRig/{VRM10Retarget.cs => Vrm10Retarget.cs} (100%) rename Assets/VRM10/Runtime/ControlRig/{VRM10Retarget.cs.meta => Vrm10Retarget.cs.meta} (100%) diff --git a/Assets/VRM10/Runtime/ControlRig/VRM10Retarget.cs b/Assets/VRM10/Runtime/ControlRig/Vrm10Retarget.cs similarity index 100% rename from Assets/VRM10/Runtime/ControlRig/VRM10Retarget.cs rename to Assets/VRM10/Runtime/ControlRig/Vrm10Retarget.cs diff --git a/Assets/VRM10/Runtime/ControlRig/VRM10Retarget.cs.meta b/Assets/VRM10/Runtime/ControlRig/Vrm10Retarget.cs.meta similarity index 100% rename from Assets/VRM10/Runtime/ControlRig/VRM10Retarget.cs.meta rename to Assets/VRM10/Runtime/ControlRig/Vrm10Retarget.cs.meta