From 3f02a1127f238d9e67428c9a66f31f9b47eec034 Mon Sep 17 00:00:00 2001 From: bd_ Date: Sun, 18 Aug 2024 18:47:33 -0700 Subject: [PATCH] fix: constant reactive objects are incorrectly animated to original scene state (#1017) Closes: #1014 --- .../AnimationGeneration/ReactiveObjectPass.cs | 13 +++-- .../InitialStates/SCDefaultAnimation.cs | 4 +- .../InitialStates/SCDefaultAnimation.prefab | 52 +++++++++++++++++++ 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPass.cs b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPass.cs index e93f7bd3..72f37d93 100644 --- a/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPass.cs +++ b/Editor/ReactiveObjects/AnimationGeneration/ReactiveObjectPass.cs @@ -41,8 +41,8 @@ namespace nadena.dev.modular_avatar.core.editor ); GenerateActiveSelfProxies(shapes); - - ProcessInitialStates(initialStates); + + ProcessInitialStates(initialStates, shapes); ProcessInitialAnimatorVariables(shapes); foreach (var groups in shapes.Values) @@ -81,7 +81,8 @@ namespace nadena.dev.modular_avatar.core.editor } } - private void ProcessInitialStates(Dictionary initialStates) + private void ProcessInitialStates(Dictionary initialStates, + Dictionary shapes) { var asc = context.Extension(); @@ -161,6 +162,10 @@ namespace nadena.dev.modular_avatar.core.editor } } + if (!shapes.ContainsKey(key)) + // Do not generate any animation base state if the property is set to a constant value, + // because we won't generate any override layers. + continue; if (animBaseState is float f) { @@ -476,7 +481,7 @@ namespace nadena.dev.modular_avatar.core.editor var clip = new AnimationClip(); clip.name = $"Set {path}:{key.PropertyName}={value}"; - if (value is UnityEngine.Object obj) + if (value is Object obj) { var binding = EditorCurveBinding.PPtrCurve(path, componentType, key.PropertyName); AnimationUtility.SetObjectReferenceCurve(clip, binding, new [] diff --git a/UnitTests~/ShapeChanger/InitialStates/SCDefaultAnimation.cs b/UnitTests~/ShapeChanger/InitialStates/SCDefaultAnimation.cs index d1ee2ff4..13be9ca7 100644 --- a/UnitTests~/ShapeChanger/InitialStates/SCDefaultAnimation.cs +++ b/UnitTests~/ShapeChanger/InitialStates/SCDefaultAnimation.cs @@ -52,8 +52,8 @@ namespace ShapeChangerTests typeof(SkinnedMeshRenderer), "blendShape.key3" )); - Assert.AreEqual(6.0f, curve.keys[0].value, 0.1f); - Assert.AreEqual(6.0f, curve.keys[1].value, 0.1f); + // Always-on set, no curve should be generated + Assert.IsNull(curve); // Check actual blendshape states Assert.AreEqual(10.0f, smr.GetBlendShapeWeight(sharedMesh.GetBlendShapeIndex("key1")), 0.1f); diff --git a/UnitTests~/ShapeChanger/InitialStates/SCDefaultAnimation.prefab b/UnitTests~/ShapeChanger/InitialStates/SCDefaultAnimation.prefab index d7bed984..f6431564 100644 --- a/UnitTests~/ShapeChanger/InitialStates/SCDefaultAnimation.prefab +++ b/UnitTests~/ShapeChanger/InitialStates/SCDefaultAnimation.prefab @@ -44,8 +44,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 2db441f589c3407bb6fb5f02ff8ab541, type: 3} m_Name: m_EditorClassIdentifier: + m_inverted: 0 m_targetRenderer: referencePath: test mesh + targetObject: {fileID: 0} m_shapes: - ShapeName: key2 ChangeType: 0 @@ -94,8 +96,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 2db441f589c3407bb6fb5f02ff8ab541, type: 3} m_Name: m_EditorClassIdentifier: + m_inverted: 0 m_targetRenderer: referencePath: test mesh + targetObject: {fileID: 0} m_shapes: - ShapeName: key1 ChangeType: 1 @@ -144,8 +148,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 2db441f589c3407bb6fb5f02ff8ab541, type: 3} m_Name: m_EditorClassIdentifier: + m_inverted: 0 m_targetRenderer: referencePath: test mesh + targetObject: {fileID: 0} m_shapes: - ShapeName: key3 ChangeType: 1 @@ -160,6 +166,8 @@ GameObject: m_Component: - component: {fileID: 569625391371299408} - component: {fileID: 3841502665919975468} + - component: {fileID: 2918390808850211981} + - component: {fileID: 664065153831629983} m_Layer: 0 m_Name: InitialOffToggled m_TagString: Untagged @@ -194,12 +202,56 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 2db441f589c3407bb6fb5f02ff8ab541, type: 3} m_Name: m_EditorClassIdentifier: + m_inverted: 0 m_targetRenderer: referencePath: test mesh + targetObject: {fileID: 0} m_shapes: - ShapeName: key1 ChangeType: 1 Value: 20 +--- !u!114 &2918390808850211981 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6385483934583485188} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3b29d45007c5493d926d2cd45a489529, type: 3} + m_Name: + m_EditorClassIdentifier: + Control: + name: + icon: {fileID: 0} + type: 102 + parameter: + name: + value: 1 + style: 0 + subMenu: {fileID: 0} + subParameters: [] + labels: [] + MenuSource: 1 + menuSource_otherObjectChildren: {fileID: 0} + isSynced: 1 + isSaved: 1 + isDefault: 0 +--- !u!114 &664065153831629983 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6385483934583485188} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7ef83cb0c23d4d7c9d41021e544a1978, type: 3} + m_Name: + m_EditorClassIdentifier: + menuToAppend: {fileID: 0} + installTargetMenu: {fileID: 0} --- !u!1 &6855505756433160176 GameObject: m_ObjectHideFlags: 0