From f64f00e2d32c0a1694417c290dd3b8a50e44530a Mon Sep 17 00:00:00 2001 From: bd_ Date: Fri, 6 Jan 2023 23:45:10 +0900 Subject: [PATCH] chore: Add AnimateAddedBones test --- .../EditModeTests}/AnimateAddedBones.meta | 0 .../AnimateAddedBones/AAB_Animation.anim | 0 .../AnimateAddedBones/AAB_Animation.anim.meta | 0 .../AAB_Controller.controller | 4 +- .../AAB_Controller.controller.meta | 0 .../AnimateAddedBones/AnimateAddedBones.cs | 48 ++++++++++++++ .../AnimateAddedBones.cs.meta | 3 + .../AnimateAddedBones.prefab | 0 .../AnimateAddedBones.prefab.meta | 0 .../EditModeTests/PathMappingTest.cs | 36 +--------- .../_ModularAvatar/EditModeTests/TestBase.cs | 65 +++++++++++++++++++ .../EditModeTests/TestBase.cs.meta | 3 + 12 files changed, 122 insertions(+), 37 deletions(-) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/AnimateAddedBones.meta (100%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/AnimateAddedBones/AAB_Animation.anim (100%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/AnimateAddedBones/AAB_Animation.anim.meta (100%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/AnimateAddedBones/AAB_Controller.controller (97%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/AnimateAddedBones/AAB_Controller.controller.meta (100%) create mode 100644 Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.cs create mode 100644 Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.cs.meta rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/AnimateAddedBones/AnimateAddedBones.prefab (100%) rename Assets/{bd_/ModularAvatar/DevAssets => _ModularAvatar/EditModeTests}/AnimateAddedBones/AnimateAddedBones.prefab.meta (100%) create mode 100644 Assets/_ModularAvatar/EditModeTests/TestBase.cs create mode 100644 Assets/_ModularAvatar/EditModeTests/TestBase.cs.meta diff --git a/Assets/bd_/ModularAvatar/DevAssets/AnimateAddedBones.meta b/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones.meta similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/AnimateAddedBones.meta rename to Assets/_ModularAvatar/EditModeTests/AnimateAddedBones.meta diff --git a/Assets/bd_/ModularAvatar/DevAssets/AnimateAddedBones/AAB_Animation.anim b/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AAB_Animation.anim similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/AnimateAddedBones/AAB_Animation.anim rename to Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AAB_Animation.anim diff --git a/Assets/bd_/ModularAvatar/DevAssets/AnimateAddedBones/AAB_Animation.anim.meta b/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AAB_Animation.anim.meta similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/AnimateAddedBones/AAB_Animation.anim.meta rename to Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AAB_Animation.anim.meta diff --git a/Assets/bd_/ModularAvatar/DevAssets/AnimateAddedBones/AAB_Controller.controller b/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AAB_Controller.controller similarity index 97% rename from Assets/bd_/ModularAvatar/DevAssets/AnimateAddedBones/AAB_Controller.controller rename to Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AAB_Controller.controller index 6b59abb0..e5536590 100644 --- a/Assets/bd_/ModularAvatar/DevAssets/AnimateAddedBones/AAB_Controller.controller +++ b/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AAB_Controller.controller @@ -7,7 +7,7 @@ AnimatorStateMachine: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: Base Layer + m_Name: merged m_ChildStates: - serializedVersion: 1 m_State: {fileID: 2149298753904408782} @@ -33,7 +33,7 @@ AnimatorController: m_AnimatorParameters: [] m_AnimatorLayers: - serializedVersion: 5 - m_Name: Base Layer + m_Name: merged m_StateMachine: {fileID: -9015797059024545987} m_Mask: {fileID: 0} m_Motions: [] diff --git a/Assets/bd_/ModularAvatar/DevAssets/AnimateAddedBones/AAB_Controller.controller.meta b/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AAB_Controller.controller.meta similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/AnimateAddedBones/AAB_Controller.controller.meta rename to Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AAB_Controller.controller.meta diff --git a/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.cs b/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.cs new file mode 100644 index 00000000..1ef7f7af --- /dev/null +++ b/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.cs @@ -0,0 +1,48 @@ +using System.Linq; +using nadena.dev.modular_avatar.core.editor; +using NUnit.Framework; +using UnityEditor; +using UnityEditor.Animations; +using UnityEngine; +using VRC.SDK3.Avatars.Components; + +namespace modular_avatar_tests.AnimateAddedBones +{ + /// + /// This test verifies that merged animations which affect a bone newly added to an armature by Merge Armature + /// are properly adjusted for the new bone path. + /// + public class AnimateAddedBones : TestBase + { + [Test] + public void AnimatesAddedBones() + { + var prefab = CreatePrefab("AnimateAddedBones.prefab"); + AvatarProcessor.ProcessAvatar(prefab); + + var fx = prefab.GetComponent().baseAnimationLayers + .FirstOrDefault(l => l.type == VRCAvatarDescriptor.AnimLayerType.FX); + + Assert.NotNull(fx); + var ac = fx.animatorController as AnimatorController; + Assert.NotNull(ac); + Assert.False(fx.isDefault); + + var layer = ac.layers.FirstOrDefault(l => l.name == "merged"); + Assert.NotNull(layer); + var state = layer.stateMachine.states[0].state; + Assert.NotNull(state); + + var motion = state.motion as AnimationClip; + Assert.NotNull(motion); + + var cubeObject = prefab.transform.Find("Armature/Hips").GetChild(0).gameObject; + Assert.True(cubeObject.name.StartsWith("Cube$")); + + var binding = + EditorCurveBinding.FloatCurve("Armature/Hips/" + cubeObject.name, typeof(Transform), + "localEulerAnglesRaw.x"); + Assert.NotNull(AnimationUtility.GetEditorCurve(motion, binding)); + } + } +} \ No newline at end of file diff --git a/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.cs.meta b/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.cs.meta new file mode 100644 index 00000000..03cbd72f --- /dev/null +++ b/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ef5030710e5f4bcca49b82ef9307fb11 +timeCreated: 1673015480 \ No newline at end of file diff --git a/Assets/bd_/ModularAvatar/DevAssets/AnimateAddedBones/AnimateAddedBones.prefab b/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.prefab similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/AnimateAddedBones/AnimateAddedBones.prefab rename to Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.prefab diff --git a/Assets/bd_/ModularAvatar/DevAssets/AnimateAddedBones/AnimateAddedBones.prefab.meta b/Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.prefab.meta similarity index 100% rename from Assets/bd_/ModularAvatar/DevAssets/AnimateAddedBones/AnimateAddedBones.prefab.meta rename to Assets/_ModularAvatar/EditModeTests/AnimateAddedBones/AnimateAddedBones.prefab.meta diff --git a/Assets/_ModularAvatar/EditModeTests/PathMappingTest.cs b/Assets/_ModularAvatar/EditModeTests/PathMappingTest.cs index f9f518ee..0fd03202 100644 --- a/Assets/_ModularAvatar/EditModeTests/PathMappingTest.cs +++ b/Assets/_ModularAvatar/EditModeTests/PathMappingTest.cs @@ -9,42 +9,8 @@ using VRC.SDK3.Avatars.Components; namespace modular_avatar_tests { - public class PathMappingTest + public class PathMappingTest : TestBase { - private List objects; - - [SetUp] - public void Setup() - { - objects = new List(); - } - - [TearDown] - public void Teardown() - { - foreach (var obj in objects) - { - Object.DestroyImmediate(obj); - } - } - - GameObject CreateRoot(string name) - { - var go = new GameObject(name); - objects.Add(go); - // Needed for avatar path finding functions to work properly - go.AddComponent(typeof(VRCAvatarDescriptor)); - return go; - } - - GameObject CreateChild(GameObject parent, string name) - { - var go = new GameObject(name); - go.transform.parent = parent.transform; - objects.Add(go); - return go; - } - [Test] public void TracksSimpleRenames() { diff --git a/Assets/_ModularAvatar/EditModeTests/TestBase.cs b/Assets/_ModularAvatar/EditModeTests/TestBase.cs new file mode 100644 index 00000000..bdcaa472 --- /dev/null +++ b/Assets/_ModularAvatar/EditModeTests/TestBase.cs @@ -0,0 +1,65 @@ +using System.Collections.Generic; +using nadena.dev.modular_avatar.core.editor; +using NUnit.Framework; +using UnityEditor; +using UnityEngine; +using VRC.SDK3.Avatars.Components; + +namespace modular_avatar_tests +{ + public class TestBase + { + private List objects; + + [SetUp] + public void Setup() + { + objects = new List(); + } + + [TearDown] + public void Teardown() + { + foreach (var obj in objects) + { + Object.DestroyImmediate(obj); + } + } + + [OneTimeTearDown] + void Cleanup() + { + Util.DeleteTemporaryAssets(); + } + + protected GameObject CreateRoot(string name) + { + var go = new GameObject(name); + objects.Add(go); + // Needed for avatar path finding functions to work properly + go.AddComponent(typeof(VRCAvatarDescriptor)); + return go; + } + + protected GameObject CreateChild(GameObject parent, string name) + { + var go = new GameObject(name); + go.transform.parent = parent.transform; + objects.Add(go); + return go; + } + + protected GameObject CreatePrefab(string relPath) + { + var prefabRoot = "Assets/_ModularAvatar/EditModeTests/" + GetType().Name + "/"; + var prefabPath = prefabRoot + relPath; + + var prefab = AssetDatabase.LoadAssetAtPath(prefabPath); + Assert.NotNull(prefab, "Missing test prefab {0}", prefabPath); + + var go = Object.Instantiate(prefab); + objects.Add(go); + return go; + } + } +} \ No newline at end of file diff --git a/Assets/_ModularAvatar/EditModeTests/TestBase.cs.meta b/Assets/_ModularAvatar/EditModeTests/TestBase.cs.meta new file mode 100644 index 00000000..a30dc39c --- /dev/null +++ b/Assets/_ModularAvatar/EditModeTests/TestBase.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d3babb39034641909c515570601d049f +timeCreated: 1673015522 \ No newline at end of file