From 02e148f76796b73d4b9c8e9903d9f01686c432f2 Mon Sep 17 00:00:00 2001 From: bd_ Date: Tue, 22 Aug 2023 20:54:56 +0900 Subject: [PATCH] further refactoring --- .../EditModeTests/DuplicateObjectNameTest.cs | 2 + .../MergeArmatureTests/MultiLevelMergeTest.cs | 13 +++- .../EditModeTests/PathMappingTest.cs | 74 ------------------- .../EditModeTests/PathMappingTest.cs.meta | 11 --- .../ReplaceObject/ReplaceObjectTests.cs | 10 ++- .../EditModeTests/RetargetMeshesTest.cs | 33 ++++++--- .../_ModularAvatar/EditModeTests/Tests.asmdef | 3 +- .../Editor/AvatarProcessor.cs | 7 +- .../Editor/Menu/ActionProcessing.meta | 8 -- Packages/packages-lock.json | 6 ++ 10 files changed, 53 insertions(+), 114 deletions(-) delete mode 100644 Assets/_ModularAvatar/EditModeTests/PathMappingTest.cs delete mode 100644 Assets/_ModularAvatar/EditModeTests/PathMappingTest.cs.meta delete mode 100644 Packages/nadena.dev.modular-avatar/Editor/Menu/ActionProcessing.meta diff --git a/Assets/_ModularAvatar/EditModeTests/DuplicateObjectNameTest.cs b/Assets/_ModularAvatar/EditModeTests/DuplicateObjectNameTest.cs index e02d63d96..0d82adabb 100644 --- a/Assets/_ModularAvatar/EditModeTests/DuplicateObjectNameTest.cs +++ b/Assets/_ModularAvatar/EditModeTests/DuplicateObjectNameTest.cs @@ -6,6 +6,7 @@ namespace _ModularAvatar.EditModeTests { public class DuplicateObjectNameTest : TestBase { + /* TODO - move to build framework [Test] public void test_duplicate_object_names() { @@ -17,5 +18,6 @@ public void test_duplicate_object_names() c2.gameObject.name = "child2"; Assert.AreEqual(PathMappings.MapPath("child"), "child"); } + */ } } \ No newline at end of file diff --git a/Assets/_ModularAvatar/EditModeTests/MergeArmatureTests/MultiLevelMergeTest.cs b/Assets/_ModularAvatar/EditModeTests/MergeArmatureTests/MultiLevelMergeTest.cs index b90257fab..f08eed7bb 100644 --- a/Assets/_ModularAvatar/EditModeTests/MergeArmatureTests/MultiLevelMergeTest.cs +++ b/Assets/_ModularAvatar/EditModeTests/MergeArmatureTests/MultiLevelMergeTest.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Runtime.CompilerServices; +using nadena.dev.build_framework.animation; using nadena.dev.modular_avatar.core; using nadena.dev.modular_avatar.core.editor; using NUnit.Framework; @@ -53,7 +54,9 @@ public void mergeProcessesInTopoOrder() m1_leaf2.AddComponent(); m2_leaf3.AddComponent(); - BuildContext context = new BuildContext(root.GetComponent()); + nadena.dev.build_framework.BuildContext context = + new nadena.dev.build_framework.BuildContext(root.GetComponent(), null); + context.ActivateExtensionContext(typeof(TrackObjectRenamesContext)); new MergeArmatureHook().OnPreprocessAvatar(context, root); Assert.IsTrue(bone.GetComponentInChildren() != null); @@ -78,7 +81,9 @@ public void canDisableNameMangling() ma.mergeTarget.referencePath = RuntimeUtil.AvatarRootPath(armature); ma.mangleNames = false; - BuildContext context = new BuildContext(root.GetComponent()); + nadena.dev.build_framework.BuildContext context = + new nadena.dev.build_framework.BuildContext(root.GetComponent(), null); + context.ActivateExtensionContext(typeof(TrackObjectRenamesContext)); new MergeArmatureHook().OnPreprocessAvatar(context, root); Assert.IsTrue(m_bone == null); // destroyed by retargeting pass @@ -99,7 +104,9 @@ public void manglesByDefault() var ma = merge.AddComponent(); ma.mergeTarget.referencePath = RuntimeUtil.AvatarRootPath(armature); - BuildContext context = new BuildContext(root.GetComponent()); + nadena.dev.build_framework.BuildContext context = + new nadena.dev.build_framework.BuildContext(root.GetComponent(), null); + context.ActivateExtensionContext(typeof(TrackObjectRenamesContext)); new MergeArmatureHook().OnPreprocessAvatar(context, root); Assert.IsTrue(m_bone == null); // destroyed by retargeting pass diff --git a/Assets/_ModularAvatar/EditModeTests/PathMappingTest.cs b/Assets/_ModularAvatar/EditModeTests/PathMappingTest.cs deleted file mode 100644 index 0fd032022..000000000 --- a/Assets/_ModularAvatar/EditModeTests/PathMappingTest.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.IO; -using nadena.dev.modular_avatar.core.editor; -using NUnit.Framework; -using UnityEngine; -using UnityEngine.TestTools; -using VRC.SDK3.Avatars.Components; - -namespace modular_avatar_tests -{ - public class PathMappingTest : TestBase - { - [Test] - public void TracksSimpleRenames() - { - var root = CreateRoot("root"); - var a = CreateChild(root, "a"); - - PathMappings.Init(root); - Assert.AreEqual("a", PathMappings.MapPath("a")); - a.name = "b"; - PathMappings.ClearCache(); - Assert.AreEqual("b", PathMappings.MapPath("a")); - } - - [Test] - public void TracksObjectMoves() - { - var root = CreateRoot("root"); - var a = CreateChild(root, "a"); - var b = CreateChild(root, "b"); - - PathMappings.Init(root); - Assert.AreEqual("a", PathMappings.MapPath("a")); - a.transform.parent = b.transform; - PathMappings.ClearCache(); - Assert.AreEqual("b/a", PathMappings.MapPath("a")); - } - - [Test] - public void TracksCollapses() - { - var root = CreateRoot("root"); - var a = CreateChild(root, "a"); - var b = CreateChild(a, "b"); - var c = CreateChild(b, "c"); - - PathMappings.Init(root); - PathMappings.MarkRemoved(b); - c.transform.parent = a.transform; - Object.DestroyImmediate(b); - - Assert.AreEqual("a/c", PathMappings.MapPath("a/b/c")); - } - - [Test] - public void TransformLookthrough() - { - var root = CreateRoot("root"); - var a = CreateChild(root, "a"); - var b = CreateChild(a, "b"); - var c = CreateChild(b, "c"); - var d = CreateChild(c, "d"); - - PathMappings.Init(root); - PathMappings.MarkTransformLookthrough(b); - PathMappings.MarkTransformLookthrough(c); - Assert.AreEqual("a/b/c", PathMappings.MapPath("a/b/c")); - Assert.AreEqual("a", PathMappings.MapPath("a/b/c", true)); - Assert.AreEqual("a/b/c/d", PathMappings.MapPath("a/b/c/d", true)); - } - } -} \ No newline at end of file diff --git a/Assets/_ModularAvatar/EditModeTests/PathMappingTest.cs.meta b/Assets/_ModularAvatar/EditModeTests/PathMappingTest.cs.meta deleted file mode 100644 index d776cb537..000000000 --- a/Assets/_ModularAvatar/EditModeTests/PathMappingTest.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: fc087947fd98b2b43a853f93161cfe13 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/_ModularAvatar/EditModeTests/ReplaceObject/ReplaceObjectTests.cs b/Assets/_ModularAvatar/EditModeTests/ReplaceObject/ReplaceObjectTests.cs index bec921a5b..8421b43c9 100644 --- a/Assets/_ModularAvatar/EditModeTests/ReplaceObject/ReplaceObjectTests.cs +++ b/Assets/_ModularAvatar/EditModeTests/ReplaceObject/ReplaceObjectTests.cs @@ -1,4 +1,5 @@ using System; +using nadena.dev.build_framework.animation; using nadena.dev.modular_avatar.core; using nadena.dev.modular_avatar.core.editor; using nadena.dev.modular_avatar.editor.ErrorReporting; @@ -11,10 +12,14 @@ namespace modular_avatar_tests.ReplaceObject { public class ReplaceObjectTests : TestBase { + private TrackObjectRenamesContext pathMappings; + void Process(GameObject root) { var avDesc = root.GetComponent(); - new ReplaceObjectPass(new BuildContext(avDesc)).Process(); + var buildContext = new nadena.dev.build_framework.BuildContext(avDesc, null); + pathMappings = buildContext.ActivateExtensionContext(); + new ReplaceObjectPass(buildContext).Process(); } [Test] @@ -160,10 +165,9 @@ public void updatesPathMappings() var replaceObject = replacement.AddComponent(); replaceObject.targetObject.Set(replacee); - PathMappings.Init(root); Process(root); - Assert.AreEqual("replacement", PathMappings.MapPath("replacee")); + Assert.AreEqual("replacement", pathMappings.MapPath("replacee")); } } } \ No newline at end of file diff --git a/Assets/_ModularAvatar/EditModeTests/RetargetMeshesTest.cs b/Assets/_ModularAvatar/EditModeTests/RetargetMeshesTest.cs index d128df2fd..3a4a56686 100644 --- a/Assets/_ModularAvatar/EditModeTests/RetargetMeshesTest.cs +++ b/Assets/_ModularAvatar/EditModeTests/RetargetMeshesTest.cs @@ -1,4 +1,5 @@ -using nadena.dev.modular_avatar.core.editor; +using nadena.dev.build_framework.animation; +using nadena.dev.modular_avatar.core.editor; using NUnit.Framework; using UnityEngine; using VRC.SDK3.Avatars.Components; @@ -20,13 +21,19 @@ public void RootBoneOnly() skinnedMeshRenderer.rootBone = b.transform; Debug.Assert(skinnedMeshRenderer.bones.Length == 0); - BoneDatabase.AddMergedBone(b.transform); - var context = new BuildContext(root.GetComponent()); - new RetargetMeshes().OnPreprocessAvatar(root, context); + var build_context = + new nadena.dev.build_framework.BuildContext(root.GetComponent(), null); + var torc = new TrackObjectRenamesContext(); + torc.OnActivate(build_context); + + var bonedb = new BoneDatabase(); + bonedb.AddMergedBone(b.transform); + + new RetargetMeshes().OnPreprocessAvatar(root, bonedb, torc); Assert.AreEqual(a.transform, skinnedMeshRenderer.rootBone); } - + [Test] public void NoMeshRootBoneOnly() { @@ -41,13 +48,19 @@ public void NoMeshRootBoneOnly() skinnedMeshRenderer.rootBone = b.transform; Debug.Assert(skinnedMeshRenderer.bones.Length == 0); - BoneDatabase.AddMergedBone(b.transform); - var context = new BuildContext(root.GetComponent()); - new RetargetMeshes().OnPreprocessAvatar(root, context); + var build_context = + new nadena.dev.build_framework.BuildContext(root.GetComponent(), null); + var torc = new TrackObjectRenamesContext(); + torc.OnActivate(build_context); + + var bonedb = new BoneDatabase(); + bonedb.AddMergedBone(b.transform); + + new RetargetMeshes().OnPreprocessAvatar(root, bonedb, torc); Assert.AreEqual(a.transform, skinnedMeshRenderer.rootBone); - Assert.AreEqual(new Bounds(new Vector3(0, 0, 0), new Vector3(2, 2, 2)), + Assert.AreEqual(new Bounds(new Vector3(0, 0, 0), new Vector3(2, 2, 2)), skinnedMeshRenderer.localBounds); } } -} +} \ No newline at end of file diff --git a/Assets/_ModularAvatar/EditModeTests/Tests.asmdef b/Assets/_ModularAvatar/EditModeTests/Tests.asmdef index e7f708c74..f69971159 100644 --- a/Assets/_ModularAvatar/EditModeTests/Tests.asmdef +++ b/Assets/_ModularAvatar/EditModeTests/Tests.asmdef @@ -8,7 +8,8 @@ "GUID:5718fb738711cd34ea54e9553040911d", "GUID:b906909fcc54f634db50f2cad0f988d9", "GUID:3456780c4fb2d324ab9c633d6f1b0ddb", - "GUID:e9745f6a32442194c8dc5a43e9ab86f9" + "GUID:e9745f6a32442194c8dc5a43e9ab86f9", + "GUID:62ced99b048af7f4d8dfe4bed8373d76" ], "includePlatforms": [ "Editor" diff --git a/Packages/nadena.dev.modular-avatar/Editor/AvatarProcessor.cs b/Packages/nadena.dev.modular-avatar/Editor/AvatarProcessor.cs index 9b70b056d..c951eca90 100644 --- a/Packages/nadena.dev.modular-avatar/Editor/AvatarProcessor.cs +++ b/Packages/nadena.dev.modular-avatar/Editor/AvatarProcessor.cs @@ -158,12 +158,10 @@ public bool OnPreprocessAvatar(GameObject avatarGameObject) public static void ProcessAvatar(GameObject avatarGameObject) { - if (nowProcessing) return; - - var context = new BuildContext(avatarGameObject.GetComponent()); - ProcessAvatar(context); + build_framework.AvatarProcessor.ProcessAvatar(avatarGameObject); } + /* internal static void ProcessAvatar(BuildContext context) { throw new NotImplementedException("Needs rework post-ABPF"); @@ -302,6 +300,7 @@ internal static void ProcessAvatar(BuildContext context) Debug.Log($"Processed avatar " + avatarGameObject.name + " in " + sw.ElapsedMilliseconds + "ms"); } + */ private static void ClearEditorOnlyTagComponents(Transform obj) { diff --git a/Packages/nadena.dev.modular-avatar/Editor/Menu/ActionProcessing.meta b/Packages/nadena.dev.modular-avatar/Editor/Menu/ActionProcessing.meta deleted file mode 100644 index 12ce6c0f7..000000000 --- a/Packages/nadena.dev.modular-avatar/Editor/Menu/ActionProcessing.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: d1cf0a36e200446cb099ec448b446495 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index fd9c771cc..429ceb4de 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -188,6 +188,12 @@ "source": "embedded", "dependencies": {} }, + "nadena.dev.av3-build-framework": { + "version": "file:nadena.dev.av3-build-framework", + "depth": 0, + "source": "embedded", + "dependencies": {} + }, "nadena.dev.modular-avatar": { "version": "file:nadena.dev.modular-avatar", "depth": 0,