Skip to content

Commit

Permalink
further refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunderscore committed Aug 22, 2023
1 parent 27dfa06 commit 02e148f
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace _ModularAvatar.EditModeTests
{
public class DuplicateObjectNameTest : TestBase
{
/* TODO - move to build framework
[Test]
public void test_duplicate_object_names()
{
Expand All @@ -17,5 +18,6 @@ public void test_duplicate_object_names()
c2.gameObject.name = "child2";
Assert.AreEqual(PathMappings.MapPath("child"), "child");
}
*/
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -53,7 +54,9 @@ public void mergeProcessesInTopoOrder()
m1_leaf2.AddComponent<TestComponentA>();
m2_leaf3.AddComponent<TestComponentB>();

BuildContext context = new BuildContext(root.GetComponent<VRCAvatarDescriptor>());
nadena.dev.build_framework.BuildContext context =
new nadena.dev.build_framework.BuildContext(root.GetComponent<VRCAvatarDescriptor>(), null);
context.ActivateExtensionContext(typeof(TrackObjectRenamesContext));
new MergeArmatureHook().OnPreprocessAvatar(context, root);

Assert.IsTrue(bone.GetComponentInChildren<TestComponentA>() != null);
Expand All @@ -78,7 +81,9 @@ public void canDisableNameMangling()
ma.mergeTarget.referencePath = RuntimeUtil.AvatarRootPath(armature);
ma.mangleNames = false;

BuildContext context = new BuildContext(root.GetComponent<VRCAvatarDescriptor>());
nadena.dev.build_framework.BuildContext context =
new nadena.dev.build_framework.BuildContext(root.GetComponent<VRCAvatarDescriptor>(), null);
context.ActivateExtensionContext(typeof(TrackObjectRenamesContext));
new MergeArmatureHook().OnPreprocessAvatar(context, root);

Assert.IsTrue(m_bone == null); // destroyed by retargeting pass
Expand All @@ -99,7 +104,9 @@ public void manglesByDefault()
var ma = merge.AddComponent<ModularAvatarMergeArmature>();
ma.mergeTarget.referencePath = RuntimeUtil.AvatarRootPath(armature);

BuildContext context = new BuildContext(root.GetComponent<VRCAvatarDescriptor>());
nadena.dev.build_framework.BuildContext context =
new nadena.dev.build_framework.BuildContext(root.GetComponent<VRCAvatarDescriptor>(), null);
context.ActivateExtensionContext(typeof(TrackObjectRenamesContext));
new MergeArmatureHook().OnPreprocessAvatar(context, root);

Assert.IsTrue(m_bone == null); // destroyed by retargeting pass
Expand Down
74 changes: 0 additions & 74 deletions Assets/_ModularAvatar/EditModeTests/PathMappingTest.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/_ModularAvatar/EditModeTests/PathMappingTest.cs.meta

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,10 +12,14 @@ namespace modular_avatar_tests.ReplaceObject
{
public class ReplaceObjectTests : TestBase
{
private TrackObjectRenamesContext pathMappings;

void Process(GameObject root)
{
var avDesc = root.GetComponent<VRCAvatarDescriptor>();
new ReplaceObjectPass(new BuildContext(avDesc)).Process();
var buildContext = new nadena.dev.build_framework.BuildContext(avDesc, null);
pathMappings = buildContext.ActivateExtensionContext<TrackObjectRenamesContext>();
new ReplaceObjectPass(buildContext).Process();
}

[Test]
Expand Down Expand Up @@ -160,10 +165,9 @@ public void updatesPathMappings()
var replaceObject = replacement.AddComponent<ModularAvatarReplaceObject>();
replaceObject.targetObject.Set(replacee);

PathMappings.Init(root);
Process(root);

Assert.AreEqual("replacement", PathMappings.MapPath("replacee"));
Assert.AreEqual("replacement", pathMappings.MapPath("replacee"));
}
}
}
33 changes: 23 additions & 10 deletions Assets/_ModularAvatar/EditModeTests/RetargetMeshesTest.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<VRCAvatarDescriptor>());
new RetargetMeshes().OnPreprocessAvatar(root, context);
var build_context =
new nadena.dev.build_framework.BuildContext(root.GetComponent<VRCAvatarDescriptor>(), 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()
{
Expand All @@ -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<VRCAvatarDescriptor>());
new RetargetMeshes().OnPreprocessAvatar(root, context);
var build_context =
new nadena.dev.build_framework.BuildContext(root.GetComponent<VRCAvatarDescriptor>(), 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);
}
}
}
}
3 changes: 2 additions & 1 deletion Assets/_ModularAvatar/EditModeTests/Tests.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"GUID:5718fb738711cd34ea54e9553040911d",
"GUID:b906909fcc54f634db50f2cad0f988d9",
"GUID:3456780c4fb2d324ab9c633d6f1b0ddb",
"GUID:e9745f6a32442194c8dc5a43e9ab86f9"
"GUID:e9745f6a32442194c8dc5a43e9ab86f9",
"GUID:62ced99b048af7f4d8dfe4bed8373d76"
],
"includePlatforms": [
"Editor"
Expand Down
7 changes: 3 additions & 4 deletions Packages/nadena.dev.modular-avatar/Editor/AvatarProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,10 @@ public bool OnPreprocessAvatar(GameObject avatarGameObject)

public static void ProcessAvatar(GameObject avatarGameObject)
{
if (nowProcessing) return;

var context = new BuildContext(avatarGameObject.GetComponent<VRCAvatarDescriptor>());
ProcessAvatar(context);
build_framework.AvatarProcessor.ProcessAvatar(avatarGameObject);
}

/*
internal static void ProcessAvatar(BuildContext context)
{
throw new NotImplementedException("Needs rework post-ABPF");
Expand Down Expand Up @@ -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)
{
Expand Down

This file was deleted.

6 changes: 6 additions & 0 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 02e148f

Please sign in to comment.