diff --git a/Assets/VRM10_Samples/VRM10Viewer/Motions/VrmAnimation.cs b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/Vrm10PoseLoader.cs similarity index 82% rename from Assets/VRM10_Samples/VRM10Viewer/Motions/VrmAnimation.cs rename to Assets/VRM10/Runtime/Components/VrmAnimationInstance/Vrm10PoseLoader.cs index 002276eb7..500e34931 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/Motions/VrmAnimation.cs +++ b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/Vrm10PoseLoader.cs @@ -6,59 +6,26 @@ using UniJSON; using UnityEngine; using VRMShaders; -namespace UniVRM10.VRM10Viewer +namespace UniVRM10 { - public class VrmAnimation : IVrm10Animation + public static class Vrm10PoseLoader { - private readonly Vrm10AnimationInstance m_instance; - - (INormalizedPoseProvider, ITPoseProvider) IVrm10Animation.ControlRig => m_instance.ControlRig; - IReadOnlyDictionary> IVrm10Animation.ExpressionMap => m_instance.ExpressionMap; - - public VrmAnimation(Vrm10AnimationInstance instance, + public static void LoadHumanPose(Vrm10AnimationInstance instance, Vector3 hips = default, Dictionary map = null) { - m_instance = instance; - if (instance.GetComponent() is Animation animation) + // experimental: set pose + var animator = instance.GetComponent(); + animator.GetBoneTransform(HumanBodyBones.Hips).localPosition = hips; + foreach (var kv in map) { - if (animation != null) + var t = animator.GetBoneTransform(kv.Key); + if (t != null) { - animation.Play(); - } - else - { - // experimental: set pose - var animator = instance.GetComponent(); - animator.GetBoneTransform(HumanBodyBones.Hips).localPosition = hips; - foreach (var kv in map) - { - var t = animator.GetBoneTransform(kv.Key); - if (t != null) - { - t.localRotation = kv.Value; - } - } + t.localRotation = kv.Value; } } } - public void ShowBoxMan(bool enable) - { - if (m_instance.BoxMan != null) - { - m_instance.BoxMan.enabled = enable; - } - } - - public void Dispose() - { - if (m_instance.BoxMan != null) - { - GameObject.Destroy(m_instance.BoxMan.gameObject); - } - } - - static Vector3 ToVec3(JsonNode j) { return new Vector3(-j[0].GetSingle(), j[1].GetSingle(), j[2].GetSingle()); @@ -146,7 +113,7 @@ namespace UniVRM10.VRM10Viewer return (root, map); } - public static async Task LoadVrmAnimationPose(string text) + public static async Task LoadVrmAnimationPose(string text) { using GltfData data = GlbLowLevelParser.ParseGltf( "tmp.vrma", @@ -156,7 +123,8 @@ namespace UniVRM10.VRM10Viewer new MigrationFlags() ); using var loader = new VrmAnimationImporter(data); - var instance = await loader.LoadAsync(new ImmediateCaller()); + var gltfInstance = await loader.LoadAsync(new ImmediateCaller()); + var instance = gltfInstance.GetComponent(); if (data.GLTF.extensions is UniGLTF.glTFExtensionImport extensions) { @@ -171,7 +139,7 @@ namespace UniVRM10.VRM10Viewer if (pose.TryGet("humanoid", out var humanoid)) { var (root, map) = GetPose(humanoid); - return new VrmAnimation(instance.GetComponent(), root, map); + LoadHumanPose(instance, root, map); } } } @@ -179,7 +147,7 @@ namespace UniVRM10.VRM10Viewer } } - throw new System.Exception("no pose"); + return instance; } } } diff --git a/Assets/VRM10_Samples/VRM10Viewer/Motions/VrmAnimation.cs.meta b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/Vrm10PoseLoader.cs.meta similarity index 83% rename from Assets/VRM10_Samples/VRM10Viewer/Motions/VrmAnimation.cs.meta rename to Assets/VRM10/Runtime/Components/VrmAnimationInstance/Vrm10PoseLoader.cs.meta index 1ea946b9b..2710da198 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/Motions/VrmAnimation.cs.meta +++ b/Assets/VRM10/Runtime/Components/VrmAnimationInstance/Vrm10PoseLoader.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f0180f844d447bc45889d6c72a2d4ec4 +guid: 9e5c411775bed594e9698d805f06e710 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs index 2baeb5bc2..9a813670f 100644 --- a/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs +++ b/Assets/VRM10_Samples/VRM10Viewer/VRM10ViewerUI.cs @@ -1,14 +1,11 @@ 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 { @@ -454,7 +451,7 @@ namespace UniVRM10.VRM10Viewer try { - Motion = await VrmAnimation.LoadVrmAnimationPose(text); + Motion = await Vrm10PoseLoader.LoadVrmAnimationPose(text); } catch (UniJSON.ParserException) {