chore: Add TransformMappingThroughSwitchedObject test

This commit is contained in:
bd_ 2023-01-06 23:54:48 +09:00
parent f64f00e2d3
commit c3e0f94448
17 changed files with 63 additions and 16 deletions

View File

@ -20,21 +20,9 @@ namespace modular_avatar_tests.AnimateAddedBones
var prefab = CreatePrefab("AnimateAddedBones.prefab");
AvatarProcessor.ProcessAvatar(prefab);
var fx = prefab.GetComponent<VRCAvatarDescriptor>().baseAnimationLayers
.FirstOrDefault(l => l.type == VRCAvatarDescriptor.AnimLayerType.FX);
var layerName = "merged";
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 motion = findFxMotion(prefab, layerName);
var cubeObject = prefab.transform.Find("Armature/Hips").GetChild(0).gameObject;
Assert.True(cubeObject.name.StartsWith("Cube$"));

View File

@ -1,7 +1,9 @@
using System.Collections.Generic;
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;
@ -61,5 +63,32 @@ namespace modular_avatar_tests
objects.Add(go);
return go;
}
protected static AnimationClip findFxMotion(GameObject prefab, string layerName)
{
var layer = findFxLayer(prefab, layerName);
var state = layer.stateMachine.states[0].state;
Assert.NotNull(state);
var motion = state.motion as AnimationClip;
Assert.NotNull(motion);
return motion;
}
protected static AnimatorControllerLayer findFxLayer(GameObject prefab, string layerName)
{
var fx = prefab.GetComponent<VRCAvatarDescriptor>().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 == layerName);
Assert.NotNull(layer);
return layer;
}
}
}

View File

@ -7,7 +7,7 @@ AnimatorStateMachine:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Base Layer
m_Name: child_controller
m_ChildStates:
- serializedVersion: 1
m_State: {fileID: 4610933037596458320}
@ -33,7 +33,7 @@ AnimatorController:
m_AnimatorParameters: []
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
m_Name: child_controller
m_StateMachine: {fileID: -7544367895585285567}
m_Mask: {fileID: 0}
m_Motions: []

View File

@ -0,0 +1,27 @@
using nadena.dev.modular_avatar.core.editor;
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
namespace modular_avatar_tests.TransformMappingThroughSwitchedObject
{
/// <summary>
/// This test verifies that transform mappings are properly handled, even if the bone they target is on an armature
/// underneath multiple switched objects (which therefore would generate multiple levels of proxy switch objects).
/// </summary>
public class TransformMappingThroughSwitchedObject : TestBase
{
[Test]
public void TransformMappingHandledCorrectly()
{
var prefab = CreatePrefab("TransformMappingThroughSwitchedObject.prefab");
AvatarProcessor.ProcessAvatar(prefab);
var motion = findFxMotion(prefab, "child_controller");
var binding = EditorCurveBinding.FloatCurve("Armature/Hips", typeof(Transform), "localEulerAnglesRaw.x");
var curve = AnimationUtility.GetEditorCurve(motion, binding);
Assert.IsNotNull(curve);
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: baeea9019e894fb09d9b25f015856348
timeCreated: 1673016399