mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2024-12-29 02:35:06 +08:00
fix: handle AnimatorOverrideController in Merge Animator (#697)
Closes: #692
This commit is contained in:
parent
7a2385352c
commit
2f67b9509b
@ -115,11 +115,19 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
return result;
|
||||
}
|
||||
|
||||
public AnimatorController ConvertAnimatorController(AnimatorOverrideController overrideController)
|
||||
public AnimatorController ConvertAnimatorController(RuntimeAnimatorController anyController)
|
||||
{
|
||||
var merger = new AnimatorCombiner(PluginBuildContext, overrideController.name + " (clone)");
|
||||
merger.AddOverrideController("", overrideController, null);
|
||||
return merger.Finish();
|
||||
switch (anyController)
|
||||
{
|
||||
case AnimatorController ac:
|
||||
return ac;
|
||||
case AnimatorOverrideController aoc:
|
||||
var merger = new AnimatorCombiner(PluginBuildContext, anyController.name + " (clone)");
|
||||
merger.AddOverrideController("", aoc, null);
|
||||
return merger.Finish();
|
||||
default:
|
||||
throw new Exception("Unknown RuntimeAnimatorContoller type " + anyController.GetType());
|
||||
}
|
||||
}
|
||||
|
||||
#if MA_VRCSDK3_AVATARS
|
||||
|
@ -131,6 +131,11 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
|
||||
private void MergeSingle(BuildContext context, AnimatorCombiner session, ModularAvatarMergeAnimator merge)
|
||||
{
|
||||
if (merge.animator == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string basePath;
|
||||
if (merge.pathMode == MergeAnimatorPathMode.Relative)
|
||||
{
|
||||
@ -146,7 +151,8 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
}
|
||||
|
||||
bool? writeDefaults = merge.matchAvatarWriteDefaults ? writeDefaults_[merge.layerType] : null;
|
||||
session.AddController(basePath, (AnimatorController)merge.animator, writeDefaults);
|
||||
var controller = _context.ConvertAnimatorController(merge.animator);
|
||||
session.AddController(basePath, controller, writeDefaults);
|
||||
|
||||
if (merge.deleteAttachedAnimator)
|
||||
{
|
||||
|
72
UnitTests~/MergeAnimatorTests/AOC_Base.controller
Normal file
72
UnitTests~/MergeAnimatorTests/AOC_Base.controller
Normal file
@ -0,0 +1,72 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1102 &-7522159772221479498
|
||||
AnimatorState:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Anim1
|
||||
m_Speed: 1
|
||||
m_CycleOffset: 0
|
||||
m_Transitions: []
|
||||
m_StateMachineBehaviours: []
|
||||
m_Position: {x: 50, y: 50, z: 0}
|
||||
m_IKOnFeet: 0
|
||||
m_WriteDefaultValues: 1
|
||||
m_Mirror: 0
|
||||
m_SpeedParameterActive: 0
|
||||
m_MirrorParameterActive: 0
|
||||
m_CycleOffsetParameterActive: 0
|
||||
m_TimeParameterActive: 0
|
||||
m_Motion: {fileID: 7400000, guid: 3925d31cc9ff67446906c60ce9c245f2, type: 2}
|
||||
m_Tag:
|
||||
m_SpeedParameter:
|
||||
m_MirrorParameter:
|
||||
m_CycleOffsetParameter:
|
||||
m_TimeParameter:
|
||||
--- !u!1107 &-2419141567855426485
|
||||
AnimatorStateMachine:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Target
|
||||
m_ChildStates:
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: -7522159772221479498}
|
||||
m_Position: {x: 267, y: 200, z: 0}
|
||||
m_ChildStateMachines: []
|
||||
m_AnyStateTransitions: []
|
||||
m_EntryTransitions: []
|
||||
m_StateMachineTransitions: {}
|
||||
m_StateMachineBehaviours: []
|
||||
m_AnyStatePosition: {x: 50, y: 20, z: 0}
|
||||
m_EntryPosition: {x: 50, y: 120, z: 0}
|
||||
m_ExitPosition: {x: 800, y: 120, z: 0}
|
||||
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
|
||||
m_DefaultState: {fileID: -7522159772221479498}
|
||||
--- !u!91 &9100000
|
||||
AnimatorController:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: AOC_Base
|
||||
serializedVersion: 5
|
||||
m_AnimatorParameters: []
|
||||
m_AnimatorLayers:
|
||||
- serializedVersion: 5
|
||||
m_Name: Target
|
||||
m_StateMachine: {fileID: -2419141567855426485}
|
||||
m_Mask: {fileID: 0}
|
||||
m_Motions: []
|
||||
m_Behaviours: []
|
||||
m_BlendingMode: 0
|
||||
m_SyncedLayerIndex: -1
|
||||
m_DefaultWeight: 0
|
||||
m_IKPass: 0
|
||||
m_SyncedLayerAffectsTiming: 0
|
||||
m_Controller: {fileID: 9100000}
|
8
UnitTests~/MergeAnimatorTests/AOC_Base.controller.meta
Normal file
8
UnitTests~/MergeAnimatorTests/AOC_Base.controller.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 603635c9d61945c4a9972f00f9206507
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 9100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,13 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!221 &22100000
|
||||
AnimatorOverrideController:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: AOC_Override
|
||||
m_Controller: {fileID: 9100000, guid: 603635c9d61945c4a9972f00f9206507, type: 2}
|
||||
m_Clips:
|
||||
- m_OriginalClip: {fileID: 7400000, guid: 3925d31cc9ff67446906c60ce9c245f2, type: 2}
|
||||
m_OverrideClip: {fileID: 7400000, guid: de95379b15e98fc4c98670377d47267f, type: 2}
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba5804e3851377a4e8eba40c65a7c1f1
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 22100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
53
UnitTests~/MergeAnimatorTests/Anim1.anim
Normal file
53
UnitTests~/MergeAnimatorTests/Anim1.anim
Normal file
@ -0,0 +1,53 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!74 &7400000
|
||||
AnimationClip:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Anim1
|
||||
serializedVersion: 6
|
||||
m_Legacy: 0
|
||||
m_Compressed: 0
|
||||
m_UseHighQualityCurve: 1
|
||||
m_RotationCurves: []
|
||||
m_CompressedRotationCurves: []
|
||||
m_EulerCurves: []
|
||||
m_PositionCurves: []
|
||||
m_ScaleCurves: []
|
||||
m_FloatCurves: []
|
||||
m_PPtrCurves: []
|
||||
m_SampleRate: 60
|
||||
m_WrapMode: 0
|
||||
m_Bounds:
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
m_Extent: {x: 0, y: 0, z: 0}
|
||||
m_ClipBindingConstant:
|
||||
genericBindings: []
|
||||
pptrCurveMapping: []
|
||||
m_AnimationClipSettings:
|
||||
serializedVersion: 2
|
||||
m_AdditiveReferencePoseClip: {fileID: 0}
|
||||
m_AdditiveReferencePoseTime: 0
|
||||
m_StartTime: 0
|
||||
m_StopTime: 1
|
||||
m_OrientationOffsetY: 0
|
||||
m_Level: 0
|
||||
m_CycleOffset: 0
|
||||
m_HasAdditiveReferencePose: 0
|
||||
m_LoopTime: 0
|
||||
m_LoopBlend: 0
|
||||
m_LoopBlendOrientation: 0
|
||||
m_LoopBlendPositionY: 0
|
||||
m_LoopBlendPositionXZ: 0
|
||||
m_KeepOriginalOrientation: 0
|
||||
m_KeepOriginalPositionY: 1
|
||||
m_KeepOriginalPositionXZ: 0
|
||||
m_HeightFromFeet: 0
|
||||
m_Mirror: 0
|
||||
m_EditorCurves: []
|
||||
m_EulerEditorCurves: []
|
||||
m_HasGenericRootTransform: 0
|
||||
m_HasMotionFloatCurves: 0
|
||||
m_Events: []
|
8
UnitTests~/MergeAnimatorTests/Anim1.anim.meta
Normal file
8
UnitTests~/MergeAnimatorTests/Anim1.anim.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3925d31cc9ff67446906c60ce9c245f2
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 7400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
53
UnitTests~/MergeAnimatorTests/Anim2.anim
Normal file
53
UnitTests~/MergeAnimatorTests/Anim2.anim
Normal file
@ -0,0 +1,53 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!74 &7400000
|
||||
AnimationClip:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Anim2
|
||||
serializedVersion: 6
|
||||
m_Legacy: 0
|
||||
m_Compressed: 0
|
||||
m_UseHighQualityCurve: 1
|
||||
m_RotationCurves: []
|
||||
m_CompressedRotationCurves: []
|
||||
m_EulerCurves: []
|
||||
m_PositionCurves: []
|
||||
m_ScaleCurves: []
|
||||
m_FloatCurves: []
|
||||
m_PPtrCurves: []
|
||||
m_SampleRate: 60
|
||||
m_WrapMode: 0
|
||||
m_Bounds:
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
m_Extent: {x: 0, y: 0, z: 0}
|
||||
m_ClipBindingConstant:
|
||||
genericBindings: []
|
||||
pptrCurveMapping: []
|
||||
m_AnimationClipSettings:
|
||||
serializedVersion: 2
|
||||
m_AdditiveReferencePoseClip: {fileID: 0}
|
||||
m_AdditiveReferencePoseTime: 0
|
||||
m_StartTime: 0
|
||||
m_StopTime: 1
|
||||
m_OrientationOffsetY: 0
|
||||
m_Level: 0
|
||||
m_CycleOffset: 0
|
||||
m_HasAdditiveReferencePose: 0
|
||||
m_LoopTime: 0
|
||||
m_LoopBlend: 0
|
||||
m_LoopBlendOrientation: 0
|
||||
m_LoopBlendPositionY: 0
|
||||
m_LoopBlendPositionXZ: 0
|
||||
m_KeepOriginalOrientation: 0
|
||||
m_KeepOriginalPositionY: 1
|
||||
m_KeepOriginalPositionXZ: 0
|
||||
m_HeightFromFeet: 0
|
||||
m_Mirror: 0
|
||||
m_EditorCurves: []
|
||||
m_EulerEditorCurves: []
|
||||
m_HasGenericRootTransform: 0
|
||||
m_HasMotionFloatCurves: 0
|
||||
m_Events: []
|
8
UnitTests~/MergeAnimatorTests/Anim2.anim.meta
Normal file
8
UnitTests~/MergeAnimatorTests/Anim2.anim.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de95379b15e98fc4c98670377d47267f
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 7400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
51
UnitTests~/MergeAnimatorTests/MergeSingleTests.cs
Normal file
51
UnitTests~/MergeAnimatorTests/MergeSingleTests.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using modular_avatar_tests;
|
||||
using nadena.dev.modular_avatar.animation;
|
||||
using nadena.dev.modular_avatar.core;
|
||||
using nadena.dev.modular_avatar.core.editor;
|
||||
using nadena.dev.ndmf;
|
||||
using NUnit.Framework;
|
||||
using PlasticPipe.PlasticProtocol.Messages;
|
||||
using UnityEngine;
|
||||
using BuildContext = nadena.dev.ndmf.BuildContext;
|
||||
|
||||
namespace UnitTests.MergeAnimatorTests
|
||||
{
|
||||
internal class MergeSingleTests : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void NoErrorWhenAnimatorIsNull()
|
||||
{
|
||||
var av = CreateRoot("root");
|
||||
|
||||
var merge = av.AddComponent<ModularAvatarMergeAnimator>();
|
||||
|
||||
var ctx = new BuildContext(av, null);
|
||||
ctx.ActivateExtensionContext<ModularAvatarContext>();
|
||||
ctx.ActivateExtensionContext<AnimationServicesContext>();
|
||||
|
||||
var errors = ErrorReport.CaptureErrors(() => new MergeAnimatorProcessor().OnPreprocessAvatar(av, ctx));
|
||||
|
||||
Assert.IsEmpty(errors);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MergeAnimationOverrideController()
|
||||
{
|
||||
var av = CreateRoot("root");
|
||||
|
||||
var merge = av.AddComponent<ModularAvatarMergeAnimator>();
|
||||
merge.animator = LoadAsset<AnimatorOverrideController>("AOC_Override.overrideController");
|
||||
|
||||
var ctx = new BuildContext(av, null);
|
||||
ctx.ActivateExtensionContext<ModularAvatarContext>();
|
||||
ctx.ActivateExtensionContext<AnimationServicesContext>();
|
||||
|
||||
var errors = ErrorReport.CaptureErrors(() => new MergeAnimatorProcessor().OnPreprocessAvatar(av, ctx));
|
||||
|
||||
Assert.IsEmpty(errors);
|
||||
|
||||
var state = FindStateInLayer(findFxLayer(av, "Target"), "Anim1");
|
||||
Assert.IsTrue(state.motion.name.StartsWith("Anim2"));
|
||||
}
|
||||
}
|
||||
}
|
3
UnitTests~/MergeAnimatorTests/MergeSingleTests.cs.meta
Normal file
3
UnitTests~/MergeAnimatorTests/MergeSingleTests.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04bbb3c34b0149509cf0fcb4d7fffdc6
|
||||
timeCreated: 1708936501
|
Loading…
Reference in New Issue
Block a user