mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-01-20 13:20:06 +08:00
1635b988a9
This branch rewrites the merge armature logic to be both simpler and more reliable. In particular, all components in the merged armature will always be moved into the target armature, eliminating the need for complex and unreliable constraint adjustments. I also rewrite the path remapping logic to be more reliable by tracking actual GameObjects, rather than string paths. This change fixes a number of constraint-heavy outfits, including: * https://cloudz.booth.pm/items/3751948 * https://capettiya.booth.pm/items/4424678 It also fixes issues with some more advanced use cases, such as animating transforms on bones that are newly added using merge armature.
108 lines
3.1 KiB
C#
108 lines
3.1 KiB
C#
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
|
|
{
|
|
private List<GameObject> objects;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
objects = new List<GameObject>();
|
|
}
|
|
|
|
[TearDown]
|
|
public void Teardown()
|
|
{
|
|
foreach (var obj in objects)
|
|
{
|
|
Object.DestroyImmediate(obj);
|
|
}
|
|
}
|
|
|
|
GameObject CreateRoot(string name)
|
|
{
|
|
var go = new GameObject(name);
|
|
objects.Add(go);
|
|
// Needed for avatar path finding functions to work properly
|
|
go.AddComponent(typeof(VRCAvatarDescriptor));
|
|
return go;
|
|
}
|
|
|
|
GameObject CreateChild(GameObject parent, string name)
|
|
{
|
|
var go = new GameObject(name);
|
|
go.transform.parent = parent.transform;
|
|
objects.Add(go);
|
|
return go;
|
|
}
|
|
|
|
[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));
|
|
}
|
|
}
|
|
} |