2023-09-24 13:37:10 +08:00
|
|
|
|
using nadena.dev.modular_avatar.animation;
|
2023-08-05 14:47:03 +08:00
|
|
|
|
using nadena.dev.modular_avatar.core.editor;
|
2023-04-09 18:08:57 +08:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace modular_avatar_tests
|
|
|
|
|
{
|
|
|
|
|
public class RetargetMeshesTest : TestBase
|
|
|
|
|
{
|
|
|
|
|
// Real world case of this test case is with skinned mesh without bones or skinned mesh renderer with null mesh.
|
|
|
|
|
[Test]
|
|
|
|
|
public void RootBoneOnly()
|
|
|
|
|
{
|
|
|
|
|
var root = CreateRoot("root");
|
|
|
|
|
var a = CreateChild(root, "a");
|
|
|
|
|
var b = CreateChild(a, "b");
|
|
|
|
|
|
|
|
|
|
var skinnedMeshRenderer = root.AddComponent<SkinnedMeshRenderer>();
|
|
|
|
|
skinnedMeshRenderer.sharedMesh = new Mesh();
|
|
|
|
|
skinnedMeshRenderer.rootBone = b.transform;
|
|
|
|
|
Debug.Assert(skinnedMeshRenderer.bones.Length == 0);
|
|
|
|
|
|
2023-11-10 14:37:56 +08:00
|
|
|
|
var build_context = new nadena.dev.ndmf.BuildContext(root, null);
|
2023-09-30 23:09:43 +08:00
|
|
|
|
var torc = new AnimationServicesContext();
|
2023-08-05 14:47:03 +08:00
|
|
|
|
torc.OnActivate(build_context);
|
|
|
|
|
|
|
|
|
|
var bonedb = new BoneDatabase();
|
|
|
|
|
bonedb.AddMergedBone(b.transform);
|
|
|
|
|
|
2023-09-30 23:09:43 +08:00
|
|
|
|
new RetargetMeshes().OnPreprocessAvatar(root, bonedb, torc.PathMappings);
|
2023-04-09 18:08:57 +08:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(a.transform, skinnedMeshRenderer.rootBone);
|
|
|
|
|
}
|
2023-08-05 14:47:03 +08:00
|
|
|
|
|
2023-04-09 18:08:57 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void NoMeshRootBoneOnly()
|
|
|
|
|
{
|
|
|
|
|
var root = CreateRoot("root");
|
|
|
|
|
var a = CreateChild(root, "a");
|
|
|
|
|
var b = CreateChild(a, "b");
|
|
|
|
|
b.transform.localScale = new Vector3(2, 2, 2);
|
|
|
|
|
|
|
|
|
|
var skinnedMeshRenderer = root.AddComponent<SkinnedMeshRenderer>();
|
|
|
|
|
skinnedMeshRenderer.sharedMesh = null;
|
|
|
|
|
skinnedMeshRenderer.localBounds = new Bounds(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
|
|
|
|
|
skinnedMeshRenderer.rootBone = b.transform;
|
|
|
|
|
Debug.Assert(skinnedMeshRenderer.bones.Length == 0);
|
|
|
|
|
|
2023-11-10 14:37:56 +08:00
|
|
|
|
var build_context = new nadena.dev.ndmf.BuildContext(root, null);
|
2023-09-30 23:09:43 +08:00
|
|
|
|
var torc = new AnimationServicesContext();
|
2023-08-05 14:47:03 +08:00
|
|
|
|
torc.OnActivate(build_context);
|
|
|
|
|
|
|
|
|
|
var bonedb = new BoneDatabase();
|
|
|
|
|
bonedb.AddMergedBone(b.transform);
|
|
|
|
|
|
2023-09-30 23:09:43 +08:00
|
|
|
|
new RetargetMeshes().OnPreprocessAvatar(root, bonedb, torc.PathMappings);
|
2023-04-09 18:08:57 +08:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(a.transform, skinnedMeshRenderer.rootBone);
|
2023-08-05 14:47:03 +08:00
|
|
|
|
Assert.AreEqual(new Bounds(new Vector3(0, 0, 0), new Vector3(2, 2, 2)),
|
2023-04-09 18:08:57 +08:00
|
|
|
|
skinnedMeshRenderer.localBounds);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-05 14:47:03 +08:00
|
|
|
|
}
|