fix: merge blend tree does not correct parameter type conflicts (#1552)

This commit is contained in:
bd_ 2025-04-09 20:05:48 -07:00 committed by GitHub
parent 8cba3560ce
commit dcda15569a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 75 additions and 7 deletions

View File

@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
### Fixed
- [#1552] Merge Blend Treeにて、メインアバターFXレイヤーと同じ名前のintやboolパラメーターがBlend Treeに含まれている場合、
パラメーター型が修正されない問題を修正
- [#1553] リアクティブコンポーネントが生成するステートに、WD設定が正しくない問題を修正
### Changed

View File

@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
### Fixed
- [#1552] Merge Blend Tree failed to correct parameter types when the main avatar FX layer contained an int or bool
parameter with the same name as one used in the blend tree.
- [#1553] Reactive components might generate states with incorrect write default settings
### Changed

View File

@ -12,6 +12,8 @@ Modular Avatarの主な変更点をこのファイルで記録しています。
- (実験的機能) VRC以外のプラットフォームのサポートを有効化
### Fixed
- [#1552] Merge Blend Treeにて、メインアバターFXレイヤーと同じ名前のintやboolパラメーターがBlend Treeに含まれている場合、
パラメーター型が修正されない問題を修正
- [#1553] リアクティブコンポーネントが生成するステートに、WD設定が正しくない問題を修正
### Changed

View File

@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- (Experimental feature) Enabled support for non-VRC platforms
### Fixed
- [#1552] Merge Blend Tree failed to correct parameter types when the main avatar FX layer contained an int or bool
parameter with the same name as one used in the blend tree.
- [#1553] Reactive components might generate states with incorrect write default settings
### Changed

View File

@ -65,14 +65,31 @@ namespace nadena.dev.modular_avatar.core.editor
foreach (var name in _parameterNames)
{
if (fx.Parameters.ContainsKey(name)) continue;
fx.Parameters = fx.Parameters.SetItem(name, new AnimatorControllerParameter()
if (fx.Parameters.TryGetValue(name, out var existingParameter))
{
name = name,
type = AnimatorControllerParameterType.Float,
defaultFloat = 0.0f
});
switch (existingParameter.type)
{
case AnimatorControllerParameterType.Bool:
existingParameter.defaultFloat = existingParameter.defaultBool ? 1 : 0;
break;
case AnimatorControllerParameterType.Int:
existingParameter.defaultFloat = existingParameter.defaultInt;
break;
}
existingParameter.type = AnimatorControllerParameterType.Float;
}
else
{
existingParameter = new AnimatorControllerParameter
{
name = name,
type = AnimatorControllerParameterType.Float,
defaultFloat = 0.0f
};
}
fx.Parameters = fx.Parameters.SetItem(name, existingParameter);
}
}

View File

@ -141,6 +141,49 @@ namespace modular_avatar_tests
Assert.AreEqual(new[] {MergeBlendTreePass.BlendTreeLayerName, MMDRelayPass.ControlLayerName, MMDRelayPass.DummyLayerName, "m2", "Eyes", "FaceMood", "m1", "m3"}, layerNames);
}
[Test]
public void BoolParameterConvertedToFloat()
{
// Create an animator controller with a bool parameter
var controller = new AnimatorController();
controller.AddParameter("testBool", AnimatorControllerParameterType.Bool);
// Create the root object and set the FX layer to the created controller
var root = CreateRoot("root");
var vrcDesc = root.GetComponent<VRCAvatarDescriptor>();
var baseLayers = vrcDesc.baseAnimationLayers;
for (int i = 0; i < baseLayers.Length; i++)
{
if (baseLayers[i].type == VRCAvatarDescriptor.AnimLayerType.FX)
{
baseLayers[i].animatorController = controller;
baseLayers[i].isDefault = false;
}
}
vrcDesc.customizeAnimationLayers = true;
// Add a Merge Blend Tree component using the same parameter
var child = CreateChild(root, "child");
var mergeComponent = child.AddComponent<ModularAvatarMergeBlendTree>();
var blendTree = new BlendTree
{
blendParameter = "testBool",
blendType = BlendTreeType.Simple1D
};
blendTree.AddChild(AnimationTestUtil.AnimationWithPath("a"));
mergeComponent.BlendTree = blendTree;
// Process the avatar
AvatarProcessor.ProcessAvatar(root);
// Verify that the parameter is converted to a float
var fxController = FindController(root, VRCAvatarDescriptor.AnimLayerType.FX).animatorController as AnimatorController;
Assert.IsTrue(fxController!.parameters.Any(p =>
p.name == "testBool" && p.type == AnimatorControllerParameterType.Float));
}
ModularAvatarMergeAnimator TestMerge(GameObject root, string mergeName, Motion motion = null)
{